On 11/17/2014 08:50 PM, Guido van Rossum wrote:
Separate from this special case, I am also worried about backward compatibility, and I have yet to get a good idea for how widespread code is that depends on StopIteration bubbling out from generators. I also don't have a good idea how often this issue bites users, but I have a feeling it does bite.
One argument for making the change*: When we're writing __next__, or __getattr__, etc., it is obvious that we are playing with internals and have to be extra careful of what other exceptions might be raised in that code. Contrariwise, the only indication of something special about a generator is the presence of the yield keyword -- for ordinary use (such as in for loops) it doesn't matter whether the called function returns a list, tuple, iterator, generator, or whatever, as long as it can be iterated over, and so when writing a generator, or converting an iterable-returning function into a generator, there's nothing obvious saying, "Hey! Watch out for a StopIteration somewhere else in this block of code!"
* I make no statement as to how strong this argument is, but there you have it. :)