summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2020-11-07 02:45:56 (GMT)
committerGitHub <noreply@github.com>2020-11-07 02:45:56 (GMT)
commit825ac383327255d38b69a753e5e41710bb3ed010 (patch)
tree86543aba40795918c174dbb899528e339c619208 /Lib/inspect.py
parent7c01f1540f958d4f52188b28afca721a9a6925c3 (diff)
downloadcpython-825ac383327255d38b69a753e5e41710bb3ed010.zip
cpython-825ac383327255d38b69a753e5e41710bb3ed010.tar.gz
cpython-825ac383327255d38b69a753e5e41710bb3ed010.tar.bz2
bpo-42133: update parts of the stdlib to fall back to `__spec__.loader` when `__loader__` is missing (#22929)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index ac127cb..7412d0e 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -707,10 +707,13 @@ def getsourcefile(object):
if os.path.exists(filename):
return filename
# only return a non-existent filename if the module has a PEP 302 loader
- if getattr(getmodule(object, filename), '__loader__', None) is not None:
+ module = getmodule(object, filename)
+ if getattr(module, '__loader__', None) is not None:
+ return filename
+ elif getattr(getattr(module, "__spec__", None), "loader", None) is not None:
return filename
# or it is in the linecache
- if filename in linecache.cache:
+ elif filename in linecache.cache:
return filename
def getabsfile(object, _filename=None):