On Wed, Nov 19, 2014 at 08:19:41PM -0800, Ethan Furman wrote:
We are not, however, responsible for third-party documentation.
No, of course not, but we should be aware that:
* some people believe that raising StopIteration is an acceptable way to exit a generator; and
* doing so has worked fine since generators were introduced back in Python 2.2.
I wonder whether people who learned about generators back in the 2.2 days will have stronger opinions about raising StopIteration than more recent users? I remember learning that an explicit raise was the way to exit a generator, and sure enough the 2.2 What's New says this:
Inside a generator function, the return statement can only be used without a value, and signals the end of the procession of values; afterwards the generator cannot return any further values. return with a value, such as return 5, is a syntax error inside a generator function. The end of the generator’s results can also be indicated by raising StopIteration manually, or by just letting the flow of execution fall off the bottom of the function.
That's not to say that we can't change the behaviour, but neither can we say it is undocumented or blame third parties.
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.
Huh, you say that like it's a long time :-)