[Python-Dev] Call for prudence about PEP-572 (original) (raw)
Eric V. Smith eric at trueblade.com
Sun Jul 8 14:20:54 EDT 2018
- Previous message (by thread): [Python-Dev] Call for prudence about PEP-572
- Next message (by thread): [Python-Dev] Call for prudence about PEP-572
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 "", line 1 @lookup[0] ^ SyntaxError: invalid syntax But this works: newdecorator = lookup[0] @newdecorator ... 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 https://mail.python.org/pipermail/python-ideas/2009-September/005623.html, 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.
Eric
- Previous message (by thread): [Python-Dev] Call for prudence about PEP-572
- Next message (by thread): [Python-Dev] Call for prudence about PEP-572
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]