summaryrefslogtreecommitdiffstats
path: root/Lib/linecache.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/linecache.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/linecache.py')
-rw-r--r--Lib/linecache.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/linecache.py b/Lib/linecache.py
index fa5dbd0..513b17e 100644
--- a/Lib/linecache.py
+++ b/Lib/linecache.py
@@ -165,9 +165,14 @@ def lazycache(filename, module_globals):
if not filename or (filename.startswith('<') and filename.endswith('>')):
return False
# Try for a __loader__, if available
- if module_globals and '__loader__' in module_globals:
- name = module_globals.get('__name__')
- loader = module_globals['__loader__']
+ if module_globals and '__name__' in module_globals:
+ name = module_globals['__name__']
+ if (loader := module_globals.get('__loader__')) is None:
+ if spec := module_globals.get('__spec__'):
+ try:
+ loader = spec.loader
+ except AttributeError:
+ pass
get_source = getattr(loader, 'get_source', None)
if name and get_source: