[Python-ideas] Decorator syntax

Nick Coghlan ncoghlan at gmail.com
Thu Sep 3 00:22:46 CEST 2009


MRAB wrote:
>> However, this looks better to me:
>>
>>    @(a + b)
>>    @(a or (c and d))
>>
> Conditions in 'if' and 'while' statements don't need parentheses, so why
> do decorators?

Those are already closed by the colon so requiring parentheses would be
redundant:

 if a + b:
 while a + b:

The minimalist tweak would be to follow Guido's preference and just
accept subscripting in addition to calls.

>> So, in terms of Grammar/Grammar, what about
>>
>>    decorator: '@' atom trailer* NEWLINE
>>
> I say "keep it clean", ie no parentheses except where operator priority
> or clarity require them.

I actually agree with Georg that this is a case where clarity favours
enforced parentheses for expressions that are otherwise non-atomic.
Things like variable references, function calls and subscripting are
already atomic so the parentheses would be optional in those cases.

However, as long as Guido remains -0 extension to arbitrary expressions
isn't going to happen, parentheses or no parentheses.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------



More information about the Python-ideas mailing list