如果我有两个对象Aand B,我可以返回NotImplementedforA的__iadd__方法并使用它的方法进行B修改。A__radd__
>>> class A():
... def __init__(self, val):
... self.val = val
... def __iadd__(self, other):
... return NotImplemented
... def __ipow__(self, other):
... return NotImplemented
...
>>> class B():
... def __init__(self, val):
... self.val = val
... def __radd__(self, other):
... return A(other.val + self.val)
... def __rpow__(self, other):
... return A(other.val ** self.val)
...
>>> a = A(2)
>>> b = B(2)
>>> …Run Code Online (Sandbox Code Playgroud)