]> granicus.if.org Git - python/commitdiff
#3935: properly support list subclasses in the C impl. of bisect.
authorGeorg Brandl <georg@python.org>
Wed, 8 Oct 2008 18:47:17 +0000 (18:47 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 8 Oct 2008 18:47:17 +0000 (18:47 +0000)
Patch reviewed by Raymond.

Lib/test/test_bisect.py
Misc/NEWS
Modules/_bisectmodule.c

index 7776cc89177e6559e72e10b164f9fcb6472d1cce..66bae48536f4d19493794114d66998a46cfe9cd6 100644 (file)
@@ -196,6 +196,17 @@ class TestInsort(unittest.TestCase):
     def test_backcompatibility(self):
         self.assertEqual(self.module.insort, self.module.insort_right)
 
+    def test_listDerived(self):
+        class List(list):
+            data = []
+            def insert(self, index, item):
+                self.data.insert(index, item)
+
+        lst = List()
+        self.module.insort_left(lst, 10)
+        self.module.insort_right(lst, 5)
+        self.assertEqual([5, 10], lst.data)
+
 class TestInsortPython(TestInsort):
     module = py_bisect
 
index 50494f4f78e3d590705ff455082834550e21a655..dc435542d42ac20e71805fd237738242b3e6a998 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -20,6 +20,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #3935: Properly support list subclasses in bisect's C implementation.
+
 - Issue #4014: Don't claim that Python has an Alpha release status, in addition
   to claiming it is Mature.
 
index 4469dc0832f233ee0c13028cb8f7e2a1a80ce252..fc54954dabb98ea6e503609a8845df376066aa58 100644 (file)
@@ -82,7 +82,7 @@ insort_right(PyObject *self, PyObject *args, PyObject *kw)
        index = internal_bisect_right(list, item, lo, hi);
        if (index < 0)
                return NULL;
-       if (PyList_Check(list)) {
+       if (PyList_CheckExact(list)) {
                if (PyList_Insert(list, index, item) < 0)
                        return NULL;
        } else {
@@ -183,7 +183,7 @@ insort_left(PyObject *self, PyObject *args, PyObject *kw)
        index = internal_bisect_left(list, item, lo, hi);
        if (index < 0)
                return NULL;
-       if (PyList_Check(list)) {
+       if (PyList_CheckExact(list)) {
                if (PyList_Insert(list, index, item) < 0)
                        return NULL;
        } else {