From f3776a17effc7542826e1453b082ca0877722464 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 8 Oct 2008 18:47:17 +0000 Subject: #3935: properly support list subclasses in the C impl. of bisect. Patch reviewed by Raymond. --- Lib/test/test_bisect.py | 11 +++++++++++ Misc/NEWS | 2 ++ Modules/_bisectmodule.c | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_bisect.py b/Lib/test/test_bisect.py index 7776cc8..66bae48 100644 --- a/Lib/test/test_bisect.py +++ b/Lib/test/test_bisect.py @@ -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 diff --git a/Misc/NEWS b/Misc/NEWS index 50494f4..dc43554 100644 --- 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. diff --git a/Modules/_bisectmodule.c b/Modules/_bisectmodule.c index 4469dc0..fc54954 100644 --- a/Modules/_bisectmodule.c +++ b/Modules/_bisectmodule.c @@ -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 { -- cgit v0.12