[Python-Dev] iterator API in Py3.

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Mar 2 04:19:19 CET 2006


Raymond Hettinger wrote:

> [Greg Ewing]
> 
> > And you don't think there are many different
> > types of iterables?
> 
> Um, I meant iterators and suspect you meant the same --

The same comment applies either way. Each type of iterable
usually has its own corresponding type of iterator.

> YAGNI.  The hypothetical "future development" benefit is even more 
> specious than the appeal for consistency.

I've pointed out one possible use that would have
provided a benefit, so rather than YAGNI, I'd say
WACHUI (We Already Could Have Used It).

>  Let's try to resist 
> mucking-up this simple, elegant, and fast iterface by adding another 
> level of indirection.

There's already a level of indirection, because the
type creation machinery adds a descriptor to allow the
type slot to be called via .next() from Python. If there
were a next() function, that descriptor would not be needed.
So the total amount of indirection for built-in iterators
would remain the same.

> Looking 
> back at Guido's original rationale for naming the method next() instead 
> of __next__(), http://www.python.org/peps/pep-0234.html , it does not 
> look like any of those reasons will cease to apply in Py3.0.

The discussion in that PEP makes no mention of the flexibility
benefits of a next()/.__next__() combination. Mostly it
doesn't even discuss the combination at all, only the idea
of calling the method __next__(). The idea of a next() function
is only mentioned in a parenthetical comment in which the
sole reason for rejecting it is "it's too late, we've already
implemented it".

In 3.0 we will have a rare opportunity to revisit the idea
without the "it's too late" constraint. I'm suggesting we
give it careful consideration, because we probably won't
have another opportunity for quite a long time.

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | Carpe post meridiam!          	  |
Christchurch, New Zealand	   | (I'm not a morning person.)          |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list