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

Masklinn masklinn at masklinn.net
Thu Sep 29 17:20:58 CEST 2011


On 2011-09-29, at 17:15 , 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". Let
> the @keyword floodgates open :-)
> 
The problem with that one is that it's going to be read
in light of the corresponding keyword, so it'd make people
think the purpose is to __enter__/__exit__ all objects
provided around the function call somehow (pretty nice 
for the lock, nonsensical for the integer, of course).



More information about the Python-ideas mailing list