[Python-Dev] PEP 572: Assignment Expressions -- intention to accept, near-final draft
v+python at g.nevcal.com
Tue Jul 10 00:06:10 EDT 2018
On 7/9/2018 8:43 PM, Guido van Rossum wrote:
>> An exception to this special case applies when the target name is the
>> same as a loop control variable for a comprehension containing it.
>> This is invalid. This exception exists to rule out edge cases of the
>> above scope rules as illustrated by ``[i := i+1 for i in range(5)]``
>> or ``[[(j := j) for i in range(5)] for j in range(5)]``. Note that
>> this exception also applies to ``[i := 0 for i, j in stuff]``, as
>> as to cases like ``[i+1 for i in i := stuff]``.
> It is unclear whether exactly what is invalid. Is the use of the
> target name that is the same as (any of the nested) loop control
> variable invalid? I think, from discussions, that that is what is
> meant. But this paragraph could be interpreted as meaning the
> special case doesn't apply, meaning that the target name would be
> in a "sublocal" scope.
> Really? If it didn't say "this is invalid" I could see that "exception
> to the special case" might be interpreted as "the special case doesn't
> apply". But with "This is invalid" explicitly added I don't see how
> that interpretation could be valid. Is it clearer if I changed that to
> "Such code is invalid"? Or perhaps I should move "This is invalid" to
> the end of the paragraph?
That's better; even better might be to say what is invalid... instead of
"Use of any of the comprension loop control variables as a target name
in an assignment expression is invalid."
It isn't really an exception to the special case, it is an exception to
the general rule than any old name can be used as an assignment
expression target, IIUC.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev