From: Victor Stinner Date: Mon, 15 Jun 2026 09:46:52 +0000 (+0200) Subject: gh-146102: Don't clear exception on success in odictobject.c (#151347) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b3b7c0025be4f9d08d5f4259b8ffc7b05fa0ba7f;p=thirdparty%2FPython%2Fcpython.git gh-146102: Don't clear exception on success in odictobject.c (#151347) Calling PyErr_Clear() on success can mask a pending exception. Replace it with an assertion checking that no exception is set. --- diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 6f05395b18d7..14c1b0240582 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -2206,13 +2206,14 @@ update __setitem__ static int mutablemapping_add_pairs(PyObject *self, PyObject *pairs) { + assert(!PyErr_Occurred()); + PyObject *pair, *iterator, *unexpected; int res = 0; iterator = PyObject_GetIter(pairs); if (iterator == NULL) return -1; - PyErr_Clear(); while ((pair = PyIter_Next(iterator)) != NULL) { /* could be more efficient (see UNPACK_SEQUENCE in ceval.c) */