[Python-ideas] x=(yield from) confusion [was:Yet another alternative name for yield-from]

Jim Jewett jimjjewett at gmail.com
Thu Apr 9 18:47:18 CEST 2009

On 4/9/09, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Jacob Holm wrote:
>> Then let me revisit my earlier statement that when close() catches a
>> StopIteration with a non-None value, it should either return it or raise
>> an exception.

This implies that the value is always important; I write plenty of
functions that don't bother to return anything, and expect that would
still be common if I were factoring out loops.

>> Since the value is not saved, a second close() will
>> neither be able to return it, nor raise a StopIteration with it.

If close is called more than once, that suggests at least one of those
calls is just freeing resources, and doesn't need a value.

>>> It doesn't matter if there is only one use case, as long as it is a
>>> common one. And we already have that: Greg Ewing's "refactoring".

>> I remain unconvinced that the "initial next()" issue isn't also a
>> problem for that use case, but I am not going to argue about this.

That does suggest that yield-from *should* accept pre-started
generators, if only because the previous line (or a decorator) may
have primed it.

> For refactoring, the pattern of passing in a "start" value for use in
> the first yield expression in the subiterator should be adequate.

Only if you know what the first value should be.  If you're using a
sentinel that you plan to discard, then it would be way simpler to
just prime the generator before the yield-from.


More information about the Python-ideas mailing list