Wolfgang Maier added the comment:

You are probably right that the io classes are broken.

>From https://docs.python.org/3/library/stdtypes.html#iterator-types:

Once an iterator’s __next__() method raises StopIteration, it must continue to 
do so on subsequent calls. Implementations that do not obey this property are 
deemed broken.


One consequence of __iter__ returning self is that the above is not guaranteed:

>>> with open('somefile', 'w') as f:
        f.write('some text')

        
9
>>> with open('somefile', 'r') as f:
        i = iter(f)
        assert f is i
        for line in i:
                print(line)
        try:
                next(i)
        except StopIteration:
                print('exhausted iterator')
        f.seek(0)
        print(next(i))

        
some text
exhausted iterator
0
some text

So the io classes are *officially* broken.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23700>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to