summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-05-08 19:49:42 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-05-08 19:49:42 (GMT)
commit9d7c870c6d66c8b2e066001f31ac3037d50f7012 (patch)
treec41da1755bdc2af527581c02cf2fd2ed9781ac38 /Modules
parentffa5a5015a359045d7efb2c4cd0b5738c97b86ce (diff)
downloadcpython-9d7c870c6d66c8b2e066001f31ac3037d50f7012.zip
cpython-9d7c870c6d66c8b2e066001f31ac3037d50f7012.tar.gz
cpython-9d7c870c6d66c8b2e066001f31ac3037d50f7012.tar.bz2
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. Will backport.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/itertoolsmodule.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 4ce4643..3515bc6 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -699,6 +699,12 @@ cycle_next(cycleobject *lz)
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);
@@ -1658,6 +1664,12 @@ chain_next(chainobject *lz)
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;