[Python-ideas] Revised**7 PEP on Yield-From

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Mar 21 01:35:02 CET 2009

> Jacob Holm wrote:
>> The "GeneratorExit", I expect due to the description of close in PEP 342:
>> def close(self):
>> try:
>> self.throw(GeneratorExit)
>> except (GeneratorExit, StopIteration):
>> pass
>> else:
>> raise RuntimeError("generator ignored GeneratorExit")

Hmmm... well, my PEP kind of supersedes that when a yield-from
is in effect, because it specifies that the subiterator is
finalized first by attempting to call its 'close' method, not
by throwing GeneratorExit into it. After that, GeneratorExit is
used to finalize the delegating generator.

The reasoning is that GeneratorExit is an implementation
detail of generators, not something iterators in general should
be expected to deal with.


More information about the Python-ideas mailing list