A decorator syntax not yet mentioned (I think!)
Jeff Shannon
jeff at ccvcorp.com
Wed Aug 11 14:29:54 EDT 2004
Michael Sparks wrote:
>Peter Hansen wrote:
>
>
>>class Klass:
>> # init set
>>
>> decorate:
>> staticmethod
>> def meth0(x):
>> return x
>>
>>
>
>[snip]
>My initial reaction to @decorators was "ugh!". However I was coming to
>accept it as inevitable after reading the various arguments for/against
>various syntaxes. *This* syntax strikes me personally as having
>distinct advantages - largely for clarity of code, and solves the
>"where *DOES* the function start?" question with large decorator
>blocks.
>
I agree. This seems to fit the absolute requirements I've heard passed
down from GvR, and also avoids all of the things that really made my
teeth grate about the @decorator syntax. It's the first prefix syntax
I've seen that actually *looks* like Python to my eyes.
There's still room for discussion about the specific keyword (I'd be
happy enough with "decorate", and not so fond of "using" or "with", but
a case could easily be made for something else...) and about ordering --
presenting the decorators as a suite
decorate:
d1
d2
def method( ... )
pass
suggests to me an equivalence to
method = d2(d1(method))
which is the reverse of the ordering of @decorators. How significant
the difference is, I can't say...
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list