Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c99e0f1

Browse files
committed
Robustify getfile() against classes that lie about their __module__s
(such as the exceptions in _weakref and _locale!)
1 parent da79389 commit c99e0f1

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Lib/inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def getfile(object):
173173
return object.__file__
174174
raise TypeError, 'arg is a built-in module'
175175
if isclass(object):
176-
object = sys.modules[object.__module__]
176+
object = sys.modules.get(object.__module__)
177177
if hasattr(object, '__file__'):
178178
return object.__file__
179179
raise TypeError, 'arg is a built-in class'

0 commit comments

Comments
 (0)