Docs: minor amendments to runpy.rst (#18416)

- Add missing single quote in inline code
- Align parameter formatting with style guide recommendations
- Fix punctuation around parenthesised sentence
This commit is contained in:
Géry Ogam 2024-01-23 01:00:26 +01:00 committed by GitHub
parent 5725523695
commit 647b6cc7f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -32,7 +32,7 @@ The :mod:`runpy` module provides two functions:
.. index::
pair: module; __main__
Execute the code of the specified module and return the resulting module
Execute the code of the specified module and return the resulting module's
globals dictionary. The module's code is first located using the standard
import mechanism (refer to :pep:`302` for details) and then executed in a
fresh module namespace.
@ -44,16 +44,16 @@ The :mod:`runpy` module provides two functions:
returned.
The optional dictionary argument *init_globals* may be used to pre-populate
the module's globals dictionary before the code is executed. The supplied
dictionary will not be modified. If any of the special global variables
below are defined in the supplied dictionary, those definitions are
the module's globals dictionary before the code is executed.
*init_globals* will not be modified. If any of the special global variables
below are defined in *init_globals*, those definitions are
overridden by :func:`run_module`.
The special global variables ``__name__``, ``__spec__``, ``__file__``,
``__cached__``, ``__loader__`` and ``__package__`` are set in the globals
dictionary before the module code is executed (Note that this is a
dictionary before the module code is executed. (Note that this is a
minimal set of variables - other variables may be set implicitly as an
interpreter implementation detail).
interpreter implementation detail.)
``__name__`` is set to *run_name* if this optional argument is not
:const:`None`, to ``mod_name + '.__main__'`` if the named module is a
@ -61,7 +61,7 @@ The :mod:`runpy` module provides two functions:
``__spec__`` will be set appropriately for the *actually* imported
module (that is, ``__spec__.name`` will always be *mod_name* or
``mod_name + '.__main__``, never *run_name*).
``mod_name + '.__main__'``, never *run_name*).
``__file__``, ``__cached__``, ``__loader__`` and ``__package__`` are
:ref:`set as normal <import-mod-attrs>` based on the module spec.
@ -104,11 +104,11 @@ The :mod:`runpy` module provides two functions:
pair: module; __main__
Execute the code at the named filesystem location and return the resulting
module globals dictionary. As with a script name supplied to the CPython
command line, the supplied path may refer to a Python source file, a
module's globals dictionary. As with a script name supplied to the CPython
command line, *file_path* may refer to a Python source file, a
compiled bytecode file or a valid :data:`sys.path` entry containing a
:mod:`__main__` module
(e.g. a zipfile containing a top-level ``__main__.py`` file).
(e.g. a zipfile containing a top-level :file:`__main__.py` file).
For a simple script, the specified code is simply executed in a fresh
module namespace. For a valid :data:`sys.path` entry (typically a zipfile or
@ -119,26 +119,26 @@ The :mod:`runpy` module provides two functions:
there is no such module at the specified location.
The optional dictionary argument *init_globals* may be used to pre-populate
the module's globals dictionary before the code is executed. The supplied
dictionary will not be modified. If any of the special global variables
below are defined in the supplied dictionary, those definitions are
the module's globals dictionary before the code is executed.
*init_globals* will not be modified. If any of the special global variables
below are defined in *init_globals*, those definitions are
overridden by :func:`run_path`.
The special global variables ``__name__``, ``__spec__``, ``__file__``,
``__cached__``, ``__loader__`` and ``__package__`` are set in the globals
dictionary before the module code is executed (Note that this is a
dictionary before the module code is executed. (Note that this is a
minimal set of variables - other variables may be set implicitly as an
interpreter implementation detail).
interpreter implementation detail.)
``__name__`` is set to *run_name* if this optional argument is not
:const:`None` and to ``'<run_path>'`` otherwise.
If the supplied path directly references a script file (whether as source
or as precompiled byte code), then ``__file__`` will be set to the
supplied path, and ``__spec__``, ``__cached__``, ``__loader__`` and
If *file_path* directly references a script file (whether as source
or as precompiled byte code), then ``__file__`` will be set to
*file_path*, and ``__spec__``, ``__cached__``, ``__loader__`` and
``__package__`` will all be set to :const:`None`.
If the supplied path is a reference to a valid :data:`sys.path` entry, then
If *file_path* is a reference to a valid :data:`sys.path` entry, then
``__spec__`` will be set appropriately for the imported :mod:`__main__`
module (that is, ``__spec__.name`` will always be ``__main__``).
``__file__``, ``__cached__``, ``__loader__`` and ``__package__`` will be
@ -146,7 +146,7 @@ The :mod:`runpy` module provides two functions:
A number of alterations are also made to the :mod:`sys` module. Firstly,
:data:`sys.path` may be altered as described above. ``sys.argv[0]`` is updated
with the value of ``path_name`` and ``sys.modules[__name__]`` is updated
with the value of *file_path* and ``sys.modules[__name__]`` is updated
with a temporary module object for the module being executed. All
modifications to items in :mod:`sys` are reverted before the function
returns.