Clarify eval() doc from library/functions. (GH-22700)

This commit is contained in:
Antoine 2020-12-16 16:45:19 +01:00 committed by GitHub
parent aefb69b23f
commit fc3dca3e16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 8 deletions

View File

@ -478,14 +478,15 @@ are always available. They are listed here in alphabetical order.
dictionaries as global and local namespace. If the *globals* dictionary is dictionaries as global and local namespace. If the *globals* dictionary is
present and does not contain a value for the key ``__builtins__``, a present and does not contain a value for the key ``__builtins__``, a
reference to the dictionary of the built-in module :mod:`builtins` is reference to the dictionary of the built-in module :mod:`builtins` is
inserted under that key before *expression* is parsed. This means that inserted under that key before *expression* is parsed. That way you can
*expression* normally has full access to the standard :mod:`builtins` control what builtins are available to the executed code by inserting your
module and restricted environments are propagated. If the *locals* own ``__builtins__`` dictionary into *globals* before passing it to
dictionary is omitted it defaults to the *globals* dictionary. If both :func:`eval`. If the *locals* dictionary is omitted it defaults to the
dictionaries are omitted, the expression is executed with the *globals* and *globals* dictionary. If both dictionaries are omitted, the expression is
*locals* in the environment where :func:`eval` is called. Note, *eval()* executed with the *globals* and *locals* in the environment where
does not have access to the :term:`nested scopes <nested scope>` (non-locals) in the :func:`eval` is called. Note, *eval()* does not have access to the
enclosing environment. :term:`nested scopes <nested scope>` (non-locals) in the enclosing
environment.
The return value is the result of The return value is the result of
the evaluated expression. Syntax errors are reported as exceptions. Example: the evaluated expression. Syntax errors are reported as exceptions. Example: