[Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Oct 20 02:50:28 CEST 2012

Christian Tismer wrote:
> Actually I would like to have a python context where it gets into
> "async mode" and interprets all functions defined in that mode as 
> generators.

That sounds somewhat similar to another idea I proposed a while

There would be a special kind of function called a "cofunction",
that you define using "codef" instead of "def". A cofunction
is essentially a generator, but with a special property: when
one cofunction calls another, the call is implicitly made as
a "yield from" call.

This scheme wouldn't be completely transparent, since the
cofunctions have to be defined in a special way. But the calls
would look like ordinary calls.

There's a PEP describing a variation on the idea here:


In that version, calls to cofunctions are specially marked
using a "cocall" keyword. But since writing that, I've come to
believe that my original idea (where the cocalls are implicit)
was better.


More information about the Python-ideas mailing list