bpo-37646: Document that eval() cannot access nested scopes (GH-1511… · python/cpython@9341dcb

@@ -465,12 +465,16 @@ are always available. They are listed here in alphabetical order.

465465

dictionaries as global and local namespace. If the *globals* dictionary is

466466

present and does not contain a value for the key ``__builtins__``, a

467467

reference to the dictionary of the built-in module :mod:`builtins` is

468-

inserted under that key before *expression* is parsed.

469-

This means that *expression* normally has full

470-

access to the standard :mod:`builtins` module and restricted environments are

471-

propagated. If the *locals* dictionary is omitted it defaults to the *globals*

472-

dictionary. If both dictionaries are omitted, the expression is executed in the

473-

environment where :func:`eval` is called. The return value is the result of

468+

inserted under that key before *expression* is parsed. This means that

469+

*expression* normally has full access to the standard :mod:`builtins`

470+

module and restricted environments are propagated. If the *locals*

471+

dictionary is omitted it defaults to the *globals* dictionary. If both

472+

dictionaries are omitted, the expression is executed with the *globals* and

473+

*locals* in the environment where :func:`eval` is called. Note, *eval()*

474+

does not have access to the :term:`nested scope`\s (non-locals) in the

475+

enclosing environment.

476+477+

The return value is the result of

474478

the evaluated expression. Syntax errors are reported as exceptions. Example:

475479476480

>>> x = 1