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 rhettinger
Recipients docs@python, rhettinger
Date 2016-04-01.01:31:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1459474292.87.0.515226107717.issue26683@psf.upfronthosting.co.za>
In-reply-to
Content
The docs for locals() say that inside a function that local variables and free variables are included:  https://docs.python.org/3/library/functions.html#locals

Elsewhere we use the terms "cell variables" or "nonlocals".   Mathematically, the word "free" means unbound, so that isn't applicable here and isn't the usual way of describing variables in the enclosing scope.

>>> def f(x):
        def g(y):
            z = x + y
            print(locals())
        return g

>>> f(10)(20)
{'x': 10, 'y': 20, 'z': 30}

Also, I'm not sure why "x" and "y" are included in the definition for locals().  That seems strange given that "x" and "y" are not local to "g" and that "x += 1" would fail with an UnboundLocalError.
History
Date User Action Args
2016-04-01 01:31:32rhettingersetrecipients: + rhettinger, docs@python
2016-04-01 01:31:32rhettingersetmessageid: <1459474292.87.0.515226107717.issue26683@psf.upfronthosting.co.za>
2016-04-01 01:31:32rhettingerlinkissue26683 messages
2016-04-01 01:31:31rhettingercreate