A decorator syntax not yet mentioned (I think!)

Peter Hansen peter at engcorp.com
Thu Aug 12 19:32:32 CEST 2004


paolo veronelli wrote:

> On Wed, 11 Aug 2004 11:40:32 -0400, Peter Hansen <peter at engcorp.com> wrote:
> I think 'mutate' is better then 'decorate', and anyway I like to see 
> what is mutated and the possibility to explicitate it make possible
> to move decorations from this position ,I put them where I like (at 
> least if I have to call them decorations) even in another file...
> 
> so
> 
> class Klass:
>     def meth0(x):
>         return x
>     mutate meth0:
>         staticmethod
> 
> mutate Klass.meth0:
>     debugged
> 
> reads good to me.

This has the disadvantage of repeating the function name.  I know
you call it an advantage...  but arguably the biggest part of
the whole decorator "argument" revolves around whether or not
it's critical to put the decorator right up above the "def" so
that it can't be missed.  If the method you describe above was
deemed acceptable, then I think we'd be sticking with the
current approach that just reads "func = decorate(func)".

-Peter



More information about the Python-list mailing list