On Fri, Nov 21, 2014 at 4:56 PM, Alexander Heger email@example.com wrote:
Maybe a way to obtain equivalency to the generator functions in this case is to "break" this example for the iterator object as well, in that StopIteration has to be raised in the frame of the generator object; if it raised in a different context, e.g., a function called by __next__, that StopIteration should also be converted to a RuntimeError similar to what is proposed in the PEP for the generator functions. Maybe this is not what Chris intends to happen, but it would make things consistent.
I"mn not sure which Chris you are refering to, but for my part, yes and no:
Yes, that would keep iterator classes and generator functions consistent, which would be a good thing.
No: I don't think we should do that -- StopIteration is part of the iterator protocol -- generators are another way to write something that complies with the iterator protocol -- generators should handle StopIteration the same way that iterator classes do.
Yes, there are some cases that can be confusing and hard to debug -- but them's the breaks.