[Python-ideas] Yield-From: GeneratorExit?

Nick Coghlan ncoghlan at gmail.com
Sun Mar 22 22:08:57 CET 2009

Jacob Holm wrote:
> If I understand Nick correctly, he would like to drop the "except
> GeneratorExit: raise" part, and possibly change BaseException to
> Exception. I don't like the idea of just dropping the "except
> GeneratorExit: raise", as that brings us back in the situation where
> shared subiterators are less useful. If we also change BaseException to
> Exception, the only difference is that it will no longer be possible to
> throw exceptions like SystemExit and KeyboardInterrupt that don't
> inherit from Exception to a subiterator.

Note that as of 2.6, GeneratorExit doesn't inherit from Exception either
- it now inherits directly from BaseException, just like the other two
terminal exceptions:

Python 2.6+ (trunk:66863M, Oct  9 2008, 21:32:59)
>>> BaseException.__subclasses__()
[<type 'exceptions.Exception'>, <type 'exceptions.GeneratorExit'>, <type
'exceptions.SystemExit'>, <type 'exceptions.KeyboardInterrupt'>]

All I'm saying is that if GeneratorExit doesn't get passed down then
neither should SystemExit nor KeyboardInterrupt, while if the latter two
*do* get passed down, then so should GeneratorExit.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list