Skip to content

Commit 3b6422d

Browse files
author
georg.brandl
committed
#3935: properly support list subclasses in the C impl. of bisect.
Patch reviewed by Raymond. git-svn-id: http://svn.python.org/projects/python/trunk@66856 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent abc414e commit 3b6422d

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Lib/test/test_bisect.py

+11
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ def test_vsBuiltinSort(self, n=500):
196196
def test_backcompatibility(self):
197197
self.assertEqual(self.module.insort, self.module.insort_right)
198198

199+
def test_listDerived(self):
200+
class List(list):
201+
data = []
202+
def insert(self, index, item):
203+
self.data.insert(index, item)
204+
205+
lst = List()
206+
self.module.insort_left(lst, 10)
207+
self.module.insort_right(lst, 5)
208+
self.assertEqual([5, 10], lst.data)
209+
199210
class TestInsortPython(TestInsort):
200211
module = py_bisect
201212

Misc/NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Core and Builtins
2020
Library
2121
-------
2222

23+
- Issue #3935: Properly support list subclasses in bisect's C implementation.
24+
2325
- Issue #4014: Don't claim that Python has an Alpha release status, in addition
2426
to claiming it is Mature.
2527

Modules/_bisectmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ insort_right(PyObject *self, PyObject *args, PyObject *kw)
8282
index = internal_bisect_right(list, item, lo, hi);
8383
if (index < 0)
8484
return NULL;
85-
if (PyList_Check(list)) {
85+
if (PyList_CheckExact(list)) {
8686
if (PyList_Insert(list, index, item) < 0)
8787
return NULL;
8888
} else {
@@ -183,7 +183,7 @@ insort_left(PyObject *self, PyObject *args, PyObject *kw)
183183
index = internal_bisect_left(list, item, lo, hi);
184184
if (index < 0)
185185
return NULL;
186-
if (PyList_Check(list)) {
186+
if (PyList_CheckExact(list)) {
187187
if (PyList_Insert(list, index, item) < 0)
188188
return NULL;
189189
} else {

0 commit comments

Comments
 (0)