I have the following class:
class MyInt:
def __init__(self, v):
if type(v) != int:
raise ValueError('value must be an int')
self.v = v
def __getattr__(self, attr):
return getattr(self.v, attr)
i = MyInt(0)
print(i + 1)
I get the error: TypeError: unsupported operand type(s) for +: 'MyInt' and 'int'
Shouldn't i.__add__(1)
be called? And shouldn't __getattr__
be called when no such method is found in the MyInt
class?