mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-112414: Fix AttributeError
when calling repr()
on a namespace package imported with a custom loader (#112425)
This commit is contained in:
parent
e954ac7205
commit
0622839cfe
4 changed files with 16 additions and 3 deletions
|
@ -824,10 +824,16 @@ def _module_repr_from_spec(spec):
|
|||
"""Return the repr to use for the module."""
|
||||
name = '?' if spec.name is None else spec.name
|
||||
if spec.origin is None:
|
||||
if spec.loader is None:
|
||||
loader = spec.loader
|
||||
if loader is None:
|
||||
return f'<module {name!r}>'
|
||||
elif (
|
||||
_bootstrap_external is not None
|
||||
and isinstance(loader, _bootstrap_external.NamespaceLoader)
|
||||
):
|
||||
return f'<module {name!r} (namespace) from {list(loader._path)}>'
|
||||
else:
|
||||
return f'<module {name!r} (namespace) from {list(spec.loader._path)}>'
|
||||
return f'<module {name!r} ({loader!r})>'
|
||||
else:
|
||||
if spec.has_location:
|
||||
return f'<module {name!r} from {spec.origin!r}>'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue