mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Issue #23132: Improve performance and introspection support of comparison
methods created by functool.total_ordering.
This commit is contained in:
parent
a2d86228d5
commit
697a526fa1
3 changed files with 69 additions and 39 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue