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

Jim Jewett jimjjewett at gmail.com
Fri Apr 3 20:48:22 CEST 2009

On 4/3/09, Jacob Holm <jh at improva.dk> wrote:

> Yielding the current value on each send was not part of the original
> example ...

So in the original you cared about the final value, but not the
intermediate yields.  My question is whether there is a sane case
where you care about *both*, *and* you care about distinguishing them.
 And is this case common really enough that we don't want it marked up
with something more explicit, like a sentinel or a raise?

> The reason for closing would be that once you have computed the final
> result, you want whatever resources the coroutine is using to be freed.
> Since only the final result is assumed to be useful, it makes perfect
> sense to close the coroutine at the same time as you are requesting the
> final result.

    def outer(unfinished=object()):
        for result in g:
            yield unfinished    # cooperative multi-tasking, so co-operate
            if result is not unfinished: break

I see some value in simplifying that, or adding more power.

But I'm not convinced the current proposal actually is much simpler,
or that the extra power wouldn't be better written in a more explicit
manner.  I think the above still translates into

    def outer(unfinished=object()):
        #    # now also need to set an initial value of result
        #    # *OR* distinguish intermediate from final results.
        #    result=unfinished
        #    # loop is now implicit
        #    while result is unfinished:
        #        result = yield from g
        result = yield from g

More information about the Python-ideas mailing list