Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Synchronize `io.BufferedReader` and `io.BufferedIOBase` documentationwith the current implementation. Focused on behavior around non-blockingstreams.
Uh oh!
There was an error while loading.Please reload this page.
BufferedReader at least just forwards `None` from the underlying stream.1. `BufferedReader.read(size=10)` `raw.read(size=10)` returns None2. `BufferedReader.read()` without size, raw implements `readall()` which returns None3. `BufferedReader.read()` without size, raw doesn't have readall so uses a loop that calls `raw.read()` which returns None.
Uh oh!
There was an error while loading.Please reload this page.
cc:@gpshead |
Uh oh!
There was an error while loading.Please reload this page.
@@ -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 ina7f317d
deftest_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") | |
exceptself.BlockingIOErrorase: | |
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) |
e1f8914
intopython:mainUh oh!
There was an error while loading.Please reload this page.
…ythonGH-130653)(cherry picked from commite1f8914)Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Sorry,@cmaloney and@gpshead, I could not cleanly backport this to
|
GH-134444 is a backport of this pull request to the3.14 branch. |
…cking (pythonGH-130653)(cherry picked from commite1f8914)Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
GH-134445 is a backport of this pull request to the3.13 branch. |
Uh oh!
There was an error while loading.Please reload this page.
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/