summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_functools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-01-08 07:01:56 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-01-08 07:01:56 (GMT)
commit23f9fc344827c02cf2450f7e0903681e69db201a (patch)
treec0454c2980f0a3f768597b5e4f54896ad8970ca3 /Lib/test/test_functools.py
parent06ec45e2f8108d6bfc1fa8abe80de94bc4eeb8a3 (diff)
downloadcpython-23f9fc344827c02cf2450f7e0903681e69db201a.zip
cpython-23f9fc344827c02cf2450f7e0903681e69db201a.tar.gz
cpython-23f9fc344827c02cf2450f7e0903681e69db201a.tar.bz2
Issue #10042: Fixed the total_ordering decorator to handle cross-type
comparisons that could lead to infinite recursion.
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r--Lib/test/test_functools.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index f41a144..73a77d6 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -457,6 +457,8 @@ class TestTotalOrdering(unittest.TestCase):
self.value = value
def __lt__(self, other):
return self.value < other.value
+ def __eq__(self, other):
+ return self.value == other.value
self.assertTrue(A(1) < A(2))
self.assertTrue(A(2) > A(1))
self.assertTrue(A(1) <= A(2))
@@ -471,6 +473,8 @@ class TestTotalOrdering(unittest.TestCase):
self.value = value
def __le__(self, other):
return self.value <= other.value
+ def __eq__(self, other):
+ return self.value == other.value
self.assertTrue(A(1) < A(2))
self.assertTrue(A(2) > A(1))
self.assertTrue(A(1) <= A(2))
@@ -485,6 +489,8 @@ class TestTotalOrdering(unittest.TestCase):
self.value = value
def __gt__(self, other):
return self.value > other.value
+ def __eq__(self, other):
+ return self.value == other.value
self.assertTrue(A(1) < A(2))
self.assertTrue(A(2) > A(1))
self.assertTrue(A(1) <= A(2))
@@ -499,6 +505,8 @@ class TestTotalOrdering(unittest.TestCase):
self.value = value
def __ge__(self, other):
return self.value >= other.value
+ def __eq__(self, other):
+ return self.value == other.value
self.assertTrue(A(1) < A(2))
self.assertTrue(A(2) > A(1))
self.assertTrue(A(1) <= A(2))
@@ -524,6 +532,22 @@ class TestTotalOrdering(unittest.TestCase):
class A:
pass
+ def test_bug_10042(self):
+ @functools.total_ordering
+ class TestTO:
+ def __init__(self, value):
+ self.value = value
+ def __eq__(self, other):
+ if isinstance(other, TestTO):
+ return self.value == other.value
+ return False
+ def __lt__(self, other):
+ if isinstance(other, TestTO):
+ return self.value < other.value
+ raise TypeError
+ with self.assertRaises(TypeError):
+ TestTO(8) <= ()
+
class TestLRU(unittest.TestCase):
def test_lru(self):