diff Modules/itertoolsmodule.c @ 32011:50708b8f0d28 2.3

SF #950057: itertools.chain doesn't "process" exceptions as they occur Both cycle() and chain() were handling exceptions only when switching input sources. The patch makes the handle more immediate.
author Raymond Hettinger <python@rcn.com>
date Sat, 08 May 2004 19:52:39 +0000
parents 97f3d66558fb
children
line wrap: on
line diff
--- a/Modules/itertoolsmodule.c	Fri May 07 19:13:47 2004 +0000
+++ b/Modules/itertoolsmodule.c	Sat May 08 19:52:39 2004 +0000
@@ -94,6 +94,12 @@
 				PyList_Append(lz->saved, item);
 			return item;
 		}
+		if (PyErr_Occurred()) {
+			if (PyErr_ExceptionMatches(PyExc_StopIteration))
+				PyErr_Clear();
+			else
+				return NULL;
+		}
 		if (PyList_Size(lz->saved) == 0) 
 			return NULL;
 		it = PyObject_GetIter(lz->saved);
@@ -1049,6 +1055,12 @@
 		item = PyIter_Next(it);
 		if (item != NULL)
 			return item;
+		if (PyErr_Occurred()) {
+			if (PyErr_ExceptionMatches(PyExc_StopIteration))
+				PyErr_Clear();
+			else
+				return NULL;
+		}
 		lz->iternum++;
 	}
 	return NULL;