[Python-Dev] GeneratorExit is unintuitive and uneccessary

Phillip J. Eby pje at telecommunity.com
Thu Aug 24 02:43:31 CEST 2006


At 01:44 AM 8/24/2006 +0200, Igor Bukanov wrote:
>Regarding yield in the finally problem:
>
>The current implementation throws RuntimeException after the yield
>transfer the control back to the close method. If that is changed to
>reporting a bad behavior and rethrowing GeneratorExit or its hidden
>analog as suggested at the point of yield inside the generator, that
>would nicely unwind possible outer finally blocks and close the
>generator in any case.

This approach has already been proposed and rejected multiple times.  A 
badly-behaving generator is broken and asking it to handle the error of its 
own brokenness will lead only to grief.  Once the generator yields 
inappropriately, it has proven it cannot be trusted.  It is only 
compounding the generator's insanity to ask it to handle this error!



More information about the Python-Dev mailing list