[Python-ideas] Proto-PEP on a 'yield from' statement

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Feb 13 07:25:34 CET 2009

George Sakkis wrote:

> - A "yield x" expression has completely different semantics from
> "yield from x"; that's a bad idea given how similar they look.

If that's a concern, I would take it as an indication
that 'yield from' is perhaps not the best syntax to
use, and maybe it should be something completely new,
such as

    y = delegate f(args)

But then you lose the connection with generators that
the word 'yield' gives you.

> - Returning a value by stuffing it in the StopIteration abuses the
> exception mechanism.

I don't see why. StopIteration is already being used as
an out-of-band return value to signal the end of iteration.
Attaching further information to that return value doesn't
seem an unreasonable thing to do.

In any case, that's an implementation detail. There are
other ways that the desired result could be achieved --
the desired result being the appearance of the return
value as the value of the 'yield from' expression.


More information about the Python-ideas mailing list