Commit f19d7a0c authored by Jim Fulton's avatar Jim Fulton

Added a small optimization to avoid unnecessary imports that were

sucking up a lot of time, as shown in some profile output.
parent 6f2882ed
...@@ -183,6 +183,13 @@ def find_global(modulename, globalname, ...@@ -183,6 +183,13 @@ def find_global(modulename, globalname,
>>> broken_cache.clear() >>> broken_cache.clear()
""" """
# short circuit common case:
try:
return getattr(sys.modules[modulename], globalname)
except (AttributeError, KeyError):
pass
try: try:
__import__(modulename) __import__(modulename)
except ImportError: except ImportError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment