41 lines
544 B
Python
41 lines
544 B
Python
|
# test __complex__ function support
|
||
|
|
||
|
|
||
|
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
|
||
|
|
||
|
|
||
|
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")
|