[Python-Dev] Re: Single- vs. Multi-pass iterability
François Pinard
pinard@iro.umontreal.ca
09 Jul 2002 21:05:58 -0400
[Greg Ewing]
> pinard@iro.umontreal.ca:
> > could we have the guarantee that if an iterable returns an
> > iterator through the iterable's __iter__, the iterator's __iter__ method
> > will never be called from looping over the iterable?
> [...pause while Greg's brain parses that sentence...]
(Sorry for my bad English.)
> Yes, I believe that's true.
If yes, then, the Library Reference is misleading, at the page:
http://www.python.org/dev/doc/devel/lib/typeiter.html
when it strongly says that any iterator's __iter__ method is "required".
I guess this is a possible source of confusion.
The context does not make it clear that the iterator's __iter__ method is
*only* required whenever one *also* wants to use an iterator as an iterable.
Better would be to describe __iter__ only once, the first time through,
saying everything there that has to be said, and only retain for iterators
the requirement of having a `next()' method. We should describe the truth.
P.S. - Also, I do not understand the tiny bit about the `in' statement in the
above page. Has `in' ever been a statement? If it refers to the comparison
operator `in', then has it any special properties when used with iterators?
I'm unsuccessful at seeing any hint about this from the documentation:
http://www.python.org/dev/doc/devel/ref/comparisons.html
--
François Pinard http://www.iro.umontreal.ca/~pinard