On Fri, Sep 7, 2018 at 4:11 AM, Franklin? Lee
<leewangzhong+pyt...@gmail.com> wrote:
> On Tue, Aug 28, 2018 at 6:37 PM Greg Ewing <greg.ew...@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.

What is the virtual type here, and what does its __iadd__ method do? I
don't understand you here. Can you go into detail? Suppose I'm the
author of the class that all six of these objects are instances of;
can I customize the effect of __iadd__ here in some way, and if so,
how?

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to