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

Ethan Furman ethan at stoneleaf.us
Thu Sep 29 17:00:38 CEST 2011

Nick Coghlan wrote:
>     @nonlocal(n=0, lock=threading.Lock())
>     def global_counter():
>         with lock:
>             n += 1
>             return n
> It's presence in the decorator list hints that this is something
> happening outside the functions ordinary local scope, as well as
> indicating when the initialisation happens. The 'nonlocal' then ties
> in with how they behave from the point of view of the code in the
> function body.

I think this fits in nicely with the @staticmethod and @classmethod 
decorator usage as well.


More information about the Python-ideas mailing list