summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-11-27 08:53:57 (GMT)
committerGitHub <noreply@github.com>2023-11-27 08:53:57 (GMT)
commitf9861e69c913bfaabf57bfa9a0207d19e192dcde (patch)
tree5505884fdfc1552a34987a3541b79fee271980cb /Lib/importlib/_bootstrap.py
parent42df73652dba4937489e34a92dbf184a184c2d93 (diff)
downloadcpython-f9861e69c913bfaabf57bfa9a0207d19e192dcde.zip
cpython-f9861e69c913bfaabf57bfa9a0207d19e192dcde.tar.gz
cpython-f9861e69c913bfaabf57bfa9a0207d19e192dcde.tar.bz2
[3.12] gh-112414: Fix `AttributeError` when calling `repr()` on a namespace package imported with a custom loader (GH-112425) (#112440)
gh-112414: Fix `AttributeError` when calling `repr()` on a namespace package imported with a custom loader (GH-112425) (cherry picked from commit 0622839cfedacbb48eba27180fd0f0586fe97771) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index ec2e56f..d942045 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -824,10 +824,16 @@ def _module_repr_from_spec(spec):
"""Return the repr to use for the module."""
name = '?' if spec.name is None else spec.name
if spec.origin is None:
- if spec.loader is None:
+ loader = spec.loader
+ if loader is None:
return f'<module {name!r}>'
+ elif (
+ _bootstrap_external is not None
+ and isinstance(loader, _bootstrap_external.NamespaceLoader)
+ ):
+ return f'<module {name!r} (namespace) from {list(loader._path)}>'
else:
- return f'<module {name!r} (namespace) from {list(spec.loader._path)}>'
+ return f'<module {name!r} ({loader!r})>'
else:
if spec.has_location:
return f'<module {name!r} from {spec.origin!r}>'