[Python-ideas] Tweaking closures and lexical scoping to include the function being defined
Paul Moore
p.f.moore at gmail.com
Thu Sep 29 23:48:58 CEST 2011
On 29 September 2011 22:36, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Paul Moore wrote:
>>
>> On 29 September 2011 14:30, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>
>>> @nonlocal(n=0, lock=threading.Lock())
>>> def global_counter():
>>> with lock:
>>> n += 1
>>> return n
>>>
>> The above says to me "the following
>> values are nonlocal to this function",
>
> It still has the problem that the *visibility* is *local*,
> directly contradicting what the keyword says.
I see what you mean. But I think with this version, the fact that the
variable is visible in the "decorator" call (i.e., just slightly
outside the function body) is enough to make me feel less
uncomfortable than the purely-within-the-function "nonlocal VAR from
EXPR" did...
Paul.
More information about the Python-ideas
mailing list