[Python-checkins] Namespace packages _bootstrap.ModuleSpec.loader attributes are no longer None (#10376)

Barry Warsaw webhook-mailer at python.org
Wed May 1 16:08:24 EDT 2019


https://github.com/python/cpython/commit/ee88af3f4f7493df4ecf52faf429e63351bbcd5c
commit: ee88af3f4f7493df4ecf52faf429e63351bbcd5c
branch: master
author: Géry Ogam <gery.ogam at gmail.com>
committer: Barry Warsaw <barry at python.org>
date: 2019-05-01T13:08:17-07:00
summary:

Namespace packages _bootstrap.ModuleSpec.loader attributes are no longer None (#10376)

Namespace packages _bootstrap.ModuleSpec.loader attributes are no longer `None` _after_ calling the importlib._bootstrap._init_module_attrs function.

See:
* https://stackoverflow.com/questions/52869541/namespace-package-spec-loader-and-loader-attributes-not-set-to-none
* https://bugs.python.org/issue35181

files:
M Doc/reference/import.rst

diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst
index 88290c88bb35..0228bfb7e984 100644
--- a/Doc/reference/import.rst
+++ b/Doc/reference/import.rst
@@ -345,12 +345,11 @@ of what happens during the loading portion of import::
     _init_module_attrs(spec, module)
 
     if spec.loader is None:
-        if spec.submodule_search_locations is not None:
-            # namespace package
-            sys.modules[spec.name] = module
-        else:
-            # unsupported
-            raise ImportError
+        # unsupported
+        raise ImportError
+    if spec.origin is None and spec.submodule_search_locations is not None:
+        # namespace package
+        sys.modules[spec.name] = module
     elif not hasattr(spec.loader, 'exec_module'):
         module = spec.loader.load_module(spec.name)
         # Set __loader__ and __package__ if missing.



More information about the Python-checkins mailing list