[Python-Dev] Re: PEP 318: Decorators last before colon
Andrew Koenig
ark-mlist at att.net
Mon Apr 5 10:42:40 EDT 2004
[I've mentioned this idea before, but don't recall seeing any responses to
it; so I'm mentioning it again in case it got lost the first time]
I am concerned about putting decorators before the function definition
because of the possibility of such code quietly sneaking through existing
compilers:
[classmethod]
def foo(bar, baz):
pass
Guido is concerned about putting decorators after the function definition
because there may be a lot of them and it may be hard to read:
def foo(bar, baz) \
[staticmethod, classmethod, otherattributes(debug=True}) }:
pass
Here's what I don't understand.
I imagine that most of the time, when someone decorates a function with lots
of attributes, there is at least the possibility of decorating more than one
function with the same set of attributes.
In such a case, doesn't it make sense to bind a variable to the attributes
and use it instead?
Attributes = [staticmethod, classmethod,
otherattributes(debug=True)]
def foo(bar, baz) Attributes:
pass
And doesn't this idea answer the objection that too many attributes after
the parameter list make the definition hard to read?
For that matter, why do we need the brackets if there is only one attribute:
def foo(bar, baz) staticmethod:
pass
I am suggesting that what comes between the ) and the : should be an
expression, which must evaluate to either a callable or a sequence of
callables. For that matter, why not allow a tuple expression without
parentheses:
def foo(bar, baz) staticmethod, classmethod:
pass
Whatever sequence you put there, I think the semantics are clear: Before
binding a name to the function, pass it to the callable or in turn to each
element of the sequence.
More information about the Python-Dev
mailing list