[Python-Dev] Iterating a closed StringIO

Nick Coghlan ncoghlan at gmail.com
Fri Nov 18 14:57:19 CET 2005


Guido van Rossum wrote:
> 
> I hope there isn't anyone here who believes this patch would be a bad idea?

Not me, but the Iterator protocol docs may need a minor tweak. Currently they 
say this:

"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 wording is a bit too strong, as it's perfectly acceptable for an object 
to provide other methods which affect the result of subsequent calls to the 
next() method (examples being the seek() and close() methods in the file 
interface).

The current wording does describe the basic intent of the API correctly, but 
you could forgiven for thinking that it ruled out modifying the state of a 
completed iterator in a way that restarts it, or causes it to raise an 
exception other than StopIteration.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.blogspot.com


More information about the Python-Dev mailing list