diff options
author | Brett Cannon <brett@python.org> | 2013-06-16 18:56:58 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-06-16 18:56:58 (GMT) |
commit | 13d8ff9c5bc6c957696e9e25e54a02fc077af1af (patch) | |
tree | e5fc52292423168a125f2aab800e4c12f66fe719 /Lib/importlib/_bootstrap.py | |
parent | 645ab68f25457b24f2dadfa3e6911cebac30d33e (diff) | |
download | cpython-13d8ff9c5bc6c957696e9e25e54a02fc077af1af.zip cpython-13d8ff9c5bc6c957696e9e25e54a02fc077af1af.tar.gz cpython-13d8ff9c5bc6c957696e9e25e54a02fc077af1af.tar.bz2 |
Issues #18058, 18057: Make importlib._bootstrap.NamespaceLoader
conform the the InspectLoader ABC. Perk of this is that runpy/-m can
now work with namespace packages.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 15 |
1 files changed, 14 insertions, 1 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 |