On Fri, Aug 25, 2017 at 2:10 PM, Paul Rubin <no.email@nospam.invalid> wrote: > Steve D'Aprano <steve+pyt...@pearwood.info> writes: >> Did __next__ cache the most recently generated value? > > No but if they're going to change stuff, they might as well actually > improve it instead of just renaming it to break code gratutiously.
Any code that called iter.next() instead of next(iter) was already broken. Converting it to the proper notation makes it work on all Python versions. Any code that needs to *implement* an iterator can do so fairly simply: class Foo(object): # you already need (object) for Py2 compat def __iter__(self): return self def __next__(self): # whatever return 42 next = __next__ # this is all you need to add Considering that it then brings the protocol nicely in line with every other magic-method protocol in Python, this is a Good Thing. It's one more line of code in any class that is an iterator - not all iterables, only custom iterators. It's no additional code in consumers of iterators. ChrisA -- https://mail.python.org/mailman/listinfo/python-list