[Python-ideas] Yield-From: Finalization guarantees
Jacob Holm
jh at improva.dk
Mon Mar 30 00:59:48 CEST 2009
Nick Coghlan wrote:
> Jacob Holm wrote:
>
>> Having a return in the finally clause like in my example is sufficient
>> to suppress the exception.
>>
>
> Ah, I did miss that - I think it just means the code has been refactored
> incorrectly though.
>
>
Ok
> I think the refactoring is buggy, because it has changed the code from
> leaving exceptions alone to suppressing them. Consider what it would
> mean to do the same refactoring with normal functions:
>
> def inner():
> try:
> perform_operation()
> finally:
> return 'VALUE'
>
> def outer():
> val = inner()
> print val
>
> That code does NOT do the same thing as:
>
> def outer():
> try:
> perform_operation()
> finally:
> val = 'VALUE'
> print val
>
Good point. Based on this observation, I withdraw the proposal about
storing the active exception on the GeneratorReturn and reraising it in
yield-from. I still think we should get rid of the check for
GeneratorExit, because of the other example I gave.
- Jacob
More information about the Python-ideas
mailing list