]> granicus.if.org Git - python/commitdiff
Robustify getfile() against classes that lie about their __module__s
authorKa-Ping Yee <ping@zesty.ca>
Fri, 13 Apr 2001 12:10:40 +0000 (12:10 +0000)
committerKa-Ping Yee <ping@zesty.ca>
Fri, 13 Apr 2001 12:10:40 +0000 (12:10 +0000)
    (such as the exceptions in _weakref and _locale!)

Lib/inspect.py

index f62167ba2e39e2a5b6b056b269c34a22f5ecb574..c358a5c57e77b315740e600f2f6312ec7f4d275c 100644 (file)
@@ -173,7 +173,7 @@ def getfile(object):
             return object.__file__
         raise TypeError, 'arg is a built-in module'
     if isclass(object):
-        object = sys.modules[object.__module__]
+        object = sys.modules.get(object.__module__)
         if hasattr(object, '__file__'):
             return object.__file__
         raise TypeError, 'arg is a built-in class'