Confused about pep 318

Peter Hansen peter at engcorp.com
Fri Aug 6 07:58:15 EDT 2004


Steven Bethard wrote:
> Even the list-after-def syntax,
> which doesn't introduce semantics changes, isn't substantially clearer
> to me as a decorator than @ is -- why is a list before the : a list of
> decorators?  Seems almost as arbitrary as @.

The list-after-def is in that one sense as arbitrary as @, but at least
it feels more like Python.  It would be clear that the decorators
are applied in the order presented in the list, and since the list
clearly isn't be a normal list (coming before the def), anyone reading
it would know that it must have something to do with the function
definition.  (Anyway, as has been pointed out, the Java-based @ syntax
is not entirely arbitrary at this point, deriving from the Javadoc
comment syntax... I just think doc-generation system syntax embedded
inside code comments in another language is a poor place from which to
derive syntax for *Python*, which is why I said Python isn't exactly
leading in this area, but following, which is sad.)

The only negative mentioned for list-after-def that I've seen is that
with long argument lists it can be obscured.  I wasn't aware of the very
wide range of possible uses for decorators (not that I think many of
them are really that important), but it does seem likely that with much
more than staticmethod/classmethod around, something like @ will end
up being required because decorators will add so much to the language
that someone will be incapable of using Python without knowing all about
decorators.  (Viz. e.g. the "singleton" example, or "onexit")

If decorators will be used as much as it appears they will be, then the
"pie" syntax with the @ sign is perhaps best, simply because it is
so "in your face".  Barry named it well...

(I would like to see an alternative with "from __future__ import "
as well, but I'm not the one doing the work on this...)

-Peter



More information about the Python-list mailing list