[docs] [issue28853] locals() and free variables

Marco Buttu report at bugs.python.org
Fri Dec 2 06:32:02 EST 2016

Marco Buttu added the comment:

In addition, also if here "function blocks" means nested function, the sentence "Free variables are returned by locals() when it is called in function blocks" I think is wrong. It is true only in case of free variables belonging to the local enclosing scope. For instance, in the following case ``x`` is free in ``moo()``, but it is not in ``locals()``::

>>> x = 10
>>> def foo():
...     def moo():
...         print(x)
...         print(locals())
...     return moo
>>> moo = foo()
>>> moo()

I attach a patch with a new description and an example.

PS. Is the rst rendered by Sphinx? In that case, why we are not using the doctest Sphinx extension to test the code examples?

keywords: +patch
Added file: http://bugs.python.org/file45732/locals_func.patch

Python tracker <report at bugs.python.org>

More information about the docs mailing list