2022-07-04 17:35:46 +10:00
|
|
|
# test __complex__ function support
|
|
|
|
|
|
|
|
|
2022-07-25 15:23:48 +10:00
|
|
|
class TestFloat:
|
|
|
|
def __float__(self):
|
|
|
|
return 1.0
|
|
|
|
|
|
|
|
|
2022-07-04 17:35:46 +10:00
|
|
|
class TestComplex:
|
|
|
|
def __complex__(self):
|
|
|
|
return 1j + 10
|
|
|
|
|
|
|
|
|
|
|
|
class TestStrComplex:
|
|
|
|
def __complex__(self):
|
|
|
|
return "a"
|
|
|
|
|
|
|
|
|
|
|
|
class TestNonComplex:
|
|
|
|
def __complex__(self):
|
|
|
|
return 6
|
|
|
|
|
|
|
|
|
|
|
|
class Test:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-07-25 15:23:48 +10:00
|
|
|
print(complex(TestFloat()))
|
2022-07-04 17:35:46 +10:00
|
|
|
print(complex(TestComplex()))
|
|
|
|
|
|
|
|
try:
|
|
|
|
print(complex(TestStrComplex()))
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
print(complex(TestNonComplex()))
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
print(complex(Test()))
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|