mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
#3935: properly support list subclasses in the C impl. of bisect.
Patch reviewed by Raymond.
This commit is contained in:
parent
06a1386902
commit
f3776a17ef
3 changed files with 15 additions and 2 deletions
|
|
@ -196,6 +196,17 @@ class TestInsort(unittest.TestCase):
|
||||||
def test_backcompatibility(self):
|
def test_backcompatibility(self):
|
||||||
self.assertEqual(self.module.insort, self.module.insort_right)
|
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):
|
class TestInsortPython(TestInsort):
|
||||||
module = py_bisect
|
module = py_bisect
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #4014: Don't claim that Python has an Alpha release status, in addition
|
||||||
to claiming it is Mature.
|
to claiming it is Mature.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ insort_right(PyObject *self, PyObject *args, PyObject *kw)
|
||||||
index = internal_bisect_right(list, item, lo, hi);
|
index = internal_bisect_right(list, item, lo, hi);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyList_Check(list)) {
|
if (PyList_CheckExact(list)) {
|
||||||
if (PyList_Insert(list, index, item) < 0)
|
if (PyList_Insert(list, index, item) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -183,7 +183,7 @@ insort_left(PyObject *self, PyObject *args, PyObject *kw)
|
||||||
index = internal_bisect_left(list, item, lo, hi);
|
index = internal_bisect_left(list, item, lo, hi);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyList_Check(list)) {
|
if (PyList_CheckExact(list)) {
|
||||||
if (PyList_Insert(list, index, item) < 0)
|
if (PyList_Insert(list, index, item) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue