diff options
author | Raymond Hettinger <python@rcn.com> | 2004-05-08 19:52:39 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-05-08 19:52:39 +0000 |
commit | eda9da79bb233324fc33c6bfcf623947d3c8de76 (patch) | |
tree | a012800c07a049f54aab394d399b96815d41495a /Modules | |
parent | 5ea315bbdde027515664b9e795ebcc0118593e46 (diff) | |
download | cpython-git-eda9da79bb233324fc33c6bfcf623947d3c8de76.tar.gz |
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/itertoolsmodule.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 68e176f23d..edc6159c87 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -94,6 +94,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); @@ -1049,6 +1055,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; |