Issue #665761: functools.reduce() will no longer mask exceptions other
than TypeError raised by the iterator argument. Also added a test to
check that zip() already behaves similarly.
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index bf2ea3b..3437353 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -302,8 +302,9 @@
it = PyObject_GetIter(seq);
if (it == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "reduce() arg 2 must support iteration");
+ if (PyErr_ExceptionMatches(PyExc_TypeError))
+ PyErr_SetString(PyExc_TypeError,
+ "reduce() arg 2 must support iteration");
Py_XDECREF(result);
return NULL;
}