[Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)
greg.ewing at canterbury.ac.nz
Sat Oct 20 01:02:17 CEST 2012
Christian Tismer wrote:
> Can you give me a hint how your initial implementation
> works, the initial patch source?
You can find my initial patches here:
Essentially, an extra field f_yieldfrom is added to frame
objects. When a 'yield from' is started, the f_yieldfrom field
of the calling frame is set to point to the called frame.
The __next__ method of a generator first traverses the
f_yieldfrom chain to find the frame at the end, and then
resumes that frame. So most of the time, only the innermost
frame of a nested yield-from chain is actually entered in
response to a next() call.
(There are some complications due to the fact that you can
'yield from' something that's not a generator, but the above
is effectively what happens when all the objects in the
chain are generators.)
More information about the Python-ideas