This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author marco.buttu
Recipients docs@python, marco.buttu
Date 2016-12-01.16:54:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1480611277.06.0.950152525221.issue28853@psf.upfronthosting.co.za>
In-reply-to
Content
The locals() documentation [1] says that "Free variables are returned by locals() when it is called in function blocks". A free variable inside a function has a global scope, and in fact it is not returned by locals()::

>>> x = 33
>>> def foo():
...     print(x)
...     print(locals())
... 
>>> foo()
33
{}

Maybe "function blocks" here means "closure"? Does the doc mean this?

>>> def foo():
...     x = 33
...     def moo():
...         print(x)
...         print(locals())
...     return moo
... 
>>> moo = foo()
>>> moo()
33
{'x': 33}

In that case, I think it is better to write "closures" instead of 
"function blocks".


[1] https://docs.python.org/3/library/functions.html#locals
History
Date User Action Args
2016-12-01 16:54:37marco.buttusetrecipients: + marco.buttu, docs@python
2016-12-01 16:54:37marco.buttusetmessageid: <1480611277.06.0.950152525221.issue28853@psf.upfronthosting.co.za>
2016-12-01 16:54:37marco.buttulinkissue28853 messages
2016-12-01 16:54:36marco.buttucreate