diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 2cca6b3550b..0d1a15b10ce 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -940,12 +940,9 @@ cycle_next(cycleobject *lz) } return item; } - if (PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_StopIteration)) - PyErr_Clear(); - else + /* Note: StopIteration is already cleared by PyIter_Next() */ + if (PyErr_Occurred()) return NULL; - } if (PyList_Size(lz->saved) == 0) return NULL; it = PyObject_GetIter(lz->saved);