[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Call for prudence about PEP-572

On 7/8/2018 1:59 PM, Chris Angelico wrote:
> On Mon, Jul 9, 2018 at 3:55 AM, Eric V. Smith <eric at trueblade.com> wrote:
>> I agree with Chris in this case. That said, there is at least one place
>> where the grammar does forbid you from doing something that would otherwise
>> make be allowable: decorators.
>>>>> @lookup[0]
>>    File "<stdin>", line 1
>>      @lookup[0]
>>             ^
>> SyntaxError: invalid syntax
>> But this works:
>>>>> new_decorator = lookup[0]
>>>>> @new_decorator
>> ... def f(): pass
>> Thus, the idea of restricting the type of expression that can be used in
>> particular circumstances is not without precedent, and should not be
>> dismissed at face value. That is, unless we want to remove the restriction
>> on decorators, which I'm okay with, too. I have occasionally wanted to do
>> something more complicated with a decorator, and used the workaround above.
> This is true. I wasn't around when decorator syntax was discussed;
> what were the reasons for this being the way it is? It isn't simply
> "'@' test".

I was around, but I don't recall the exact reasoning. Something along 
the lines of YAGNI, I believe.

The first reference I found to it is 
although surely there are older ones, and even this email references an 
older super-confusing use of lambdas in decorators.

In any event, I see no reason to restrict where assignment expressions 
can be used.