]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #21156: importlib.abc.InspectLoader.source_to_code() is now a
authorBrett Cannon <brett@python.org>
Fri, 9 May 2014 16:28:22 +0000 (12:28 -0400)
committerBrett Cannon <brett@python.org>
Fri, 9 May 2014 16:28:22 +0000 (12:28 -0400)
staticmethod.

Doc/library/importlib.rst
Doc/whatsnew/3.5.rst
Lib/importlib/abc.py
Misc/NEWS

index 50f4ee4af858a708dff2489f0da100da14feb598..0adeefb2dc6658162f610718b951d704b1e49f1c 100644 (file)
@@ -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`.
index fbbac037a1875bc0bb73dba1fd01288c2726974f..4410de666d8dfc33ff5d0ec77d95e6cac3a6d035 100644 (file)
@@ -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
 =============
index 558abd3d9a409e2c187f84994b4f55d8b65447a4..7f6f235971d086bf9dbe1815c4e0afe8e9fd0727 100644 (file)
@@ -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'
index d47cebc18413b37e5bfd2daf34509f0f05cdff40..4b662b2c1facc0a63327b8a88efa505cfb0eb478 100644 (file)
--- 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.