Mercurial > cpython-lru_cache-weakref
diff Objects/enumobject.c @ 31908:058821d8aefd legacy-trunk
* Add unittests for iterators that report their length
* Document the differences between them
* Fix corner cases covered by the unittests
* Use Py_RETURN_NONE where possible for dictionaries
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Mon, 12 Apr 2004 18:10:01 +0000 |
| parents | 04eb2ebb46e2 |
| children | 4ca9fa2353bf |
line wrap: on
line diff
--- a/Objects/enumobject.c Mon Apr 12 17:21:03 2004 +0000 +++ b/Objects/enumobject.c Mon Apr 12 18:10:01 2004 +0000 @@ -225,6 +225,9 @@ ro->index--; return item; } + if (PyErr_ExceptionMatches(PyExc_IndexError) || + PyErr_ExceptionMatches(PyExc_StopIteration)) + PyErr_Clear(); } ro->index = -1; if (ro->seq != NULL) { @@ -242,7 +245,15 @@ static int reversed_len(reversedobject *ro) { - return ro->index + 1; + int position, seqsize; + + if (ro->seq == NULL) + return 0; + seqsize = PySequence_Size(ro->seq); + if (seqsize == -1) + return -1; + position = ro->index + 1; + return (seqsize < position) ? 0 : position; } static PySequenceMethods reversed_as_sequence = {
