Marko Rauhamaa wrote: > Chris Angelico <ros...@gmail.com>: > >> On Mon, Mar 16, 2015 at 6:12 PM, Marko Rauhamaa <ma...@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. >> >> [...] >> >> That just adds unnecessary overhead to every iterator. > > Trivial implementations are a normal way to satisfy an API. That's why > /dev/null implements a close() method, for example.
Absolutely. But you''ll notice it doesn't implement upper() and lower() methods, because it isn't a string, it's a file. Iterators shouldn't implement send() etc. methods because they aren't coroutines. >> Also, what happens when you throw something into iter([1,2,3]) ? Or >> send it a value? What happens? > > I would expect iter([1, 2, 3]) to behave highly analogously to > (x for x in [1, 2, 3]). I believe that it is an unfortunate mistake that generators which aren't coroutines support send. At the very least it is an ugly design wart, at worst it is an outright bug. -- Steven -- https://mail.python.org/mailman/listinfo/python-list