diff options
author | Ka-Ping Yee <ping@zesty.ca> | 2003-03-28 16:29:50 +0000 |
---|---|---|
committer | Ka-Ping Yee <ping@zesty.ca> | 2003-03-28 16:29:50 +0000 |
commit | b38bbbd387ff713f2b2676c253108b0747744d00 (patch) | |
tree | 64cb37c81aa3f804726d85f5b010864ee391540a /Lib/inspect.py | |
parent | Move testing code into "if __name__ == '__main__'" so it's not run on import. (diff) | |
download | cpython-b38bbbd387ff713f2b2676c253108b0747744d00.tar.gz cpython-b38bbbd387ff713f2b2676c253108b0747744d00.tar.bz2 cpython-b38bbbd387ff713f2b2676c253108b0747744d00.zip |
Make module lookup a little more robust (certain kinds of fiddling to
sys.modules previously produced an exception).
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 80f65b53ba9..4baebe0c6f4 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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__) |