summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnh71me <iyumelive@gmail.com>2022-11-06 22:13:40 (GMT)
committerGitHub <noreply@github.com>2022-11-06 22:13:40 (GMT)
commitbd221c01ddcd2cad102133611fab3569a99680b0 (patch)
treee06471ce46accb19543364b49e918f70ef63c075
parent2db55e0c0069a928775fa819973a76f840c5ab5a (diff)
downloadcpython-bd221c01ddcd2cad102133611fab3569a99680b0.zip
cpython-bd221c01ddcd2cad102133611fab3569a99680b0.tar.gz
cpython-bd221c01ddcd2cad102133611fab3569a99680b0.tar.bz2
gh-98139: enhance namespace package repr
-rw-r--r--Lib/importlib/_bootstrap.py2
-rw-r--r--Lib/test/test_importlib/test_namespace_pkgs.py4
-rw-r--r--Misc/NEWS.d/next/Library/2022-10-30-15-26-33.gh-issue-98139.qtm-9T.rst2
3 files changed, 7 insertions, 1 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index e0110e7..1a1d5cf 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -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}>'
diff --git a/Lib/test/test_importlib/test_namespace_pkgs.py b/Lib/test/test_importlib/test_namespace_pkgs.py
index f451f75..65428c3 100644
--- a/Lib/test/test_importlib/test_namespace_pkgs.py
+++ b/Lib/test/test_importlib/test_namespace_pkgs.py
@@ -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']
diff --git a/Misc/NEWS.d/next/Library/2022-10-30-15-26-33.gh-issue-98139.qtm-9T.rst b/Misc/NEWS.d/next/Library/2022-10-30-15-26-33.gh-issue-98139.qtm-9T.rst
new file mode 100644
index 0000000..ed5dd00
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-10-30-15-26-33.gh-issue-98139.qtm-9T.rst
@@ -0,0 +1,2 @@
+In :mod:`importlib._bootstrap`, enhance namespace package repr to `<module
+'x' (namespace) from ['path']>`.