[Python-Dev] Informal educator feedback on PEP 572 (was Re: 2018 Python Language Summit coverage, last part)
On 27.06.2018 16:25, Greg Ewing wrote:
> Ivan Pozdeev via Python-Dev wrote:
>> Using this assigned result elsewhere in the same expression (akin to
>> regex backreferences) is not a part of the basic idea actually.
> If that's true, then the proposal has mutated into something
> that has *no* overlap whatsoever with the use case that started
> this whole discussion,
I don't know what and where "started" it (AFAIK the idea has been around
for years) but for me, the primary use case for an assignment expression
is to be able to "catch" a value into a variable in places where I can't
put an assignment statement in, like the infamous `if re.match() is not
> which was about binding a temporary
> variable in a comprehension, for use *within* the comprehension.
Then I can't understand all the current fuss about scoping.
AFAICS, it's already like I described in
the outermost iterable is evaluated in the local scope while others in
the internal one:
In : [(l,i) for l in list(locals())[:5] for i in locals()]
(note that `i' is bound after the first evaluation of internal
`locals()' btw, as to be expected)
If the "temporary variables" are for use inside the comprehension only,
the assignment expression needs to bind in the current scope like the
regular assignment statement, no changes are needed!
>> It depends on the evaluation order (and whether something is
>> evaluated at all),
> Which to my mind is yet another reason not to like ":=".