https://github.com/python/cpython/commit/2b1b7ca953efa4d4cdb61615e419cbff402fb1b5 commit: 2b1b7ca953efa4d4cdb61615e419cbff402fb1b5 branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: JelleZijlstra <[email protected]> date: 2026-10-21T19:56:36Z summary:
[3.14] gh-131151: Add tests for exceptions raised by descriptors of comparison methods. (GH-159258) (#160090) (cherry picked from commit c1e20aaa00a924dc8ee12395df6ae2bb642f7372) Co-authored-by: Vasiliy Kiryanov <[email protected]> files: M Lib/test/test_descr.py diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 00e5386b1d56b9..ef1090d0dea4b2 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -2149,10 +2149,22 @@ def some_number(self_, key): def swallow(*args): pass def format_impl(self, spec): return "hello" - - # It would be nice to have every special method tested here, but I'm - # only listing the ones I can remember outside of typeobject.c, since it - # does it right. + def do_eq(obj): + return obj == 1 + def do_ne(obj): + return obj != 1 + def do_lt(obj): + return obj < 1 + def do_le(obj): + return obj <= 1 + def do_gt(obj): + return obj > 1 + def do_ge(obj): + return obj >= 1 + + # It would be nice to have every special method tested here. + # gh-131151: the rich comparison operators used to clear any exception + # raised by a descriptor's __get__. specials = [ ("__bytes__", bytes, hello, set(), {}), ("__reversed__", reversed, empty_seq, set(), {}), @@ -2173,6 +2185,12 @@ def format_impl(self, spec): ("__ceil__", math.ceil, zero, set(), {}), ("__dir__", dir, empty_seq, set(), {}), ("__round__", round, zero, set(), {}), + ("__eq__", do_eq, return_true, set(), {}), + ("__ne__", do_ne, return_true, set(), {}), + ("__lt__", do_lt, return_true, set(), {}), + ("__le__", do_le, return_true, set(), {}), + ("__gt__", do_gt, return_true, set(), {}), + ("__ge__", do_ge, return_true, set(), {}), ] class Checker(object): _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
