diff -r 6f097ff9ac04 Doc/library/functions.rst --- a/Doc/library/functions.rst Mon Dec 12 19:18:24 2011 +0100 +++ b/Doc/library/functions.rst Mon Dec 12 16:22:54 2011 -0500 @@ -389,7 +389,12 @@ See :func:`ast.literal_eval` for a function that can safely evaluate strings with expressions containing only literals. + .. note:: + Note that free variables will be resolved in the *globals* and not *locals* name space. + See `Execution model `__ + for more information on how names in code passed to ``eval`` will be resolved. + .. function:: exec(object[, globals[, locals]]) This function supports dynamic execution of Python code. *object* must be @@ -427,7 +432,12 @@ Pass an explicit *locals* dictionary if you need to see effects of the code on *locals* after function :func:`exec` returns. + .. note:: + Note that free variables will be resolved in the *globals* and not *locals* name space. + See `Execution model `__ + for more information on how names in code passed to ``exec`` will be resolved. + .. function:: filter(function, iterable) Construct an iterator from those elements of *iterable* for which *function* diff -r 6f097ff9ac04 Doc/reference/executionmodel.rst --- a/Doc/reference/executionmodel.rst Mon Dec 12 19:18:24 2011 +0100 +++ b/Doc/reference/executionmodel.rst Mon Dec 12 16:22:54 2011 -0500 @@ -168,7 +168,8 @@ The :func:`eval` and :func:`exec` functions do not have access to the full environment for resolving names. Names may be resolved in the local and global -namespaces of the caller. Free variables are not resolved in the nearest +namespaces of the caller. Free variables in a ``def``, list comprehension, +generator expression, or lamba are not resolved in the nearest enclosing namespace, but in the global namespace. [#]_ The :func:`exec` and :func:`eval` functions have optional arguments to override the global and local namespace. If only one namespace is specified, it is used for both. @@ -233,5 +234,5 @@ .. rubric:: Footnotes .. [#] This limitation occurs because the code that is executed by these operations - is not available at the time the module is compiled. + is not available at the time the enclosing module or code fragment is compiled.