[Python-Dev] Decorators: vertical bar syntax

Nick Bastin nbastin at opnet.com
Sat Aug 7 06:56:34 CEST 2004


On Aug 7, 2004, at 12:35 AM, Edward Loper wrote:

> The new "vertical bar" syntax was proposed recently, and has gotten
> almost unanimously positive feedback.  In particular, of 17 responses
> to the syntax, only one has been negative (see table, below).
>
> I'm including both of the following variants:
>
>     |classmethod
>     |accepts(int, int)
>     |returns(float)
>     def foo(arg1, arg2):
>         ...
>
>     def foo(arg1, arg2):
>         |classmethod
>         |accepts(int, int)
>         |returns(float)

I have to admit that at first look, the decorator-after-def syntax 
wasn't very appealing.  However, although it's not how other languages 
generally do it (does anybody know of one?), it might be easier for new 
users to understand.  i.e., I'm decorating 'this' thing, rather than 
the 'next' thing.

Does anybody suggest how this syntax plays with docstrings?  Are 
decorators after the doc string, or before, or doesn't it matter?  My 
vote would be for after the doc string, but I thought I'd throw that 
out there.  It's also entirely possible that no one else likes the 
after-def syntax, so maybe this isn't a bridge we'll have to cross.. 
:-)

As for pipe versus @, I couldn't really care less, since my syntax 
highlighter will take care of it, but for new users I think '@' stands 
out much better.  On the other hand, we might want to reserve '@' for 
some future use more aligned to its' usual meaning.  Heck, I'm 
surprised that any rational discussion is happening at all at this 
point.

Seriously, we've been discussing this for longer than I care to think 
about, and it's obvious that we're not going to get something that 
everyone agrees upon.  If there were something that everyone could 
agree upon, we'd already have found it - it's not like a pile of new 
discussion is likely to change that, so if we stick with 
'@'-before-def, that's fine by me too.

--
Nick



More information about the Python-Dev mailing list