I would like to subclass an immutable type or implement one of my own which behaves like an int does as shown in the following console session:
int
Simply don't implement __iadd__, but only __add__:
__iadd__
__add__
>>> class X(object): ... def __add__(self, o): ... return "added" >>> x = X() >>> x += 2 >>> x 'added'
If there's no x.__iadd__, Python simply calculates x += y as x = x + y doc.
x.__iadd__
x += y
x = x + y