[Python-Dev] method decorators (PEP 318)

Shane Hathaway shane at zope.com
Fri Mar 26 13:17:29 EST 2004

Skip Montanaro wrote:
> It's a shame that there's no good way to define function attributes already.
> Aside from the fact that this is different than the other form of
> "decoration", it's also different than setting attributes for classes.
> Rather than invent a unique syntax I'd prefer to either use a decorator
> function or suffer with tacking them on at the end:
>     def foobar(self, arg):
>         pass
>     foobar.author = "Guido van Rossum"
>     foobar.deprecated = True

It's interesting that this whole discussion is about placing 
declarations near the "def" statement, rather than after the function 
body.  It appears to be a surprisingly important detail.

Tossing out another idea:

         author = "Guido van Rossum"
         deprecated = True
     def foobar(self, arg):

The declaration block must be followed immediately by a class or def 
statement.  It looks elegant to me.


More information about the Python-Dev mailing list