diff options
author | Antoine <43954001+awecx@users.noreply.github.com> | 2020-12-16 15:45:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-16 15:45:19 (GMT) |
commit | fc3dca3e16a62690707dcdc923a577e5167a8e2a (patch) | |
tree | f0d56cd1946c50c9edc67acad41ed3217dd768fd /Doc/library | |
parent | aefb69b23f056c61e82ad228d950f348de090c70 (diff) | |
download | cpython-fc3dca3e16a62690707dcdc923a577e5167a8e2a.zip cpython-fc3dca3e16a62690707dcdc923a577e5167a8e2a.tar.gz cpython-fc3dca3e16a62690707dcdc923a577e5167a8e2a.tar.bz2 |
Clarify eval() doc from library/functions. (GH-22700)
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/functions.rst | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index a8a4ca4..24dc65d 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -478,14 +478,15 @@ are always available. They are listed here in alphabetical order. dictionaries as global and local namespace. If the *globals* dictionary is 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 with the *globals* and - *locals* in the environment where :func:`eval` is called. Note, *eval()* - does not have access to the :term:`nested scopes <nested scope>` (non-locals) in the - enclosing environment. + inserted under that key before *expression* is parsed. That way you can + control what builtins are available to the executed code by inserting your + own ``__builtins__`` dictionary into *globals* before passing it to + :func:`eval`. If the *locals* dictionary is omitted it defaults to the + *globals* dictionary. If both dictionaries are omitted, the expression is + executed with the *globals* and *locals* in the environment where + :func:`eval` is called. Note, *eval()* does not have access to the + :term:`nested scopes <nested scope>` (non-locals) in the enclosing + environment. The return value is the result of the evaluated expression. Syntax errors are reported as exceptions. Example: |