mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
Introduce importlib.abc. The module contains various ABCs related to imports
(mostly stuff specified by PEP 302). There are two ABCs, PyLoader and PyPycLoader, which help with implementing source and source/bytecode loaders by implementing load_module in terms of other methods. This removes a lot of gritty details loaders typically have to worry about.
This commit is contained in:
parent
aa1c8d8899
commit
2a922ed6ad
9 changed files with 739 additions and 171 deletions
|
@ -383,14 +383,8 @@ class PyPycLoader(PyLoader):
|
|||
def load_module(self, module):
|
||||
"""Load a module from source or bytecode."""
|
||||
name = module.__name__
|
||||
try:
|
||||
source_path = self.source_path(name)
|
||||
except ImportError:
|
||||
source_path = None
|
||||
try:
|
||||
bytecode_path = self.bytecode_path(name)
|
||||
except ImportError:
|
||||
bytecode_path = None
|
||||
source_path = self.source_path(name)
|
||||
bytecode_path = self.bytecode_path(name)
|
||||
# get_code can worry about no viable paths existing.
|
||||
module.__file__ = source_path or bytecode_path
|
||||
return self._load_module(module)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue