Skip to content

Commit

Permalink
pythongh-78612: Mark up eval() using param list (pythonGH-115212)
Browse files Browse the repository at this point in the history
Also mention that the 'expression' parameter can be a string.
(cherry picked from commit a71e32c)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
  • Loading branch information
erlend-aasland authored and miss-islington committed Feb 28, 2024
1 parent e5e9862 commit 2027193
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,20 @@ are always available. They are listed here in alphabetical order.

.. function:: eval(expression, globals=None, locals=None)

The arguments are a string and optional globals and locals. If provided,
*globals* must be a dictionary. If provided, *locals* can be any mapping
object.
:param expression:
A Python expression.
:type expression: :class:`str` | :ref:`code object <code-objects>`

:param globals:
The global namespace (default: ``None``).
:type globals: :class:`dict` | ``None``

:param locals:
The local namespace (default: ``None``).
:type locals: :term:`mapping` | ``None``

:returns: The result of the evaluated expression.
:raises: Syntax errors are reported as exceptions.

The *expression* argument is parsed and evaluated as a Python expression
(technically speaking, a condition list) using the *globals* and *locals*
Expand All @@ -545,8 +556,7 @@ are always available. They are listed here in alphabetical order.
:term:`nested scopes <nested scope>` (non-locals) in the enclosing
environment.

The return value is the result of
the evaluated expression. Syntax errors are reported as exceptions. Example:
Example:

>>> x = 1
>>> eval('x+1')
Expand Down

0 comments on commit 2027193

Please sign in to comment.