Created
March 4, 2018 23:01
-
-
Save jaraco/7184fa32670f2c63333377ddeb710676 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Lib/inspect.py b/Lib/inspect.py | |
index bc97efe179..d629689654 100644 | |
--- a/Lib/inspect.py | |
+++ b/Lib/inspect.py | |
@@ -642,13 +642,13 @@ def cleandoc(doc): | |
def getfile(object): | |
"""Work out which source or compiled file an object was defined in.""" | |
if ismodule(object): | |
- if hasattr(object, '__file__'): | |
+ if getattr(object, '__file__', None): | |
return object.__file__ | |
raise TypeError('{!r} is a built-in module'.format(object)) | |
if isclass(object): | |
if hasattr(object, '__module__'): | |
object = sys.modules.get(object.__module__) | |
- if hasattr(object, '__file__'): | |
+ if getattr(object, '__file__', None): | |
return object.__file__ | |
raise TypeError('{!r} is a built-in class'.format(object)) | |
if ismethod(object): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment