Decorator Syntax

Rafe Kettler rafe.kettler at gmail.com
Tue Mar 22 09:14:53 EDT 2011


On Mar 21, 8:59 pm, Mike Patterson <mikepatterso... at gmail.com> wrote:
> In my Python class the other day, the professor was going over
> decorators and he briefly mentioned that there had been this huge
> debate about the syntax and using the @ sign to signify decorators.
>
> I read about the alternative forms proposed here (http://www.python.org/dev/peps/pep-0318/#syntax-alternatives).
>
> Has anyone thought about just using dec to declare a decorator?
>
> For example:
> dec dec2
> dec dec1
> def func(arg1, arg2, ...):
>     pass

I personally love the @ syntax for two reasons:
 1. It makes it very, very obvious that a decorator is being used
 2. It feels closely tied to the function or class that it's
decorating
The 'dec' syntax isn't quite as good in those regards, IMO. It
basically looks like any other statement, which makes it less visible,
and it doesn't seem as closely tied syntactically.

Of course, that's all opinion. But what's done is done; it's doubtful
that the decorator syntax will ever change significantly.

Rafe



More information about the Python-list mailing list