[EMAIL PROTECTED] wrote: > On Oct 10, 8:23 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: <snip> >> rebinds a. Period. Which is the _essential_ thing in my post, because >> this rebinding semantics are what confused the OP. > > Doesn't this depend on wether "a" supports __iadd__ or not? Section > 3.4.7 of the docs say > > """ > If a specific method is not defined, the augmented operation falls > back to the normal methods. For instance, to evaluate the expression x > +=y, where x is an instance of a class that has an __iadd__() method, > x.__iadd__(y) is called. If x is an instance of a class that does not > define a __iadd__() method, x.__add__(y) and y.__radd__(x) are > considered, as with the evaluation of x+y. > """ > > So if a.__iadd__ exists, a += b is executed as a.__iadd__(b), in which > case there's no reason to rebind a. > You misunderstand the documentation, what you quoted doesn't say that the assignment is suppressed. If a.__iadd__ exists, a += b is executed as a = a.__iadd__(b)
The options for a+=b are: a = a.__iadd__(b) a = a.__add__(b) a = b.__radd__(a) but the assignment always happens, it is only what gets executed for the right hand side which varies. -- http://mail.python.org/mailman/listinfo/python-list