Skip to content

Instantly share code, notes, and snippets.

@jaraco
Created March 4, 2018 23:01
Show Gist options
  • Save jaraco/7184fa32670f2c63333377ddeb710676 to your computer and use it in GitHub Desktop.
Save jaraco/7184fa32670f2c63333377ddeb710676 to your computer and use it in GitHub Desktop.
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