mirror of
https://github.com/python/cpython.git
synced 2025-07-16 07:45:20 +00:00
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.
This commit is contained in:
parent
645ab68f25
commit
13d8ff9c5b
5 changed files with 1156 additions and 1079 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue