New submission from Marco Buttu:
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
----------
assignee: docs@python
components: Documentation
messages: 282200
nosy: docs@python, marco.buttu
priority: normal
severity: normal
status: open
title: locals() and free variables
type: enhancement
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue28853>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com