]> granicus.if.org Git - python/commitdiff
Namespace packages _bootstrap.ModuleSpec.loader attributes are no longer None (#10376)
authorGéry Ogam <gery.ogam@gmail.com>
Wed, 1 May 2019 20:08:17 +0000 (22:08 +0200)
committerBarry Warsaw <barry@python.org>
Wed, 1 May 2019 20:08:17 +0000 (13:08 -0700)
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

Doc/reference/import.rst

index 88290c88bb35d9cbd020899eabcd9842b9f23a01..0228bfb7e984c56db35f58b9300fe289431bbc3c 100644 (file)
@@ -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.