https://github.com/python/cpython/commit/41171301529878c377193433a410616471aa9b6f commit: 41171301529878c377193433a410616471aa9b6f branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: JelleZijlstra <[email protected]> date: 2026-10-20T11:18:12-07:00 summary:
[3.15] gh-159739: Preserve the full maxlen when copying deque subclasses (GH-159765) (#159896) (cherry picked from commit e3c395542adebfbca1f54379065c15380ac5e182) Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> files: A Misc/NEWS.d/next/Library/2026-10-19-20-38-17.gh-issue-159739.ff088c.rst M Lib/test/test_deque.py M Modules/_collectionsmodule.c diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index 3c45032cda9138..0102f203340bd9 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -810,6 +810,12 @@ def __iter__(self): class TestSubclass(unittest.TestCase): + def test_copy_maxlen(self): + original = Deque('abc', maxlen=support.MAX_Py_ssize_t) + copied = original.copy() + self.assertEqual(copied, original) + self.assertEqual(copied.maxlen, original.maxlen) + def test_basics(self): d = Deque(range(25)) d.__init__(range(200)) diff --git a/Misc/NEWS.d/next/Library/2026-10-19-20-38-17.gh-issue-159739.ff088c.rst b/Misc/NEWS.d/next/Library/2026-10-19-20-38-17.gh-issue-159739.ff088c.rst new file mode 100644 index 00000000000000..af8b06fecbfc3f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-19-20-38-17.gh-issue-159739.ff088c.rst @@ -0,0 +1 @@ +Fix copying :class:`collections.deque` subclasses with a large maximum length. diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index b0701df26bbd24..ba9a98e1333880 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -648,7 +648,7 @@ deque_copy_impl(dequeobject *deque) result = PyObject_CallOneArg((PyObject *)(Py_TYPE(deque)), (PyObject *)deque); else - result = PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi", + result = PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "On", deque, old_deque->maxlen, NULL); if (result != NULL && !PyObject_TypeCheck(result, state->deque_type)) { PyErr_Format(PyExc_TypeError, _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
