Message 230405 - Python tracker (original) (raw)

https://docs.python.org/2/reference/datamodel.html#object.iadd

[...] These methods should attempt to do the operation in-place (modifying self) and return the result (which could be, but does not have to be, self). If a specific method is not defined, the augmented assignment falls back to the normal methods. For instance, to execute the statement 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.


Returning NotImplemented still allows a TypeError to be raised, is subclass friendly, and is the way Python is designed.