summaryrefslogtreecommitdiff
path: root/Lib/linecache.py
diff options
context:
space:
mode:
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 fa5dbd09ea..513b17e999 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: