diff options
author | Barry Warsaw <barry@python.org> | 2021-10-20 14:05:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-20 14:05:29 -0700 |
commit | 876fc7fcec9a79a11546b7588d3683a5ccb4d31c (patch) | |
tree | 9195e6474ea19461bbc5d9705f05bd2cf8603209 /Lib/importlib/_bootstrap_external.py | |
parent | 6270d3eeaf17b50abc4f8f4d97790d66179638e4 (diff) | |
download | cpython-876fc7fcec9a79a11546b7588d3683a5ccb4d31c.tar.gz cpython-876fc7fcec9a79a11546b7588d3683a5ccb4d31c.zip |
bpo-35673: Add a public alias for namespace package __loader__ attribute (#29049)
Rename namespace package __loader__ class to be public.
Make the old name, i.e. _NamespaceLoader, an alias for the public name, for backward compatibility.
Diffstat (limited to 'Lib/importlib/_bootstrap_external.py')
-rw-r--r-- | Lib/importlib/_bootstrap_external.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index c9692b542a5..ef4f23a4b49 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -1279,8 +1279,10 @@ class _NamespacePath: self._path.append(item) -# We use this exclusively in module_from_spec() for backward-compatibility. -class _NamespaceLoader: +# This class is actually exposed publicly in a namespace package's __loader__ +# attribute, so it should be available through a non-private name. +# https://bugs.python.org/issue35673 +class NamespaceLoader: def __init__(self, name, path, path_finder): self._path = _NamespacePath(name, path, path_finder) @@ -1291,7 +1293,7 @@ class _NamespaceLoader: The method is deprecated. The import machinery does the job itself. """ - _warnings.warn("_NamespaceLoader.module_repr() is deprecated and " + _warnings.warn("NamespaceLoader.module_repr() is deprecated and " "slated for removal in Python 3.12", DeprecationWarning) return '<module {!r} (namespace)>'.format(module.__name__) @@ -1327,6 +1329,10 @@ class _NamespaceLoader: return NamespaceReader(self._path) +# We use this exclusively in module_from_spec() for backward-compatibility. +_NamespaceLoader = NamespaceLoader + + # Finders ##################################################################### class PathFinder: |