circuitpython/tests/float/complex_special_mehods.py
Damien George 9f911d822e py/objcomplex: Add mp_obj_get_complex_maybe for use in complex bin-op.
This allows complex binary operations to fail gracefully with unsupported
operation rather than raising an exception, so that special methods work
correctly.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-27 01:03:10 +10:00

16 lines
232 B
Python

# test complex interacting with special methods
class A:
def __add__(self, x):
print("__add__")
return 1
def __radd__(self, x):
print("__radd__")
return 2
print(A() + 1j)
print(1j + A())