summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py15
-rw-r--r--Lib/importlib/abc.py2
2 files changed, 15 insertions, 2 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 1276ff1..e32afec 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1238,12 +1238,25 @@ class NamespaceLoader:
def module_repr(cls, module):
return "<module '{}' (namespace)>".format(module.__name__)
+ def is_package(self, fullname):
+ return True
+
+ def get_source(self, fullname):
+ return ''
+
+ def get_code(self, fullname):
+ return compile('', '<string>', 'exec', dont_inherit=True)
+
+ def init_module_attrs(self, module):
+ module.__loader__ = self
+ module.__package__ = module.__name__
+
def load_module(self, fullname):
"""Load a namespace module."""
_verbose_message('namespace module loaded with path {!r}', self._path)
with module_to_load(fullname) as module:
+ self.init_module_attrs(module)
module.__path__ = self._path
- module.__package__ = fullname
return module
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index cf20e9f..b53a1a5 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -188,7 +188,7 @@ class InspectLoader(Loader):
load_module = _bootstrap._LoaderBasics.load_module
_register(InspectLoader, machinery.BuiltinImporter, machinery.FrozenImporter,
- machinery.ExtensionFileLoader)
+ machinery.ExtensionFileLoader, _bootstrap.NamespaceLoader)
class ExecutionLoader(InspectLoader):