aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-05-07 13:49:29 +0200
committerGitHub <noreply@github.com>2024-05-07 13:49:29 +0200
commitf85021a6a2f251883ac355a21f1ad51f7bf64fb7 (patch)
tree9d88e00ded71fd882968b83ca1afed169fae0275
parent56c61cc564eb1d990903cb28a8178674774add2e (diff)
downloadcpython3-f85021a6a2f251883ac355a21f1ad51f7bf64fb7.tar.gz
[3.12] gh-78612: Mark up eval() using param list (GH-115212) (#116044)
Also mention that the 'expression' parameter can be a string. (cherry picked from commit a71e32ce8e183023fc1ee401c22ebe35e4832f09) Co-authored-by: Erlend E. Aasland <erlend@python.org>
-rw-r--r--Doc/library/functions.rst20
1 files changed, 15 insertions, 5 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 7edcd5d5ac..b314cb2a70 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -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*
@@ -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')