Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9341dcb

Browse files
bpo-37646: Document that eval() cannot access nested scopes (GH-15117) (GH-15155)
(cherry picked from commit 610a482) Co-authored-by: Raymond Hettinger <[email protected]>
1 parent ef0b819 commit 9341dcb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Doc/library/functions.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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:
475479

476480
>>> x = 1

0 commit comments

Comments
 (0)