circuitpython/tests/basics/class_reverse_op.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

22 lines
370 B
Python
Raw Normal View History

2017-11-16 13:33:48 -05:00
import skip_if
skip_if.no_reverse_ops()
class A:
def __init__(self, v):
self.v = v
def __add__(self, o):
if isinstance(o, A):
return A(self.v + o.v)
return A(self.v + o)
def __radd__(self, o):
return A(self.v + o)
def __repr__(self):
return "A({})".format(self.v)
print(A(3) + 1)
print(2 + A(5))