Skip to content

Commit 05aa839

Browse files
committed
Issue #23757: Only call the concrete list API for exact lists.
1 parent 6202c17 commit 05aa839

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lib/test/seq_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ def itermulti(seqn):
8484
'Test multiple tiers of iterators'
8585
return chain(imap(lambda x:x, iterfunc(IterGen(Sequence(seqn)))))
8686

87+
class LyingTuple(tuple):
88+
def __iter__(self):
89+
yield 1
90+
91+
class LyingList(list):
92+
def __iter__(self):
93+
yield 1
94+
8795
class CommonTest(unittest.TestCase):
8896
# The type to be tested
8997
type2test = None
@@ -130,6 +138,10 @@ def __getitem__(self, i):
130138
self.assertRaises(TypeError, self.type2test, IterNoNext(s))
131139
self.assertRaises(ZeroDivisionError, self.type2test, IterGenExc(s))
132140

141+
# Issue #23757
142+
self.assertEqual(self.type2test(LyingTuple((2,))), self.type2test((1,)))
143+
self.assertEqual(self.type2test(LyingList([2])), self.type2test([1]))
144+
133145
def test_truth(self):
134146
self.assertFalse(self.type2test())
135147
self.assertTrue(self.type2test([42]))

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Core and Builtins
5151

5252
- Issue #23971: Fix underestimated presizing in dict.fromkeys().
5353

54+
- Issue #23757: PySequence_Tuple() incorrectly called the concrete list API
55+
when the data was a list subclass.
56+
5457
- Issue #20274: Remove ignored and erroneous "kwargs" parameters from three
5558
METH_VARARGS methods on _sqlite.Connection.
5659

Objects/abstract.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ PySequence_Tuple(PyObject *v)
21692169
Py_INCREF(v);
21702170
return v;
21712171
}
2172-
if (PyList_Check(v))
2172+
if (PyList_CheckExact(v))
21732173
return PyList_AsTuple(v);
21742174

21752175
/* Get iterator. */

0 commit comments

Comments
 (0)