[Python-ideas] On evaluating features [was: Unpacking iterables for augmented assignment]
Franklin? Lee
leewangzhong+python at gmail.com
Thu Sep 6 14:11:02 EDT 2018
On Tue, Aug 28, 2018 at 6:37 PM Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>
> Guido van Rossum wrote:
> > we might propose (as the OP did) that this:
> >
> > a, b, c += x, y, z
> >
> > could be made equivalent to this:
> >
> > a += x
> > b += y
> > c += z
>
> But not without violating the principle that
>
> lhs += rhs
>
> is equivalent to
>
> lhs = lhs.__iadd__(lhs)
(Corrected: lhs = lhs.__iadd__(rhs))
Since lhs here is neither a list nor a tuple, how is it violated? Or
rather, how is it any more of a special case than in this syntax:
# Neither name-binding or setitem/setattr.
[a,b,c] = items
If lhs is a Numpy array, then:
a_b_c += x, y, z
is equivalent to:
a_b_c = a_b_c.__iadd__((x,y,z))
We can translate the original example:
a, b, c += x, y, z
to:
a, b, c = target_list(a,b,c).__iadd__((x,y,z))
where `target_list` is a virtual (not as in "virtual function") type
for target list constructs.
More information about the Python-ideas
mailing list