Skip to content

Commit 1dcff40

Browse files
authored
Address review: Update eval() docs and fix reflowing
- Revert paragraph reflowing in exec() docs. - Update eval() documentation to clarify it accepts a bytes-like object.
1 parent df37fa1 commit 1dcff40

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

Doc/library/functions.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ are always available. They are listed here in alphabetical order.
590590

591591
:param source:
592592
A Python expression.
593-
:type source: :class:`str` | :ref:`code object <code-objects>`
593+
:type source: :class:`str` | :term:`bytes-like object` | :ref:`code object <code-objects>`
594594

595595
:param globals:
596596
The global namespace (default: ``None``).
@@ -633,15 +633,15 @@ are always available. They are listed here in alphabetical order.
633633

634634
This function can also be used to execute arbitrary code objects (such as
635635
those created by :func:`compile`). In this case, pass a code object instead
636-
of a string. If the code object has been compiled with ``'exec'`` as the
636+
of a string or a bytes-like object. If the code object has been compiled with ``'exec'`` as the
637637
*mode* argument, :func:`eval`\'s return value will be ``None``.
638638

639639
Hints: dynamic execution of statements is supported by the :func:`exec`
640640
function. The :func:`globals` and :func:`locals` functions
641641
return the current global and local dictionary, respectively, which may be
642642
useful to pass around for use by :func:`eval` or :func:`exec`.
643643

644-
If the given source is a string, then leading and trailing spaces and tabs
644+
If the given source is a string or a bytes-like object, then leading and trailing spaces and tabs
645645
are stripped.
646646

647647
See :func:`ast.literal_eval` for a function to evaluate strings
@@ -675,15 +675,15 @@ are always available. They are listed here in alphabetical order.
675675
untrusted user-supplied input will lead to security vulnerabilities.
676676

677677
This function supports dynamic execution of Python code. *source* must be
678-
a string, a bytes-like object, or a code object. If it is a string or a
679-
bytes-like object, it is parsed as a suite of Python statements which is
680-
then executed (unless a syntax error occurs). [#]_ If it is a code object,
681-
it is simply executed. In all cases, the code that's executed is expected
682-
to be valid as file input (see the section :ref:`file-input` in the
683-
Reference Manual). Be aware that the :keyword:`nonlocal`, :keyword:`yield`,
684-
and :keyword:`return` statements may not be used outside of function
685-
definitions even within the context of code passed to the :func:`exec`
686-
function. The return value is ``None``.
678+
a string, a bytes-like object or a code object. If it is a string or a bytes-like object, it is parsed as
679+
a suite of Python statements which is then executed (unless a syntax error
680+
occurs). [#]_ If it is a code object, it is simply executed. In all cases,
681+
the code that's executed is expected to be valid as file input (see the
682+
section :ref:`file-input` in the Reference Manual). Be aware that the
683+
:keyword:`nonlocal`, :keyword:`yield`, and :keyword:`return`
684+
statements may not be used outside of
685+
function definitions even within the context of code passed to the
686+
:func:`exec` function. The return value is ``None``.
687687

688688
In all cases, if the optional parts are omitted, the code is executed in the
689689
current scope. If only *globals* is provided, it must be a dictionary

0 commit comments

Comments
 (0)