Skip to content

Commit f19579b

Browse files
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 225b055) Co-authored-by: Berker Peksag <[email protected]>
1 parent fed8718 commit f19579b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Doc/library/functions.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,10 @@ are always available. They are listed here in alphabetical order.
420420
The *expression* argument is parsed and evaluated as a Python expression
421421
(technically speaking, a condition list) using the *globals* and *locals*
422422
dictionaries as global and local namespace. If the *globals* dictionary is
423-
present and lacks '__builtins__', the current globals are copied into *globals*
424-
before *expression* is parsed. This means that *expression* normally has full
423+
present and does not contain a value for the key ``__builtins__``, a
424+
reference to the dictionary of the built-in module :mod:`builtins` is
425+
inserted under that key before *expression* is parsed.
426+
This means that *expression* normally has full
425427
access to the standard :mod:`builtins` module and restricted environments are
426428
propagated. If the *locals* dictionary is omitted it defaults to the *globals*
427429
dictionary. If both dictionaries are omitted, the expression is executed in the

0 commit comments

Comments
 (0)