substituting __iadd__ doesn't work as expected for += operator
问题 I have an object from a library (numpy.ndarray), in which I've substituted the __iadd__ method for a custom one. If I call object.__iadd__(x), it works as expected. However, object+=x seems to call the old (unsubstituted) method. I wanted to prevent overflows on numpy from occurring on specific cases, so I created a context manager for that. Here's the (still very crude) code: class NumpyOverflowPreventer( object ): inverse_operator= { '__iadd__':'__sub__', '__isub__':'__add__', '__imul__': '