Skip to content

Commit 0e1e8db

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 2e4ae8f commit 0e1e8db

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
@@ -434,8 +434,10 @@ are always available. They are listed here in alphabetical order.
434434
The *expression* argument is parsed and evaluated as a Python expression
435435
(technically speaking, a condition list) using the *globals* and *locals*
436436
dictionaries as global and local namespace. If the *globals* dictionary is
437-
present and lacks '__builtins__', the current globals are copied into *globals*
438-
before *expression* is parsed. This means that *expression* normally has full
437+
present and does not contain a value for the key ``__builtins__``, a
438+
reference to the dictionary of the built-in module :mod:`builtins` is
439+
inserted under that key before *expression* is parsed.
440+
This means that *expression* normally has full
439441
access to the standard :mod:`builtins` module and restricted environments are
440442
propagated. If the *locals* dictionary is omitted it defaults to the *globals*
441443
dictionary. If both dictionaries are omitted, the expression is executed in the

0 commit comments

Comments
 (0)