The patch is good.
I was first surprised by the fact that e.characters_written is not used
in the write() method; but _flush_unlocked() already adjusts the
_write_buf according to the original e.characters_written raised by the
underlying raw file. Everything is fine.
I suggest however to add some tests around the first "except
BlockingIOError". This would answer the question:
# XXX Why not just let the exception pass through?
For example, I modified a function in your patch:
def testWriteNonBlockingOverage(self):
raw = MockNonBlockWriterIO((-1, -2))
[...]
# Subsequent calls to write() try to flush the raw file.
try:
bufio.write(b"x")
except io.BlockingIOError as e:
# Two more chars were written at the raw level
self.assertEqual(bufio._write_buf, write_buf[2:])
# But write() did not accept anything.
self.assertEqual(e.characters_written, 0)
else:
self.fail("BlockingIOError not raised") |