[New-bugs-announce] [issue26683] Questionable terminology for describing what locals() does

Raymond Hettinger report at bugs.python.org
Thu Mar 31 21:31:32 EDT 2016


New submission from Raymond Hettinger:

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.

----------
assignee: docs at python
components: Documentation
messages: 262713
nosy: docs at python, rhettinger
priority: normal
severity: normal
status: open
title: Questionable terminology for describing what locals() does
versions: Python 2.7, Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26683>
_______________________________________


More information about the New-bugs-announce mailing list