Skip to content

Commit 225b055

Browse files
authored
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().)
1 parent 77d5781 commit 225b055

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

0 commit comments

Comments
 (0)