Skip to content

Commit fc3dca3

Browse files
authored
Clarify eval() doc from library/functions. (GH-22700)
1 parent aefb69b commit fc3dca3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Doc/library/functions.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,15 @@ are always available. They are listed here in alphabetical order.
478478
dictionaries as global and local namespace. If the *globals* dictionary is
479479
present and does not contain a value for the key ``__builtins__``, a
480480
reference to the dictionary of the built-in module :mod:`builtins` is
481-
inserted under that key before *expression* is parsed. This means that
482-
*expression* normally has full access to the standard :mod:`builtins`
483-
module and restricted environments are propagated. If the *locals*
484-
dictionary is omitted it defaults to the *globals* dictionary. If both
485-
dictionaries are omitted, the expression is executed with the *globals* and
486-
*locals* in the environment where :func:`eval` is called. Note, *eval()*
487-
does not have access to the :term:`nested scopes <nested scope>` (non-locals) in the
488-
enclosing environment.
481+
inserted under that key before *expression* is parsed. That way you can
482+
control what builtins are available to the executed code by inserting your
483+
own ``__builtins__`` dictionary into *globals* before passing it to
484+
:func:`eval`. If the *locals* dictionary is omitted it defaults to the
485+
*globals* dictionary. If both dictionaries are omitted, the expression is
486+
executed with the *globals* and *locals* in the environment where
487+
:func:`eval` is called. Note, *eval()* does not have access to the
488+
:term:`nested scopes <nested scope>` (non-locals) in the enclosing
489+
environment.
489490

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

0 commit comments

Comments
 (0)