[Python-checkins] bpo-22057: Clarify eval() documentation (GH-8812)

Miss Islington (bot) webhook-mailer at python.org
Sun Aug 19 06:32:15 EDT 2018


https://github.com/python/cpython/commit/f19579b8f1fcd2dd8ffaf3e443b09930057c01d1
commit: f19579b8f1fcd2dd8ffaf3e443b09930057c01d1
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-08-19T06:32:12-04:00
summary:

bpo-22057: Clarify eval() documentation (GH-8812)


If a globals dictionary without a '__builtins__' key is passed to
eval(), a '__builtins__' key will be inserted to the dictionary:

    >>> eval("print('__builtins__' in globals())", {})
    True

(As a result of this behavior, we can use the builtins
print() and globals() even if we passed a dictionary without a
'__builtins__' key to eval().)
(cherry picked from commit 225b05548027d55aafb11b65f6a4a2bef2f5196f)

Co-authored-by: Berker Peksag <berker.peksag at gmail.com>

files:
M Doc/library/functions.rst

diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 9ebadfca0f57..b6e52469bd85 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -420,8 +420,10 @@ are always available.  They are listed here in alphabetical order.
    The *expression* argument is parsed and evaluated as a Python expression
    (technically speaking, a condition list) using the *globals* and *locals*
    dictionaries as global and local namespace.  If the *globals* dictionary is
-   present and lacks '__builtins__', the current globals are copied into *globals*
-   before *expression* is parsed.  This means that *expression* normally has full
+   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



More information about the Python-checkins mailing list