summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/abc.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-07-20 04:23:48 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-07-20 04:23:48 (GMT)
commit6919427e9462d05f402faa5f846f43e08347cebe (patch)
tree862ce874c7e299b7eb5078a7a5b668e4b17b9918 /Lib/importlib/abc.py
parent64ef00fa605463e1da84e43ea8a5d722843174b6 (diff)
downloadcpython-6919427e9462d05f402faa5f846f43e08347cebe.zip
cpython-6919427e9462d05f402faa5f846f43e08347cebe.tar.gz
cpython-6919427e9462d05f402faa5f846f43e08347cebe.tar.bz2
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.
Diffstat (limited to 'Lib/importlib/abc.py')
-rw-r--r--Lib/importlib/abc.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index 7b89d0b..c912280 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -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.