[Python-ideas] The way decorators are parsng

Guido van Rossum guido at python.org
Thu Oct 20 05:48:45 CEST 2011


2011/10/19 Nick Coghlan <ncoghlan at gmail.com>:
> 2011/10/20 Guido van Rossum <guido at python.org>:
>> If this gets changed we won't be able to give a different meaning to e.g.
>>
>> @(...)
>> @[...]
>> @{...}
>>
>> since those will all have to be accepted as valid forms of the syntax
>>
>> @<expr>
>
> True, although the restriction could just be weakened to "must start
> with an identifier" rather than eliminated entirely. Since tuples,
> lists, dictionaries and sets aren't callable, that wouldn't be a
> noticeable restriction in practice.

But surely someone would manage to come up with a use case for an
expression *starting* with one of those, e.g.

@[f, g, h][i]

or

@{a: b, c: d}[x]

I don't think it's reasonable to constrain it less than it currently
is but more than a general expression. Though I wouldn't allow commas
-- there's no way that

@f, g
def pooh(): ...

can make sense. Oh way, it could be a shorthand for

@f
@g
def pooh(): ...

:-)

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list