[Python-ideas] Cofunctions - an enhancement to yield-from

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Aug 2 02:07:06 CEST 2010


Antoine Pitrou wrote:

> Is it an enhancement or really an alternate proposal?

I would say it's complementary. There are still use cases for
'yield from', when you're dealing with generators that are
designed to produce values.

Given that both are useful, defining cofunctions in terms of
yield-from allows them to share most of the underlying machinery.
It also makes it clear how ordinary functions, generators and
cofunctions all interact with each other.

> From an outsider's view (mine :-)), I think this alternative makes more
> sense than trying to stretch the generator protocol far beyond what it
> was designed for at the start. It would also clearly separate the two
> use cases of generative iteration and coroutines.

Well, that's one way of looking at it. Another is that generators
and coroutines are such closely related concepts that it would
seem odd not to be able to define one in terms of the other,
or both in terms of some unifying construct.

-- 
Greg



More information about the Python-ideas mailing list