[issue1677872] Efficient reverse line iterator
Mark Russell
report at bugs.python.org
Mon Dec 10 21:56:44 CET 2007
Mark Russell added the comment:
As Guido requested I've split off the generic reversed() and __reversed__()
doc additions to this patch against 2.6: http://bugs.python.org/issue1582
The I/O error from reversed(open("/etc/passwd")) was caused by the inner
TextIOWrapper calling close() (via the inherited IOBase.__del__() method).
I've fixed it by having TextIOReverseIterator keep a reference to the file
object, and added a test case for the bug.
I think it's at least questionable that TextIOWrapper.close() is calling
buffer.close() on a buffer that it did not create. I assumed that keeping
a reference to the buffer object would be enough to keep the buffer open,
and I suspect this is likely to trip up others in future. I think
TextIOWrapper.close() should probably just set a flag (for the use of its
own closed() method) and rely on reference counting to call close()
on the buffer object. If that sounds on the right lines I'm happy to think
about it a bit more and submit a patch.
Added file: http://bugs.python.org/file8913/reverse-file-iterator-20071210.diff
_____________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1677872>
_____________________________________
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: reverse-file-iterator-20071210.diff
Url: http://mail.python.org/pipermail/python-bugs-list/attachments/20071210/a0835968/attachment-0001.txt
More information about the Python-bugs-list
mailing list