
March 2, 2009
5:21 a.m.
Jim Jewett wrote:
I would expect that to be interpreted as a StopIteration and handled gracefully. If that doesn't seem reasonable, then I wonder if the whole protocol is still too fragile.
I've just done what I should have done in the first place and checked the documentation. From the Library Reference, section 3.5, Iterator Types: "The intention of the protocol is that once an iterator's next() method raises StopIteration, it will continue to do so on subsequent calls. Implementations that do not obey this property are deemed broken. (This constraint was added in Python 2.3; in Python 2.2, various iterators are broken according to this rule.)" So according to modern-day rules at least, Jacob's example will work fine. -- Greg