Decorator syntax

Peter Hansen peter at engcorp.com
Wed Aug 4 22:58:47 EDT 2004


C. Barnes wrote:

> I vote for
> 
> def f(): [synchronized, classmethod]
>   (body of function)
> 
> This is backwards compatible (Python <= 2.3 raise
> SyntaxError), and looks much nicer than @.

I'm nearly certain, without bothering to check, that this
was one of the many proposals already discussed and rejected,
if nothing else for the simple reason that it only works
nicely when you have a short definition such as your example
(with "f()") and not nicely at all with a much longer name
and argument list.  Inevitably you would need to split the
decorator part onto a second line, either requiring a
backslash (ugly) or changing your second comment about it
raising a SyntaxError with previous versions (because it
then matches valid though meaningless code).

Anyway, check the past discussions before going back around
the same arguments yet again.

For the record, the @ syntax is despicable and horribly
un-Pythonic, IMHO, and I really hope never to read code that
uses it. :-(

(And my preferred syntax was "def f() [classmethod]:", FWIW)

-Peter



More information about the Python-list mailing list