[Python-ideas] Possible PEP 380 tweak

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Oct 28 22:14:46 CEST 2010


Jacob Holm wrote:

> 1) Define a new "coiterator" protocol, consisting of a new special
> method __conext__, and a new StopCoIteration exception that the regular
> StopIteration inherits from.

I don't think it's necessary to have a new protocol. All
that's needed is to allow for the possibility of the
__next__ method of an iterator being a cofunction.

Under the current version of PEP 3152, with an explicit
"cocall" operation, this would require a new kind of
for-loop. Maybe using "cofor"?

However, my current thinking on cofunctions is that
cocalls should be implicit -- you declare a cofunction
with "codef", and any call made within it can potentially
be a cocall. In that case, there would be no need for new
syntax -- the existing for-loop could just do the right
thing when given an object whose __next__ method is a
cofunction.

Thinking about this has made me even more sure that
implicit cocalls are the way to go, because it means
that any other things we think of that need to take
cofunctions into account can be fixed without having
to introduce new syntax for each one.

-- 
Greg



More information about the Python-ideas mailing list