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 0626cc6a70bc8f7..3e20a79044216a0 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -744,9 +744,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; }