diff --git a/Misc/NEWS.d/next/Library/2026-06-23-15-02-27.gh-issue-152017.wH89hr.rst b/Misc/NEWS.d/next/Library/2026-06-23-15-02-27.gh-issue-152017.wH89hr.rst new file mode 100644 index 000000000000000..b903e39d6215054 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-23-15-02-27.gh-issue-152017.wH89hr.rst @@ -0,0 +1 @@ +:class:`collections.deque` no longer suppresses :exc:`MemoryError` in certain cases. diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index e96a546a818d3d7..c2e8741735b3f86 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -746,9 +746,10 @@ deque_clear(PyObject *self) adversary could cause it to never terminate). */ + PyObject *old_exc = PyErr_GetRaisedException(); b = newblock(deque); + PyErr_SetRaisedException(old_exc); if (b == NULL) { - PyErr_Clear(); goto alternate_method; }