mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +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
|
@ -74,8 +74,16 @@ iter_iternext(PyObject *iterator)
|
|||
static int
|
||||
iter_len(seqiterobject *it)
|
||||
{
|
||||
if (it->it_seq)
|
||||
return PyObject_Size(it->it_seq) - it->it_index;
|
||||
int seqsize, len;
|
||||
|
||||
if (it->it_seq) {
|
||||
seqsize = PySequence_Size(it->it_seq);
|
||||
if (seqsize == -1)
|
||||
return -1;
|
||||
len = seqsize - it->it_index;
|
||||
if (len >= 0)
|
||||
return len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue