summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-05-30 12:12:25 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-05-30 12:12:25 (GMT)
commit813363743d4f46062b1d5149d62252c0e2794289 (patch)
treee560c6e9c8b3b73381f0ae162cd096efa324dd10 /Lib
parentddac33882b7c51c4b0770fd39adaee33dfcd9a1c (diff)
downloadcpython-813363743d4f46062b1d5149d62252c0e2794289.zip
cpython-813363743d4f46062b1d5149d62252c0e2794289.tar.gz
cpython-813363743d4f46062b1d5149d62252c0e2794289.tar.bz2
Issue #5211: Complete removal of implicit coercions for the complex
type. Coercion for arithmetic operations was already removed in r78280, but that commit didn't remove coercion for rich comparisons.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_complex.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index fc47b23..f27593e 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -115,6 +115,19 @@ class ComplexTest(unittest.TestCase):
def test_coerce(self):
self.assertRaises(OverflowError, complex.__coerce__, 1+1j, 1L<<10000)
+ def test_no_implicit_coerce(self):
+ # Python 2.7 removed implicit coercion from the complex type
+ class A(object):
+ def __coerce__(self, other):
+ raise RuntimeError
+ __hash__ = None
+ def __cmp__(self, other):
+ return -1
+
+ a = A()
+ self.assertRaises(TypeError, lambda: a + 2.0j)
+ self.assertTrue(a < 2.0j)
+
def test_richcompare(self):
self.assertRaises(OverflowError, complex.__eq__, 1+1j, 1L<<10000)
self.assertEqual(complex.__lt__(1+1j, None), NotImplemented)