[Python-ideas] Generators are iterators

Chris Angelico rosuav at gmail.com
Thu Dec 11 11:05:36 CET 2014


On Thu, Dec 11, 2014 at 8:49 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> Currently, a StopIteration raised during 'run(self.gi_frame)' is passed on
> like any other exception, but treated specially by the generator caller.
> The change is to wrap the frame execution or do the equivalent thereof.
>
> try:
>     run(self.gi_frame)
> except StopIteration()
>     raise RuntimeError

That's pretty much how the proof-of-concept patch works, yes. (Though
the parentheses after StopIteration seem wrong I think?) In theory, it
should chain the exceptions, though that's not always currently
working. Improvements to the patch welcomed :)

ChrisA


More information about the Python-ideas mailing list