[Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in
Ka-Ping Yee
python-dev at zesty.ca
Mon Mar 5 23:31:44 CET 2007
On Mon, 5 Mar 2007 python at rcn.com wrote:
> Can I suggest that next() and __next__() be dropped entirely
> and that iterators just be made callable.
We went through a long discussion about this when iterators
were being figured out the first time around -- in fact, using
__call__ was the original proposal, and then it was changed
to __next__. I imagine we must have had good reasons for it.
PEP 234 (it amuses me that the PEP number for iterators is
three digits in arithmetic sequence) says:
Arguments against __call__() (the original proposal): taken out
of context, x() is not very readable, while x.next() is clear;
there's a danger that every special-purpose object wants to use
__call__() for its most common operation, causing more confusion
than clarity.
I think __next__ is better than __call__ because EIBTI. It's
a lot more obvious that you're doing explicit iteration (and
have all the expectations that go along with it) when you see
the call to the next built-in (or method).
Explicit iteration (calling next) is quite a bit less common
than implicit iteration (with for loops), so it's probably a
good idea for it to have a distinct look to it. Function calls
happen all over the place; it would be easy not to notice that
iteration is occurring with an x() call buried among lots of
other stuff.
-- ?!ng
More information about the Python-3000
mailing list