Decorator syntax

Terry Reedy tjreedy at udel.edu
Thu Aug 5 14:47:58 EDT 2004


> def(staticmethod) somemethod(self, args):
>     some code

>could you or someone else please enlighten me, as someone who wasn't
>following the decorator syntax discussion, why this syntax was ruled
>out?

That particular syntax -- deco in parens and jammed up against was never
proposed.  A similar syntax -- no parens and a space was.  Guide said a) he
thought there would be parser issues and b) this would cause problems with
all support tools that assume that the next name after def is the function
name.

Also, some of the major proponents want parameterized decorators and
multiple decorators, not just a different position for staticmethod and
classmethod.  So

def staticmethod func...

then becomes something like

def [mydeco(a,b,a), attributes({'a':1,sayonara:'haha'}), staticumethod]
func\
(longparamname, somemore):

and it becomes difficult to find the function name, which is the most
important thing, after all.

For what its worth: 1) this issue and multiple alternatives has been
discussed since at least Jan 03.  Since then, it has possibly taken more
devel time, and probably more Pydev postings than any single other issue;
2) the PEP is broken and Guido knows it.  We'll see if someone volunteers
to fix it.

Terry J. Reedy






More information about the Python-list mailing list