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

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Apr 9 01:45:51 CEST 2009

Jacob Holm wrote:
> I think the best way of handling this is to add a read-only 
> property to generator objects holding the latest value yielded... The 
> property can be cleared when the frame is released, so there should be 
> no issues with that.

It will still keep the value alive longer than it would
be otherwise. Some people might take issue with that.

> def dropwhile(predicate, iterable):
>    it = iter(iterable)
>    v = next(it)
>    while predicate(v):
>        v = next(it)
>    return yield from it  # Starts by yielding the last value checked, 
> which is v.

In my view this constitutes a shared iterator, and is
therefore outside the scope of yield-from.

I also don't think this generalizes well enough to be
worth going out of our way to support. It only works
because you're making a "tail call" to the iterator,
which is a rather special case. Most itertools-style
functions won't have that property.

> What's not to like?

The fact that yield-from and/or generator behaviour
is being complexified to support things that are
outside the scope of my proposal.

This is why I want to keep focused on refactoring,
to prevent this kind of feature creep.


More information about the Python-ideas mailing list