On 11/19/2014 04:25 PM, Steven D'Aprano wrote:
Here is a description of the generator protocol which could easily lead the reader to conclude that raising StopIteration is the correct way to exit a generator:
To support this protocol, functions with yield statement are compiled specially as generators. They return a generator object when they are called. The returned object supports the iteration interface with an automatically created __next__() method to resume execution. Generator functions may have a return simply terminates the generation of values by raising a StopIteration exceptions after any normal function exit.
We are not, however, responsible for third-party documentation.
At this point, I'm convinced that there is a good argument for a __future__ import changing this behaviour. But I suspect that making this the default behaviour in the future will break a lot of code.
Isn't that the case with every __future__ directive that becomes the standard? Folks have an entire minor release to make the adjustment.