[Python-ideas] Revised revised PEP on yield-from

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Feb 13 23:06:33 CET 2009

Bruce Frederiksen wrote:

>    1. I don't believe that you want the first yield statement (line 4). 
>       I think that this line should be deleted.

You're right, that's a mistake.

>    2. I would suggest returning the final value from close rather than
>       attached to StopIteration.

The advantage of using StopIteration is that any iterator
can take part in the protocol without having to grow a close()

I also suspect the implementation will be more straightforward,
since the point at which the return value from a generator
becomes available is the same point at which StopIteration is
raised. If close() is used for this, the value would have to
be stored somewhere until such time as close() is called.

Taking all this into account, using StopIteration to carry
the return value seems the most elegant solution to me.


More information about the Python-ideas mailing list