]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-146102: Don't clear exception on success in odictobject.c (#151347)
authorVictor Stinner <vstinner@python.org>
Mon, 15 Jun 2026 09:46:52 +0000 (11:46 +0200)
committerGitHub <noreply@github.com>
Mon, 15 Jun 2026 09:46:52 +0000 (11:46 +0200)
Calling PyErr_Clear() on success can mask a pending exception.
Replace it with an assertion checking that no exception is set.

Objects/odictobject.c

index 6f05395b18d781f79e3ced9a0ba85aacc1b52889..14c1b02405822cde7cf8f19daeb7feb293ceb0aa 100644 (file)
@@ -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) */