[Python-ideas] Cofunctions PEP - Revision 4
ncoghlan at gmail.com
Thu Aug 12 14:12:35 CEST 2010
On Thu, Aug 12, 2010 at 8:42 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
>> You want more than the iterator protocol - you want the whole
>> generator API (i.e. send() and throw() as well as __next__()).
> I can't see why that should be necessary. A 'yield from'
> manages to degrade gracefully when given something that
> only supports next(), and there's no reason a cocall can't
> do the same.
Without send() and throw(), an object is just an iterator, never a
cofunction (as there is no way for it to make cooperative calls - you
need the extra two methods in order to receive the results of any such
calls). Implementing __cocall__ without yourself being able to make
cooperative calls doesn't make any sense.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas