summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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']>`.