summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/abc.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-05-26 20:45:10 (GMT)
committerBrett Cannon <brett@python.org>2013-05-26 20:45:10 (GMT)
commit9ffe85e1e86bc6718f105f2ab9833ef80f691367 (patch)
tree236b5acf6fa3186bc46d74b64d8f68fc6c5dd097 /Lib/importlib/abc.py
parent1256f1f438503530d9dcf2790f7ff5b4a08d85f3 (diff)
downloadcpython-9ffe85e1e86bc6718f105f2ab9833ef80f691367.zip
cpython-9ffe85e1e86bc6718f105f2ab9833ef80f691367.tar.gz
cpython-9ffe85e1e86bc6718f105f2ab9833ef80f691367.tar.bz2
Move importlib.abc.SourceLoader.source_to_code() to InspectLoader.
While the previous location was fine, it makes more sense to have the method higher up in the inheritance chain, especially at a point where get_source() is defined which is the earliest source_to_code() could programmatically be used in the inheritance tree in importlib.abc.
Diffstat (limited to 'Lib/importlib/abc.py')
-rw-r--r--Lib/importlib/abc.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index 7752ac4..cdcf244 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -165,6 +165,13 @@ class InspectLoader(Loader):
"""
raise ImportError
+ def source_to_code(self, data, path='<string>'):
+ """Compile 'data' into a code object.
+
+ The 'data' argument can be anything that compile() can handle. The'path'
+ argument should be where the data was retrieved (when applicable)."""
+ return compile(data, path, 'exec', dont_inherit=True)
+
_register(InspectLoader, machinery.BuiltinImporter, machinery.FrozenImporter,
machinery.ExtensionFileLoader)