@@ -263,6 +263,34 @@ def test_insort_keynotNone(self):
263263 for f in (self .module .insort_left , self .module .insort_right ):
264264 self .assertRaises (TypeError , f , x , y , key = "b" )
265265
266+ def test_lt_returns_non_bool (self ):
267+ class A :
268+ def __init__ (self , val ):
269+ self .val = val
270+ def __lt__ (self , other ):
271+ return "nonempty" if self .val < other .val else ""
272+
273+ data = [A (i ) for i in range (100 )]
274+ i1 = self .module .bisect_left (data , A (33 ))
275+ i2 = self .module .bisect_right (data , A (33 ))
276+ self .assertEqual (i1 , 33 )
277+ self .assertEqual (i2 , 34 )
278+
279+ def test_lt_returns_notimplemented (self ):
280+ class A :
281+ def __init__ (self , val ):
282+ self .val = val
283+ def __lt__ (self , other ):
284+ return NotImplemented
285+ def __gt__ (self , other ):
286+ return self .val > other .val
287+
288+ data = [A (i ) for i in range (100 )]
289+ i1 = self .module .bisect_left (data , A (40 ))
290+ i2 = self .module .bisect_right (data , A (40 ))
291+ self .assertEqual (i1 , 40 )
292+ self .assertEqual (i2 , 41 )
293+
266294class TestBisectPython (TestBisect , unittest .TestCase ):
267295 module = py_bisect
268296
0 commit comments