[Python-Dev] Termination of two-arg iter()

Andrew P. Lentvorski bsder@mail.allcaps.org
Sun, 14 Jul 2002 03:23:25 -0700 (PDT)


On Sun, 14 Jul 2002, Brett Cannon wrote:

> end.  It seems like StopIteration is saying "stop please" and
> IteratorExhausted would be like screaming "STOP CALLING .next()!!!".

What about raising IndexError by default when someone attempts to call
.next() on an iterator already raising StopIteration?

In the case of a list, StopIteration signals that the iterator is pointing
to just beyond the end of the list.  An attempt to call .next() when
StopIteration is already true is effectively an attempt to dereference
past the end of a list (since .next() normally wants to return a value).

List accesses via an index past list end currently raise an IndexError.
Doing something similar for iterators would seem to keep things
consistent.

-a