mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
bpo-37646: Document that eval() cannot access nested scopes (GH-15117) (GH-15155)
(cherry picked from commit 610a4823cc
)
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
This commit is contained in:
parent
ef0b81927a
commit
9341dcb4b9
1 changed files with 10 additions and 6 deletions
|
@ -465,12 +465,16 @@ 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.
|
inserted under that key before *expression* is parsed. This means that
|
||||||
This means that *expression* normally has full
|
*expression* normally has full access to the standard :mod:`builtins`
|
||||||
access to the standard :mod:`builtins` module and restricted environments are
|
module and restricted environments are propagated. If the *locals*
|
||||||
propagated. If the *locals* dictionary is omitted it defaults to the *globals*
|
dictionary is omitted it defaults to the *globals* dictionary. If both
|
||||||
dictionary. If both dictionaries are omitted, the expression is executed in the
|
dictionaries are omitted, the expression is executed with the *globals* and
|
||||||
environment where :func:`eval` is called. The return value is the result of
|
*locals* in the environment where :func:`eval` is called. Note, *eval()*
|
||||||
|
does not have access to the :term:`nested scope`\s (non-locals) in the
|
||||||
|
enclosing environment.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
>>> x = 1
|
>>> x = 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue