From: Ka-Ping Yee Date: Fri, 13 Apr 2001 12:10:40 +0000 (+0000) Subject: Robustify getfile() against classes that lie about their __module__s X-Git-Tag: v2.1c1~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c99e0f18628b1b6109c88aa31a44a19d34c7d103;p=thirdparty%2FPython%2Fcpython.git Robustify getfile() against classes that lie about their __module__s (such as the exceptions in _weakref and _locale!) --- diff --git a/Lib/inspect.py b/Lib/inspect.py index f62167ba2e39..c358a5c57e77 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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'