summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-06-06 15:45:38 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-06-06 15:45:38 (GMT)
commit478d47a168bf45da9014ac1a299a222726eda058 (patch)
treeb83b214c1c16891fac46710ee6ac619da3a08256 /Lib
parent56f46f8d8c1af1cf150df61f5aeafa40ca0b18e5 (diff)
downloadcpython-478d47a168bf45da9014ac1a299a222726eda058.zip
cpython-478d47a168bf45da9014ac1a299a222726eda058.tar.gz
cpython-478d47a168bf45da9014ac1a299a222726eda058.tar.bz2
Close SF bug 563740. complex() now finds __complex__() in new style classes.
Made conversion failure error messages consistent between types. Added related unittests.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_b1.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py
index 56a5f78..afa0cf3 100644
--- a/Lib/test/test_b1.py
+++ b/Lib/test/test_b1.py
@@ -101,6 +101,17 @@ print 'compile'
compile('print 1\n', '', 'exec')
print 'complex'
+class OS:
+ def __complex__(self): return 1+10j
+class NS(object):
+ def __complex__(self): return 1+10j
+if complex(OS()) != 1+10j: raise TestFailed, '__complex__ in old style class'
+if complex(NS()) != 1+10j: raise TestFailed, '__complex__ in new style class'
+if complex("1+10j") != 1+10j: raise TestFailed, 'complex("1+10j")'
+if complex(10) != 10+0j: raise TestFailed, 'complex(10)'
+if complex(10.0) != 10+0j: raise TestFailed, 'complex(10.0)'
+if complex(10L) != 10+0j: raise TestFailed, 'complex(10L)'
+if complex(10+0j) != 10+0j: raise TestFailed, 'complex(10+0j)'
if complex(1,10) != 1+10j: raise TestFailed, 'complex(1,10)'
if complex(1,10L) != 1+10j: raise TestFailed, 'complex(1,10L)'
if complex(1,10.0) != 1+10j: raise TestFailed, 'complex(1,10.0)'