kuroko/test/testReflectedBinaryOperators.krk

52 lines
1.2 KiB
Python
Raw Permalink Normal View History

class RAdder:
def __radd__(self, o):
print("__radd__ called",o)
return f'{o} + RAdder()'
def __rmul__(self, o):
print("__rmul__ called", o)
return f'{o} * RAdder()'
2021-04-02 09:33:33 +03:00
def __rtruediv__(self, o):
print("__rtruediv__ called", o)
return f'{o} / RAdder()'
def __rpow__(self, o):
print("__rpow__ called", o)
return f'{o} ** RAdder()'
def __rrshift__(self, o):
print("__rrshift__ called", o)
return f'{o} >> RAdder()'
def __rlshift__(self, o):
print("__rlshift__ called", o)
return f'{o} << RAdder()'
def __ror__(self, o):
print("__ror__ called", o)
return f'{o} | RAdder()'
def __rand__(self, o):
print("__rand__ called", o)
return f'{o} & RAdder()'
def __rxor__(self, o):
print("__rxor__ called", o)
return f'{o} ^ RAdder()'
def __rmod__(self, o):
print("__rmod__ called", o)
return f'{o} % RAdder()'
print(42 + RAdder())
print(42 * RAdder())
2021-04-02 09:33:33 +03:00
print(42 / RAdder())
print(42 ** RAdder())
print(42 >> RAdder())
print(42 << RAdder())
print(42 | RAdder())
print(42 & RAdder())
print(42 ^ RAdder())
print(42 % RAdder())