[Python-Dev] PEP 572: Assignment Expressions (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Wed Apr 18 06:25:03 EDT 2018
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 18 April 2018 at 10:20, Guido van Rossum <guido at python.org> wrote: [Tim Peters wrote]
2. Back off and limit assignment expressions to what appears to be the overwhelmingly most common case motivated by looking at real code (as opposed to constructing examples to illustrate pitfalls & obscurities):
identifier ":=" expression I haven't had the time to follow this thread in detail; fortunately I don't have to because of Tim's excellent channeling. I am fine with this, it certainly seems the easiest to implement, with the fewest corner cases, and the easiest restriction to explain. (I was thinking there would be a use case for basic tuple unpacking, like seen a lot in for-loop, but the only examples I tried to come up with were pretty sub-optimal, so I don't worry about that any more.)
In the other direction I was thinking about the question "Then why do I think tuple unpacking is OK in comprehensions?", and realised that it's because in that situation there are keywords as delimiters on both sides (i.e. "... for name [, name]* in ..."), so it's harder for the unpacking operation to get confused with other uses of commas as separators. Similarly, in regular assignments, the unpacking target is always either between two "=" or else from the start of the line to the first "=".
By contrast, for assignment expressions, the only potential explicit opening delimiter is "(", and that's also the case for tuple literals.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]