tweaking @decorator syntax - yet another syntax

Stefan Eischet stefan at eischet.com
Fri Aug 6 12:51:02 EDT 2004


On 06.08.2004, at 14:08, Peter Hansen wrote:

> Stefan Eischet wrote:
>
>> I don't know if this particular syntax has been discussed
>> already... please feel free to bash me if it was. ;-)
>
> Bash bash.

Okay, I was asking for it. ;-) I didn't have the time to read the PEP
this morning, but I now have and still like the idea. For my
personal taste, it's way better than the ugly @ thing and a bit
more explicit than the "[]"-syntax.

>> How about using "is" after the def?
>
> Read the PEP.  Basically the same as the "as" variant.

Basically, yes. IMO there are a few important differences, though.

 From the PEP:

|Several other syntaxes have been proposed:
|def func(arg1, arg2, ...) as dec1, dec2, ...:
|    pass
|
|The absence of brackets makes it cumbersome to break long lists of
|decorators across multiple lines, and the keyword "as" doesn't have
|the same meaning as its use in the import statement. Plenty of
|alternatives to "as" [12] have been proposed. :-)

This one has optional brackets, so the breaking problems go away. ;-)

Just like the "[]" thing, this one should look familiar to Python
programmers. Lists, to me, imply that the object can be changed.
But tuples are constant, right? Or is it intended to be able to change
the decoration at runtime?

I personally also dislike the "[]"-syntax because its
placement looks quite random to me.

"is" is used in another way than usual, though, but I think it's
very close to the english meaning of "is".

Also from the PEP:

|without the intermediate assignment to the variable func. The
|decorators are near the function declaration. The @ sign makes
|it clear that something new is going on here.

"Something new" is exactly what I, personally, wouldn't like to
see in Python. How long is it supposed to look "new"? They didn't
introduce a new look or funky symbols for new style classes, for
example. When people have seen enough of @, will they have to introduce
even "newer" symbols? ;-)

But regardless of which syntax they choose, I guess I'll get used to
it sooner or later.

Cheers,
   Stefan




More information about the Python-list mailing list