[Python-checkins] r66856 - in python/trunk: Lib/test/test_bisect.py Misc/NEWS Modules/_bisectmodule.c

georg.brandl python-checkins at python.org
Wed Oct 8 20:47:18 CEST 2008


Author: georg.brandl
Date: Wed Oct  8 20:47:17 2008
New Revision: 66856

Log:
#3935: properly support list subclasses in the C impl. of bisect.
Patch reviewed by Raymond.


Modified:
   python/trunk/Lib/test/test_bisect.py
   python/trunk/Misc/NEWS
   python/trunk/Modules/_bisectmodule.c

Modified: python/trunk/Lib/test/test_bisect.py
==============================================================================
--- python/trunk/Lib/test/test_bisect.py	(original)
+++ python/trunk/Lib/test/test_bisect.py	Wed Oct  8 20:47:17 2008
@@ -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: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Oct  8 20:47:17 2008
@@ -20,6 +20,8 @@
 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.
 

Modified: python/trunk/Modules/_bisectmodule.c
==============================================================================
--- python/trunk/Modules/_bisectmodule.c	(original)
+++ python/trunk/Modules/_bisectmodule.c	Wed Oct  8 20:47:17 2008
@@ -82,7 +82,7 @@
 	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 @@
 	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 {


More information about the Python-checkins mailing list