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

index 9834af118a5c99201ceecd30a0f1096f07f373ff..24162494dd6123001081c01b2aa5572a022896ef 100644 (file)
@@ -85,6 +85,14 @@ def itermulti(seqn):
     'Test multiple tiers of iterators'
     return chain(map(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
@@ -131,6 +139,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 e9b1461944b1b2e0e9118cfc56ecd95350e04b57..2599b821d31502c9817f4a7d1cf02a6389458a18 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
 - Issue #20274: Remove ignored and erroneous "kwargs" parameters from three
   METH_VARARGS methods on _sqlite.Connection.
 
+- Issue #23757:  PySequence_Tuple() incorrectly called the concrete list API
+  when the data was a list subclass.
+
 - Issue #24096: Make warnings.warn_explicit more robust against mutation of the
   warnings.filters list.
 
index 7e3121a932c765d5e389992c7c65fcc4317e9068..cabbaf5ba1c224daa5a20204b96f82601475153e 100644 (file)
@@ -1636,7 +1636,7 @@ PySequence_Tuple(PyObject *v)
         Py_INCREF(v);
         return v;
     }
-    if (PyList_Check(v))
+    if (PyList_CheckExact(v))
         return PyList_AsTuple(v);
 
     /* Get iterator. */