summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>2022-09-06 23:37:18 (GMT)
committerGitHub <noreply@github.com>2022-09-06 23:37:18 (GMT)
commit56d9cf7fc87d2cd7b8231c44f1d710ee77fbb998 (patch)
tree79ce26868bf398fce2904e160111411838ebde8e /Lib
parent147eb723b2521e7cf889f6b24ca49adbefa0bf65 (diff)
downloadcpython-56d9cf7fc87d2cd7b8231c44f1d710ee77fbb998.zip
cpython-56d9cf7fc87d2cd7b8231c44f1d710ee77fbb998.tar.gz
cpython-56d9cf7fc87d2cd7b8231c44f1d710ee77fbb998.tar.bz2
gh-96538: Fix refleak in _bisectmodule.c (gh-96619)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_bisect.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_bisect.py b/Lib/test/test_bisect.py
index ba10822..97204d4 100644
--- a/Lib/test/test_bisect.py
+++ b/Lib/test/test_bisect.py
@@ -263,6 +263,34 @@ class TestBisect:
for f in (self.module.insort_left, self.module.insort_right):
self.assertRaises(TypeError, f, x, y, key = "b")
+ def test_lt_returns_non_bool(self):
+ class A:
+ def __init__(self, val):
+ self.val = val
+ def __lt__(self, other):
+ return "nonempty" if self.val < other.val else ""
+
+ data = [A(i) for i in range(100)]
+ i1 = self.module.bisect_left(data, A(33))
+ i2 = self.module.bisect_right(data, A(33))
+ self.assertEqual(i1, 33)
+ self.assertEqual(i2, 34)
+
+ def test_lt_returns_notimplemented(self):
+ class A:
+ def __init__(self, val):
+ self.val = val
+ def __lt__(self, other):
+ return NotImplemented
+ def __gt__(self, other):
+ return self.val > other.val
+
+ data = [A(i) for i in range(100)]
+ i1 = self.module.bisect_left(data, A(40))
+ i2 = self.module.bisect_right(data, A(40))
+ self.assertEqual(i1, 40)
+ self.assertEqual(i2, 41)
+
class TestBisectPython(TestBisect, unittest.TestCase):
module = py_bisect