https://github.com/python/cpython/commit/1fc84932c246fd69b6634531dea2c7ef20f81243 commit: 1fc84932c246fd69b6634531dea2c7ef20f81243 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: JelleZijlstra <[email protected]> date: 2026-10-21T20:19:53Z summary:
[3.15] gh-131151: Add tests for exceptions raised by descriptors of comparison methods. (GH-159258) (#160089) (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 7ac22455541fe2..8c2a7db15f4bec 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -2231,10 +2231,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(), {}), @@ -2255,6 +2267,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]
