=== modified file 'Lib/test/test_bisect.py' --- Lib/test/test_bisect.py 2008-07-10 14:03:19 +0000 +++ Lib/test/test_bisect.py 2008-09-26 17:00:22 +0000 @@ -196,6 +196,17 @@ 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 === modified file 'Modules/_bisectmodule.c' --- Modules/_bisectmodule.c 2008-07-24 05:38:48 +0000 +++ Modules/_bisectmodule.c 2008-09-26 17:07:15 +0000 @@ -82,16 +82,11 @@ index = internal_bisect_right(list, item, lo, hi); if (index < 0) return NULL; - if (PyList_Check(list)) { - if (PyList_Insert(list, index, item) < 0) - return NULL; - } else { - result = PyObject_CallMethod(list, "insert", "nO", - index, item); - if (result == NULL) - return NULL; - Py_DECREF(result); - } + + result = PyObject_CallMethod(list, "insert", "nO", index, item); + if (result == NULL) + return NULL; + Py_DECREF(result); Py_RETURN_NONE; } @@ -183,16 +178,11 @@ index = internal_bisect_left(list, item, lo, hi); if (index < 0) return NULL; - if (PyList_Check(list)) { - if (PyList_Insert(list, index, item) < 0) - return NULL; - } else { - result = PyObject_CallMethod(list, "insert", "iO", - index, item); - if (result == NULL) - return NULL; - Py_DECREF(result); - } + + result = PyObject_CallMethod(list, "insert", "iO", index, item); + if (result == NULL) + return NULL; + Py_DECREF(result); Py_RETURN_NONE; }