Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/importlib/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}>'
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_importlib/test_namespace_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def test_cant_import_other(self):
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']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In :mod:`importlib._bootstrap`, enhance namespace package repr to `<module
'x' (namespace) from ['path']>`.