[Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in

Guido van Rossum guido at python.org
Mon Mar 5 19:48:50 CET 2007


On 3/5/07, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> As an alternative, I propose that object grows a .next() method,
> which calls __next__ by default.

This would seem slated to confuse users; they will attempt to
implement next() instead of __next__(). Or people would attempt to
override these differently. If the builtin next() bites the dust, I
would rather learn to live with calling __next__() directly, just as
for certain occasions one resorts to call __import__().

On 3/5/07, python at rcn.com <python at rcn.com> wrote:
> Can I suggest that next() and __next__() be dropped entirely
>  and that iterators just be made callable.

This sounds attractive, except that I fear that the optimizations
we've implemented for calling tp_next (especially for built-in
iterators like list or dict iterators). Since tp_call must be usable
in other contexts, and has much more optional features, it will be
hard to carry these optimizations over.

It would also invalidate classes that serve as their own iterator
(like files) and already implement __call__() for sa different
purpose.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list