gh-98139: enhance namespace package repr

This commit is contained in:
Anh71me 2022-11-07 06:13:40 +08:00 committed by GitHub
parent 2db55e0c00
commit bd221c01dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View file

@ -580,7 +580,7 @@ def _module_repr_from_spec(spec):
if spec.loader is None:
return f'<module {name!r}>'
else:
return f'<module {name!r} ({spec.loader!r})>'
return f'<module {name!r} (namespace) from {list(spec.loader._path)}>'
else:
if spec.has_location:
return f'<module {name!r} from {spec.origin!r}>'

View file

@ -79,6 +79,10 @@ class SingleNamespacePackage(NamespacePackageTest):
with self.assertRaises(ImportError):
import foo.two
def test_simple_repr(self):
import foo.one
assert repr(foo).startswith("<module 'foo' (namespace) from [")
class DynamicPathNamespacePackage(NamespacePackageTest):
paths = ['portion1']