Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3d1cac

Browse files
committed
Issue #15230: Update runpy docs to clarify a couple of points that came up in this issue
1 parent 761bb11 commit a3d1cac

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

Doc/library/runpy.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ importing them first. Its main use is to implement the :option:`-m` command
1414
line switch that allows scripts to be located using the Python module
1515
namespace rather than the filesystem.
1616

17+
Note that this is *not* a sandbox module - all code is executed in the
18+
current process, and any side effects (such as cached imports of other
19+
modules) will remain in place after the functions have returned.
20+
21+
Furthermore, any functions and classes defined by the executed code are not
22+
guaranteed to work correctly after a :mod:`runpy` function has returned.
23+
If that limitation is not acceptable for a given use case, :mod:`importlib`
24+
is likely to be a more suitable choice than this module.
25+
1726
The :mod:`runpy` module provides two functions:
1827

1928

@@ -141,3 +150,5 @@ The :mod:`runpy` module provides two functions:
141150
PEP written and implemented by Nick Coghlan.
142151

143152
:ref:`using-on-general` - CPython command line details
153+
154+
The :func:`importlib.import_module` function

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ Build
384384
Documentation
385385
-------------
386386

387+
- Issue #15230: Clearly document some of the limitations of the runpy
388+
module and nudge readers towards importlib when appropriate.
389+
387390
- Issue #13557: Clarify effect of giving two different namespaces to exec or
388391
execfile().
389392

0 commit comments

Comments
 (0)