diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2018-08-19 10:25:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-19 10:25:33 (GMT) |
commit | 225b05548027d55aafb11b65f6a4a2bef2f5196f (patch) | |
tree | 6c00532cf207646c8af2442ee7965d9a7c201b8e /Doc | |
parent | 77d5781835b6e0a132694ebadc22b1cbdb9913f8 (diff) | |
download | cpython-225b05548027d55aafb11b65f6a4a2bef2f5196f.zip cpython-225b05548027d55aafb11b65f6a4a2bef2f5196f.tar.gz cpython-225b05548027d55aafb11b65f6a4a2bef2f5196f.tar.bz2 |
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().)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/functions.rst | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index e52b090..eb41e72 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -435,8 +435,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 |