[Python-ideas] On evaluating features [was: Unpacking iterables for augmented assignment]
Chris Angelico
rosuav at gmail.com
Thu Sep 6 14:23:02 EDT 2018
More information about the Python-ideas mailing list
Thu Sep 6 14:23:02 EDT 2018
- Previous message (by thread): [Python-ideas] On evaluating features [was: Unpacking iterables for augmented assignment]
- Next message (by thread): [Python-ideas] On evaluating features [was: Unpacking iterables for augmented assignment]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Sep 7, 2018 at 4:11 AM, Franklin? Lee <leewangzhong+python at gmail.com> wrote: > 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. 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
- Previous message (by thread): [Python-ideas] On evaluating features [was: Unpacking iterables for augmented assignment]
- Next message (by thread): [Python-ideas] On evaluating features [was: Unpacking iterables for augmented assignment]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list