mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
* 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
This commit is contained in:
parent
45d0b5cc44
commit
7892b1c651
5 changed files with 276 additions and 10 deletions
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue