This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wolma
Recipients bkabrda, ethan.furman, georg.brandl, ncoghlan, paul.moore, python-dev, r.david.murray, sYnfo, serhiy.storchaka, vstinner, wolma
Date 2015-03-20.16:13:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1426868018.97.0.21995057526.issue23700@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-03-20 16:13:39wolmasetrecipients: + wolma, georg.brandl, paul.moore, ncoghlan, vstinner, r.david.murray, ethan.furman, python-dev, serhiy.storchaka, bkabrda, sYnfo
2015-03-20 16:13:38wolmasetmessageid: <1426868018.97.0.21995057526.issue23700@psf.upfronthosting.co.za>
2015-03-20 16:13:38wolmalinkissue23700 messages
2015-03-20 16:13:38wolmacreate