Make module lookup a little more robust (certain kinds of fiddling to

sys.modules previously produced an exception).
This commit is contained in:
Ka-Ping Yee 2003-03-28 16:29:50 +00:00
parent e9638ccadb
commit b38bbbd387
1 changed files with 2 additions and 2 deletions

View File

@ -366,12 +366,12 @@ def getmodule(object):
except TypeError:
return None
if file in modulesbyfile:
return sys.modules[modulesbyfile[file]]
return sys.modules.get(modulesbyfile[file])
for module in sys.modules.values():
if hasattr(module, '__file__'):
modulesbyfile[getabsfile(module)] = module.__name__
if file in modulesbyfile:
return sys.modules[modulesbyfile[file]]
return sys.modules.get(modulesbyfile[file])
main = sys.modules['__main__']
if hasattr(main, object.__name__):
mainobject = getattr(main, object.__name__)