I was experimenting around with dunders in python when I found something: Say I created a class:
class MyInt:
def __init__(self, val):
self.val = val
def __add__(self, other):
return self.val + other
a = MyInt(3)
The __add__ works perfectly fine when this is run:
>>> print(a + 4)
7
However, when I ran this:
>>> print(4 + a)
TypeError: unsupported operand type(s) for +: 'int' and 'MyInt'
I know that the int class does not support adding with MyInt, but are there any workarounds for this?