On 03/02/2018 11:11 PM, Nick Coghlan wrote:
On 3 March 2018 at 03:51, Ethan Furman wrote:
Ah, right. Since the PEP primarily covers comprehensions, but then went on to discuss multi-line statements, I had forgotten the comprehension part. The answer is easy: assignment expressions in comprehensions stay inside comprehensions, just like other inner comprehension variables already do (function sub-scope, after all). Thank you for pointing that out.
That wasn't the point I was try to make: my attempted point was that I see allowing an expression like "print((f() as x), x^2, x^3)" to overwrite the regular function local "x" as being just as unacceptable as "data = [x^2 for x in sequence]" overwriting it, and we already decided that the latter was sufficiently undesirable that we were willing to break backwards compatibility in order to change it.
I think I explained myself poorly. I'm agreeing with you, and pointing out that the (var as expr) syntax /inside/ a comprehension would stay inside a comprehension, i.e. not leak out to locals(), just like your "x" above.