mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
bpo-44605: Teach @total_ordering() to work with metaclasses (GH-27633) (GH-27641)
This commit is contained in:
parent
91f6d38669
commit
fde84170d0
3 changed files with 41 additions and 12 deletions
|
@ -1153,6 +1153,34 @@ class TestTotalOrdering(unittest.TestCase):
|
|||
method_copy = pickle.loads(pickle.dumps(method, proto))
|
||||
self.assertIs(method_copy, method)
|
||||
|
||||
|
||||
def test_total_ordering_for_metaclasses_issue_44605(self):
|
||||
|
||||
@functools.total_ordering
|
||||
class SortableMeta(type):
|
||||
def __new__(cls, name, bases, ns):
|
||||
return super().__new__(cls, name, bases, ns)
|
||||
|
||||
def __lt__(self, other):
|
||||
if not isinstance(other, SortableMeta):
|
||||
pass
|
||||
return self.__name__ < other.__name__
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, SortableMeta):
|
||||
pass
|
||||
return self.__name__ == other.__name__
|
||||
|
||||
class B(metaclass=SortableMeta):
|
||||
pass
|
||||
|
||||
class A(metaclass=SortableMeta):
|
||||
pass
|
||||
|
||||
self.assertTrue(A < B)
|
||||
self.assertFalse(A > B)
|
||||
|
||||
|
||||
@functools.total_ordering
|
||||
class Orderable_LT:
|
||||
def __init__(self, value):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue