summaryrefslogtreecommitdiffstats
path: root/Objects/enumobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-04-12 18:10:01 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-04-12 18:10:01 (GMT)
commit7892b1c651d72a5bd08372f40309dec08a7065f0 (patch)
tree7ae71a1e81651c4fa7f786ebfbdbc8364a41730e /Objects/enumobject.c
parent45d0b5cc44ffb6227a2379a39b00d480f253edd5 (diff)
downloadcpython-7892b1c651d72a5bd08372f40309dec08a7065f0.zip
cpython-7892b1c651d72a5bd08372f40309dec08a7065f0.tar.gz
cpython-7892b1c651d72a5bd08372f40309dec08a7065f0.tar.bz2
* 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
Diffstat (limited to 'Objects/enumobject.c')
-rw-r--r--Objects/enumobject.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index 28719a9..549fc9f 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -225,6 +225,9 @@ reversed_next(reversedobject *ro)
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 @@ PyDoc_STRVAR(reversed_doc,
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 = {