[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Guido van Rossum guido at python.org
Thu Sep 29 18:51:46 CEST 2011


On Thu, Sep 29, 2011 at 8:21 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Paul Moore wrote:
>>
>> Actually, while we're using keywords as decorator names,
>>
>> @with(n=0, lock=threading.Lock())
>> def global_counter():
>>    with lock:
>>        n += 1
>>        return n
>>
>> reads well to me, and avoids the technical/jargon word "nonlocal".
>
> I think 'nonlocal' is the better choice as it mirrors what nonlocal does
> inside the function.  Because of its current usage 'with' will generate
> questions about __enter__ and __exit__.

+1

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list