File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -499,7 +499,7 @@ ABC hierarchy::
499499 .. versionchanged :: 3.4
500500 Raises :exc: `ImportError ` instead of :exc: `NotImplementedError `.
501501
502- .. method :: source_to_code(data, path='<string>')
502+ .. staticmethod :: source_to_code(data, path='<string>')
503503
504504 Create a code object from Python source.
505505
@@ -508,8 +508,14 @@ ABC hierarchy::
508508 the "path" to where the source code originated from, which can be an
509509 abstract concept (e.g. location in a zip file).
510510
511+ With the subsequent code object one can execute it in a module by
512+ running ``exec(code, module.__dict__) ``.
513+
511514 .. versionadded :: 3.4
512515
516+ .. versionchanged :: 3.5
517+ Made the method static.
518+
513519 .. method :: exec_module(module)
514520
515521 Implementation of :meth: `Loader.exec_module `.
Original file line number Diff line number Diff line change @@ -158,6 +158,11 @@ Improved Modules
158158 *module * contains no docstrings instead of raising :exc: `ValueError `
159159 (contributed by Glenn Jones in :issue: `15916 `).
160160
161+ * :func: `importlib.abc.InspectLoader.source_to_code ` is now a
162+ static method to make it easier to work with source code in a string.
163+ With a module object that you want to initialize you can then use
164+ ``exec(code, module.__dict__) `` to execute the code in the module.
165+
161166
162167Optimizations
163168=============
Original file line number Diff line number Diff line change @@ -217,7 +217,8 @@ def get_source(self, fullname):
217217 """
218218 raise ImportError
219219
220- def source_to_code (self , data , path = '<string>' ):
220+ @staticmethod
221+ def source_to_code (data , path = '<string>' ):
221222 """Compile 'data' into a code object.
222223
223224 The 'data' argument can be anything that compile() can handle. The'path'
Original file line number Diff line number Diff line change @@ -73,6 +73,9 @@ Core and Builtins
7373Library
7474-------
7575
76+ - Issue #21156: importlib.abc.InspectLoader.source_to_code() is now a
77+ staticmethod.
78+
7679- Issue #21396: Fix TextIOWrapper(..., write_through=True) to not force a
7780 flush() on the underlying binary stream. Patch by akira.
7881
You can’t perform that action at this time.
0 commit comments