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

Jacob Holm jh at improva.dk
Mon Apr 20 11:05:45 CEST 2009

Greg Ewing wrote:
> Jacob Holm wrote:
>> We should probably add
>>   _x = sys.exc_info()
>> as the first line in the "except BaseException as _e" block, and change
>>   _y = _m(*sys.exc_info())
>> to:
>>   _y = _m(*_x)
> I'm not sure if this is really necessary, since function
> calls save/restore the exception being handled, if I
> understand correctly. But I suppose it can't hurt to
> clarify this.

For some reason I thought that the save/restore only applied to what 
would be raised by a bare raise and not to sys.exc_info().  I have just 
tested it with a small script and it appears I was wrong.  Sorry for the 

>> FWIW I still consider an expansion using functools.partial to be more 
>> readable
> That's a matter of opinion -- I find it harder to follow
> because it separates the logic for deciding which method
> to call from the place where it's called. 

It may be slightly harder to follow, but it is easier to see that 
StopIteration is treated the same for the three operations, and it is a 
bit shorter and less deeply nested.

Anyway, that is only my opinion and in this case it is yours that count.

> Also I would
> rather express the expansion in terms of core language
> features as far as possible rather than relying on
> something imported from a library.

As shown in my response to Nick, the use of functools.partial is not 
actually needed for this style of expansion.  It is just as easy to 
collect the function and arguments in different variables and use 
_m(*_a) in the call.

I'll shut up about it now.  If you still don't like it that's fine.

- Jacob

More information about the Python-ideas mailing list