On Fri, Nov 21, 2014 at 4:56 PM, Alexander Heger <python@2sn.net> 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.



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception