8000 gh-57531 add BufferedReader.read() return value check for non-blocking stream mode by z764969689 · Pull Request #105224 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-57531 add BufferedReader.read() return value check for non-blocking stream mode #105224

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
20da301
add BufferedReader.read() return value check for non-blocking stream …
z764969689 Jun 2, 2023
696119e
📜🤖 Added by blurb_it.
blurb-it[bot] Jun 2, 2023
8c430f3
fix input_chunk assignment error
z764969689 Jun 2, 2023
bee16c0
Merge branch 'fix-issue-57531' of github.com:z764969689/cpython into …
z764969689 Jun 2, 2023
3ef17f8
Merge branch 'main' into fix-issue-57531
z764969689 Jun 2, 2023
3206d0e
Merge branch 'main' into fix-issue-57531
z764969689 Jun 2, 2023
6cadcef
Merge branch 'main' into fix-issue-57531
z764969689 Jun 3, 2023
ac22938
Merge branch 'main' into fix-issue-57531
z764969689 Jun 4, 2023
28d82b5
Merge branch 'main' into fix-issue-57531
z764969689 Jun 5, 2023
7c1ba82
Merge branch 'main' into fix-issue-57531
z764969689 Jun 9, 2023
3ae14cc
Merge branch 'main' into fix-issue-57531
z764969689 Jun 28, 2023
caf95e0
Merge branch 'main' into fix-issue-57531
z764969689 Aug 2, 2023
af3cc86
Merge branch 'main' into fix-issue-57531
z764969689 Jan 18, 2024
d13f29c
Capitalize the first letter of the sentence in the NEWS entry
z764969689 Jan 18, 2024
68741ed
Fix error by manual resolution
z764969689 Jan 18, 2024
d5e5823
Merge branch 'main' into fix-issue-57531
z764969689 Jan 18, 2024
06e36d2
Merge branch 'main' into fix-issue-57531
z764969689 Jan 19, 2024
2c98129
add simple error raising test in test_io.py
z764969689 Jan 19, 2024
4014d38
Merge branch 'fix-issue-57531' of github.com:z764969689/cpython into …
z764969689 Jan 19, 2024
9d191d8
move test_read_non_blocking_stream test case to PyTextIOWrapperTest
z764969689 Jan 19, 2024
24370ab
Merge branch 'main' into fix-issue-57531
z764969689 Jan 22, 2024
cb7e3b0
Merge branch 'main' into fix-issue-57531
z764969689 Jan 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2512,8 +2512,11 @@ def read(self, size=None):
decoder = self._decoder or self._get_decoder()
if size < 0:
# Read everything.
if (input_chunk := self.buffer.read()) is None and isinstance(self.buffer, BufferedReader):
raise BlockingIOError(
"BufferedReader.read() return None, stream opened in non-blocking mode and not data is available")
result = (self._get_decoded_chars() +
decoder.decode(self.buffer.read(), final=True))
decoder.decode(input_chunk, final=True))
if self._snapshot is not None:
self._set_decoded_chars('')
self._snapshot = None
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3995,6 +3995,14 @@ class PyTextIOWrapperTest(TextIOWrapperTest):
io = pyio
shutdown_error = "LookupError: unknown encoding: ascii"

def test_read_non_blocking_stream(self):
# Issue #57531
# io module doesn't support non-blocking files
r = self.MockRawIO((None,))
b = self.BufferedReader(r, 1000)
t = self.TextIOWrapper(b, encoding="utf-8")
self.assertRaises(BlockingIOError, t.read)


class IncrementalNewlineDecoderTest(unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add BufferedReader.read() return value check for non-blocking stream mode, raise BlockingIOError instead of TypeError with more context for the caller.
0