mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
bpo-42133: update parts of the stdlib to fall back to __spec__.loader
when __loader__
is missing (#22929)
This commit is contained in:
parent
7c01f1540f
commit
825ac38332
6 changed files with 59 additions and 14 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue