-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-80050: Update BufferedReader.read docs around non-blocking #130653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Synchronize `io.BufferedReader` and `io.BufferedIOBase` documentation with the current implementation. Focused on behavior around non-blocking streams.
BufferedReader at least just forwards `None` from the underlying stream. 1. `BufferedReader.read(size=10)` `raw.read(size=10)` returns None 2. `BufferedReader.read()` without size, raw implements `readall()` which returns None 3. `BufferedReader.read()` without size, raw doesn't have readall so uses a loop that calls `raw.read()` which returns None.
cc: @gpshead |
@@ -826,8 +823,8 @@ than raw I/O does. | |||
|
|||
Write the :term:`bytes-like object`, *b*, and return the | |||
number of bytes written. When in non-blocking mode, a | |||
:exc:`BlockingIOError` is raised if the buffer needs to be written out but | |||
the raw stream blocks. | |||
:exc:`BlockingIOError` with :attr:`BlockingIOError.characters_written` set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
characters_written
is fairly well tested in this case
Lines 1918 to 1943 in a7f317d
def test_write_non_blocking(self): | |
raw = self.MockNonBlockWriterIO() | |
bufio = self.tp(raw, 8) | |
self.assertEqual(bufio.write(b"abcd"), 4) | |
self.assertEqual(bufio.write(b"efghi"), 5) | |
# 1 byte will be written, the rest will be buffered | |
raw.block_on(b"k") | |
self.assertEqual(bufio.write(b"jklmn"), 5) | |
# 8 bytes will be written, 8 will be buffered and the rest will be lost | |
raw.block_on(b"0") | |
try: | |
bufio.write(b"opqrwxyz0123456789") | |
except self.BlockingIOError as e: | |
written = e.characters_written | |
else: | |
self.fail("BlockingIOError should have been raised") | |
self.assertEqual(written, 16) | |
self.assertEqual(raw.pop_written(), | |
b"abcdefghijklmnopqrwxyz") | |
self.assertEqual(bufio.write(b"ABCDEFGHI"), 9) | |
s = raw.pop_written() | |
# Previously buffered bytes were flushed | |
self.assertTrue(s.startswith(b"01234567A"), s) |
…ythonGH-130653) (cherry picked from commit e1f8914) Co-authored-by: Cody Maloney <[email protected]>
Sorry, @cmaloney and @gpshead, I could not cleanly backport this to
|
GH-134444 is a backport of this pull request to the 3.14 branch. |
…cking (pythonGH-130653) (cherry picked from commit e1f8914) Co-authored-by: Cody Maloney <[email protected]>
GH-134445 is a backport of this pull request to the 3.13 branch. |
…H-130653) (#134445) (cherry picked from commit e1f8914) Co-authored-by: Cody Maloney <[email protected]>
Synchronize
io.BufferedReader
andio.BufferedIOBase
documentation with the current implementation. Focused on behavior around non-blocking streams.📚 Documentation preview 📚: https://cpython-previews--130653.org.readthedocs.build/