mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Implement the PEP 302 protocol for get_filename() as
importlib.abc.ExecutionLoader. PyLoader now inherits from this ABC instead of InspectLoader directly. Both PyLoader and PyPycLoader provide concrete implementations of get_filename in terms of source_path and bytecode_path.
This commit is contained in:
parent
64ef00fa60
commit
6919427e94
6 changed files with 136 additions and 27 deletions
|
@ -76,7 +76,23 @@ InspectLoader.register(machinery.BuiltinImporter)
|
|||
InspectLoader.register(machinery.FrozenImporter)
|
||||
|
||||
|
||||
class PyLoader(_bootstrap.PyLoader, ResourceLoader, InspectLoader):
|
||||
class ExecutionLoader(InspectLoader):
|
||||
|
||||
"""Abstract base class for loaders that wish to support the execution of
|
||||
modules as scripts.
|
||||
|
||||
This ABC represents one of the optional protocols specified in PEP 302.
|
||||
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_filename(self, fullname:str) -> str:
|
||||
"""Abstract method which should return the value that __file__ is to be
|
||||
set to."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class PyLoader(_bootstrap.PyLoader, ResourceLoader, ExecutionLoader):
|
||||
|
||||
"""Abstract base class to assist in loading source code by requiring only
|
||||
back-end storage methods to be implemented.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue