[Python-checkins] bpo-37646: Document that eval() cannot access nested scopes (GH-15117) (GH-15155)
Raymond Hettinger
webhook-mailer at python.org
Tue Aug 6 21:08:03 EDT 2019
https://github.com/python/cpython/commit/9341dcb4b9520ab92df10d4256e93a50e1e7d19f
commit: 9341dcb4b9520ab92df10d4256e93a50e1e7d19f
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2019-08-06T18:07:59-07:00
summary:
bpo-37646: Document that eval() cannot access nested scopes (GH-15117) (GH-15155)
(cherry picked from commit 610a4823cc0a3c2380ad0dfe64ae483ced4e5304)
Co-authored-by: Raymond Hettinger <rhettinger at users.noreply.github.com>
files:
M Doc/library/functions.rst
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index e146f5a95acc..c225f3dee921 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -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
More information about the Python-checkins
mailing list