Skip to content

Commit 9a045fb

Browse files
committed
Revert "consider that namespace package specs might have the loader set"
This reverts commit 23fb4e0. Signed-off-by: Filipe Laíns <[email protected]>
1 parent ffa7e31 commit 9a045fb

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Lib/importlib/_bootstrap.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -755,18 +755,17 @@ def _init_module_attrs(spec, module, *, override=False):
755755
loader = NamespaceLoader.__new__(NamespaceLoader)
756756
loader._path = spec.submodule_search_locations
757757
spec.loader = loader
758-
if _bootstrap_external and isinstance(loader, _bootstrap_external.NamespaceLoader):
759-
# While the docs say that module.__file__ is not set for
760-
# built-in modules, and the code below will avoid setting it if
761-
# spec.has_location is false, this is incorrect for namespace
762-
# packages. Namespace packages have no location, but their
763-
# __spec__.origin is None, and thus their module.__file__
764-
# should also be None for consistency. While a bit of a hack,
765-
# this is the best place to ensure this consistency.
766-
#
767-
# See # https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module
768-
# and bpo-32305
769-
module.__file__ = None
758+
# While the docs say that module.__file__ is not set for
759+
# built-in modules, and the code below will avoid setting it if
760+
# spec.has_location is false, this is incorrect for namespace
761+
# packages. Namespace packages have no location, but their
762+
# __spec__.origin is None, and thus their module.__file__
763+
# should also be None for consistency. While a bit of a hack,
764+
# this is the best place to ensure this consistency.
765+
#
766+
# See # https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module
767+
# and bpo-32305
768+
module.__file__ = None
770769
try:
771770
module.__loader__ = loader
772771
except AttributeError:

0 commit comments

Comments
 (0)