summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2014-05-09 16:28:22 (GMT)
committerBrett Cannon <brett@python.org>2014-05-09 16:28:22 (GMT)
commit6eaac13c92750afddebf22fc0a57e3f40e9d1a2f (patch)
treefb9563cccb0a04691fdbec1cc3dd5a41b1b311bb
parenta237a987539aed6ba28115c2e932b205c592be88 (diff)
downloadcpython-6eaac13c92750afddebf22fc0a57e3f40e9d1a2f.zip
cpython-6eaac13c92750afddebf22fc0a57e3f40e9d1a2f.tar.gz
cpython-6eaac13c92750afddebf22fc0a57e3f40e9d1a2f.tar.bz2
Issue #21156: importlib.abc.InspectLoader.source_to_code() is now a
staticmethod.
-rw-r--r--Doc/library/importlib.rst8
-rw-r--r--Doc/whatsnew/3.5.rst5
-rw-r--r--Lib/importlib/abc.py3
-rw-r--r--Misc/NEWS3
4 files changed, 17 insertions, 2 deletions
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index 50f4ee4..0adeefb 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -499,7 +499,7 @@ ABC hierarchy::
.. versionchanged:: 3.4
Raises :exc:`ImportError` instead of :exc:`NotImplementedError`.
- .. method:: source_to_code(data, path='<string>')
+ .. staticmethod:: source_to_code(data, path='<string>')
Create a code object from Python source.
@@ -508,8 +508,14 @@ ABC hierarchy::
the "path" to where the source code originated from, which can be an
abstract concept (e.g. location in a zip file).
+ With the subsequent code object one can execute it in a module by
+ running ``exec(code, module.__dict__)``.
+
.. versionadded:: 3.4
+ .. versionchanged:: 3.5
+ Made the method static.
+
.. method:: exec_module(module)
Implementation of :meth:`Loader.exec_module`.
diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst
index fbbac03..4410de6 100644
--- a/Doc/whatsnew/3.5.rst
+++ b/Doc/whatsnew/3.5.rst
@@ -158,6 +158,11 @@ Improved Modules
*module* contains no docstrings instead of raising :exc:`ValueError`
(contributed by Glenn Jones in :issue:`15916`).
+* :func:`importlib.abc.InspectLoader.source_to_code` is now a
+ static method to make it easier to work with source code in a string.
+ With a module object that you want to initialize you can then use
+ ``exec(code, module.__dict__)`` to execute the code in the module.
+
Optimizations
=============
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index 558abd3..7f6f235 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -217,7 +217,8 @@ class InspectLoader(Loader):
"""
raise ImportError
- def source_to_code(self, data, path='<string>'):
+ @staticmethod
+ def source_to_code(data, path='<string>'):
"""Compile 'data' into a code object.
The 'data' argument can be anything that compile() can handle. The'path'
diff --git a/Misc/NEWS b/Misc/NEWS
index d47cebc..4b662b2 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -73,6 +73,9 @@ Core and Builtins
Library
-------
+- Issue #21156: importlib.abc.InspectLoader.source_to_code() is now a
+ staticmethod.
+
- Issue #21396: Fix TextIOWrapper(..., write_through=True) to not force a
flush() on the underlying binary stream. Patch by akira.