Skip to content

Commit

Permalink
bpo-37646: Document that eval() cannot access nested scopes (GH-15117)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger committed Aug 7, 2019
1 parent 3e41f3c commit 610a482
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
present and does not contain a value for the key ``__builtins__``, a
reference to the dictionary of the built-in module :mod:`builtins` is
inserted under that key before *expression* is parsed.
This means that *expression* normally has full
access to the standard :mod:`builtins` module and restricted environments are
propagated. If the *locals* dictionary is omitted it defaults to the *globals*
dictionary. If both dictionaries are omitted, the expression is executed in the
environment where :func:`eval` is called. The return value is the result of
inserted under that key before *expression* is parsed. This means that
*expression* normally has full access to the standard :mod:`builtins`
module and restricted environments are propagated. If the *locals*
dictionary is omitted it defaults to the *globals* dictionary. If both
dictionaries are omitted, the expression is executed with the *globals* and
*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:

>>> x = 1
Expand Down

0 comments on commit 610a482

Please sign in to comment.