generator/coroutine terminology

Ian Kelly ian.g.kelly at gmail.com
Mon Mar 16 03:37:54 EDT 2015


On Mon, Mar 16, 2015 at 1:12 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> I was actually referring to the offered API. It still seems to me like
> all iterators could offer close(), send() and throw(). Why? To make all
> iterators drop-in replacements of each other.

The purpose of close, send and throw is to implement *coroutines*, not
iterators. The fact that coroutines in Python happen to be implemented
as a type of iterator doesn't mean that all iterators need to have
them. You're free to add these methods to non-generator iterators that
you write in order to create iterators that pretend to be coroutines,
but I'm having a hard time seeing what purpose would be served by
this.

If on the other hand these methods were to be added to the iterator
protocol, it would just create unnecessary implementation overhead for
the 99.99% of non-generator iterators that are under no illusions
about the fact that they aren't coroutines.



More information about the Python-list mailing list