]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #23757: Only call the concrete list API for exact lists.
authorRaymond Hettinger <python@rcn.com>
Sun, 17 May 2015 21:37:39 +0000 (14:37 -0700)
committerRaymond Hettinger <python@rcn.com>
Sun, 17 May 2015 21:37:39 +0000 (14:37 -0700)
Lib/test/seq_tests.py
Misc/NEWS
Objects/abstract.c

index f5e4e0ef552d21a5eed5b361ac7e8befc1d919b1..f4673d48af3206c945a41e7cbc461897313a3209 100644 (file)
@@ -84,6 +84,14 @@ def itermulti(seqn):
     'Test multiple tiers of iterators'
     return chain(imap(lambda x:x, iterfunc(IterGen(Sequence(seqn)))))
 
+class LyingTuple(tuple):
+    def __iter__(self):
+        yield 1
+
+class LyingList(list):
+    def __iter__(self):
+        yield 1
+
 class CommonTest(unittest.TestCase):
     # The type to be tested
     type2test = None
@@ -130,6 +138,10 @@ class CommonTest(unittest.TestCase):
             self.assertRaises(TypeError, self.type2test, IterNoNext(s))
             self.assertRaises(ZeroDivisionError, self.type2test, IterGenExc(s))
 
+        # Issue #23757
+        self.assertEqual(self.type2test(LyingTuple((2,))), self.type2test((1,)))
+        self.assertEqual(self.type2test(LyingList([2])), self.type2test([1]))
+
     def test_truth(self):
         self.assertFalse(self.type2test())
         self.assertTrue(self.type2test([42]))
index ab36ec45a954d40ac81ccf7ae1108a5f752c82f9..c9b0dbefcd37aaf2bfb17c5facc442ca125954b5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -51,6 +51,9 @@ Core and Builtins
 
 - Issue #23971:  Fix underestimated presizing in dict.fromkeys().
 
+- Issue #23757:  PySequence_Tuple() incorrectly called the concrete list API
+  when the data was a list subclass.
+
 - Issue #20274: Remove ignored and erroneous "kwargs" parameters from three
   METH_VARARGS methods on _sqlite.Connection.
 
index 64a1a381e11cfa68823ab546a5f68bf163378ad1..6e289eff6edab9816ec752bc4bb368f762a5e848 100644 (file)
@@ -2169,7 +2169,7 @@ PySequence_Tuple(PyObject *v)
         Py_INCREF(v);
         return v;
     }
-    if (PyList_Check(v))
+    if (PyList_CheckExact(v))
         return PyList_AsTuple(v);
 
     /* Get iterator. */