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

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


Raymond Hettinger wrote:

> I recommend dropping the notion of forwarding from the proposal.
> The idea is use-case challenged, complicated, and should not be
> hidden behind new syntax.

I don't think it's conceptually complicated -- it
just seems that way when you write out the Python
code necessary to implement it *without* new syntax.

The essential concept is that, while the subgenerator
is running, everything behaves as though it were
talking directly to whatever is calling the outer
generator.

If you leave out some of the ways that the caller
can interact with a generator, such as send(), throw()
and close(), then it doesn't behave exactly that way,
and I think that would actually make it more complicated
to understand.

I should perhaps point out that the way I would
implement all this would *not* be by emitting
bytecode equivalent to the expansion in the PEP.
It would be more along the lines of the suggested
optimisation, and all the next(), send(), throw()
etc. calls would go more or less directly to the
subgenerator until it terminates. Done that way,
I expect the implementation would actually be fairly
simple and straightforward.

> Would hate for this to become a trojan horse proposal
> when most folks just want a fast iterator pass-through mechasism:

You can use it that way if you want, without having
to think about any of the other complications.

-- 
Greg



More information about the Python-ideas mailing list