On 2015-10-01 20:58, Steven D'Aprano wrote:
Since the semantics of the function are intentional and correct, the parameter is named misleadingly. *iterable* is not sufficiently precise, because the function does not accept any old iterable -- it fails to work correctly on *iterators*, are a sub-kind of iterable.
If you want a more practical example, any algorithm which needs to iterate over an interable two or more times needs to specify "iterable which is not an iterator".
I would disagree with this, because this terminology is both too technical and not technical enough. Just because something isn't an iterator doesn't mean you can iterate it multiple times. You *could* write an iterable which is not an iterator but still can't be iterated over multiple times (because, say, it returns a reference to some stored iterator that can't be restarted, or because it creates a custom iterator that references some persistent state of the iterable). If what you want is an iterable that can be iterated multiple times, then just say that. (Or say "reiterable" or "reentrant iterable" or whatever.) There's no need to bring iterators into it at all.