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

Jacob Holm jh at improva.dk
Fri Mar 20 20:32:46 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")
> When the generator is closed (due to the del g lines in the example), 
> this says to throw a GeneratorExit and handle the result. If we do 
> this manually, the throw will be delegated to the iterator, which will 
> print the "Throw: (<type 'exceptions.GeneratorExit'>,)" message.

It turns out I was wrong about the GeneratorExit. What I missed is that 
starting from 2.6, GeneratorExit no longer subclasses Exception, and so 
it wouldn't be thrown at the iterator. So move along, nothing to see 
here ... :)

- Jacob

More information about the Python-ideas mailing list