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

Ethan Furman ethan at stoneleaf.us
Thu Sep 29 17:21:07 CEST 2011

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__.


More information about the Python-ideas mailing list