mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-98139: enhance namespace package repr
This commit is contained in:
parent
2db55e0c00
commit
bd221c01dd
3 changed files with 7 additions and 1 deletions
|
@ -580,7 +580,7 @@ def _module_repr_from_spec(spec):
|
||||||
if spec.loader is None:
|
if spec.loader is None:
|
||||||
return f'<module {name!r}>'
|
return f'<module {name!r}>'
|
||||||
else:
|
else:
|
||||||
return f'<module {name!r} ({spec.loader!r})>'
|
return f'<module {name!r} (namespace) from {list(spec.loader._path)}>'
|
||||||
else:
|
else:
|
||||||
if spec.has_location:
|
if spec.has_location:
|
||||||
return f'<module {name!r} from {spec.origin!r}>'
|
return f'<module {name!r} from {spec.origin!r}>'
|
||||||
|
|
|
@ -79,6 +79,10 @@ class SingleNamespacePackage(NamespacePackageTest):
|
||||||
with self.assertRaises(ImportError):
|
with self.assertRaises(ImportError):
|
||||||
import foo.two
|
import foo.two
|
||||||
|
|
||||||
|
def test_simple_repr(self):
|
||||||
|
import foo.one
|
||||||
|
assert repr(foo).startswith("<module 'foo' (namespace) from [")
|
||||||
|
|
||||||
|
|
||||||
class DynamicPathNamespacePackage(NamespacePackageTest):
|
class DynamicPathNamespacePackage(NamespacePackageTest):
|
||||||
paths = ['portion1']
|
paths = ['portion1']
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
In :mod:`importlib._bootstrap`, enhance namespace package repr to `<module
|
||||||
|
'x' (namespace) from ['path']>`.
|
Loading…
Add table
Add a link
Reference in a new issue