8000 bpo-35673: Add a public alias for namespace package __loader__ attribute by warsaw · Pull Request #29049 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

bpo-35673: Add a public alias for namespace package __loader__ attribute #29049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Swap NamespaceLoader and _NamespaceLoader
The class is named NamespaceLoader and the alias is _NamespaceLoader
  • Loading branch information
warsaw committed Oct 19, 2021
commit cc0a9a46f88a178a189de48f9802b46b2019cb79
4 changes: 2 additions & 2 deletions Lib/importlib/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,9 @@ def _init_module_attrs(spec, module, *, override=False):
if spec.submodule_search_locations is not None:
if _bootstrap_external is None:
raise NotImplementedError
_NamespaceLoader = _bootstrap_external._NamespaceLoader
NamespaceLoader = _bootstrap_external.NamespaceLoader

loader = _NamespaceLoader.__new__(_NamespaceLoader)
loader = NamespaceLoader.__new__(NamespaceLoader)
loader._path = spec.submodule_search_locations
spec.loader = loader
# While the docs say that module.__file__ is not set for
Expand Down
14 changes: 7 additions & 7 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,8 +1279,10 @@ def append(self, item):
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)

Expand All @@ -1291,7 +1293,7 @@ def module_repr(module):
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__)

Expand Down Expand Up @@ -1327,10 +1329,8 @@ def get_resource_reader(self, module):
return NamespaceReader(self._path)


# 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
NamespaceLoader = _NamespaceLoader
# We use this exclusively in module_from_spec() for backward-compatibility.
_NamespaceLoader = NamespaceLoader


# Finders #####################################################################
Expand Down
0