Closed
Description
Feature or enhancement
After Loader.module_repr
has been deprecated, the repr of namespace is like:
<module 'xx' (<_frozen_bootstrap_external.NamespaceLoader object at 0x0000000>)>
which is unreadable. So I purpose the following repr:
<module 'xx' (namespace) from ['path1', 'path2']>
The change purposed to code is:
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:
return f'<module {name!r}>'
else:
return f'<module {name!r} (namespace) from {list(spec.loader._path)}>' <<< this line changed
return f'<module {name!r} ({spec.loader!r})>' >>> the unmodified line
else:
if spec.has_location:
return f'<module {name!r} from {spec.origin!r}>'
else:
return f'<module {spec.name!r} ({spec.origin})>'
In my interpreter test:
>>> import a
>>> a
<module 'a' (namespace) from ['/home/iyume/workspace/cpython/a']>
If OK, I can open PR, and add test code.