https://github.com/python/cpython/commit/c1e20aaa00a924dc8ee12395df6ae2bb642f7372
commit: c1e20aaa00a924dc8ee12395df6ae2bb642f7372
branch: main
author: Vasiliy Kiryanov <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-10-21T11:39:29-07:00
summary:
gh-131151: Add tests for exceptions raised by descriptors of comparison
methods. (#159258)
files:
M Lib/test/test_descr.py
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index a6ebda5bf4e5df..93b902a632de35 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]