diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-08-06 19:57:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-06 19:57:52 (GMT) |
commit | fde84170d06f74afd6f95d5b18cf3f733018191a (patch) | |
tree | 98ded8fdba68a38ded8f85c6db8c2e71d1aedef1 /Lib/test/test_functools.py | |
parent | 91f6d386691c060dfaa870d74b370e9c10eb8cd8 (diff) | |
download | cpython-fde84170d06f74afd6f95d5b18cf3f733018191a.zip cpython-fde84170d06f74afd6f95d5b18cf3f733018191a.tar.gz cpython-fde84170d06f74afd6f95d5b18cf3f733018191a.tar.bz2 |
bpo-44605: Teach @total_ordering() to work with metaclasses (GH-27633) (GH-27641)
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r-- | Lib/test/test_functools.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 11e8aa3..ffe2456 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -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): |