Guido van Rossum wrote:
Well argued. I suggest to go for option (1) -- make GeneratorExit inherit from BaseException. We can do this starting 2.6. Feel free to upload a patch to bugs.python.org.
It actually took me a while to figure out why this use case was convincing, when the same idea had been rejected for 2.5.
For anyone else as slow as me: in the hypothetical examples I posted before the release of 2.5, the yield could be moved to an else clause on the try-except statement without adversely affecting the semantics.
The use case Chad presented here is different, because the exceptions to be handled are being passed back in via the yield expression - moving it would defeat the whole purpose of the exception handling. I'm sure the fact that the example comes from a real application rather than the 'what-if' generator in my brain helps a lot too :)
Cheers, Nick.