Issue #23132: Improve performance and introspection support of comparison

methods created by functool.total_ordering.
This commit is contained in:
Serhiy Storchaka 2015-01-01 15:23:12 +02:00
parent a2d86228d5
commit 697a526fa1
3 changed files with 69 additions and 39 deletions

View file

@ -880,6 +880,24 @@ class TestTotalOrdering(unittest.TestCase):
with self.assertRaises(TypeError):
a <= b
def test_pickle(self):
for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):
for name in '__lt__', '__gt__', '__le__', '__ge__':
with self.subTest(method=name, proto=proto):
method = getattr(Orderable_LT, name)
method_copy = pickle.loads(pickle.dumps(method, proto))
self.assertIs(method_copy, method)
@functools.total_ordering
class Orderable_LT:
def __init__(self, value):
self.value = value
def __lt__(self, other):
return self.value < other.value
def __eq__(self, other):
return self.value == other.value
class TestLRU(unittest.TestCase):
def test_lru(self):