py/obj: Add support for __float__ and __complex__ functions.
This commit is contained in:
committed by
Damien George
parent
fa15aed0f7
commit
1e87b56219
40
tests/float/complex_dunder.py
Normal file
40
tests/float/complex_dunder.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# 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")
|
||||
Reference in New Issue
Block a user