gh-109523: Raise a BlockingIOError if reading text from a non-blocking stream cannot immediately return bytes. (GH-122933)

This commit is contained in:
Giovanni Siragusa 2024-12-02 14:18:30 +01:00 committed by GitHub
parent 930ba0ce60
commit 31f16e427b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 57 additions and 1 deletions

View file

@ -2545,9 +2545,12 @@ class TextIOWrapper(TextIOBase):
size = size_index()
decoder = self._decoder or self._get_decoder()
if size < 0:
chunk = self.buffer.read()
if chunk is None:
raise BlockingIOError("Read returned None.")
# Read everything.
result = (self._get_decoded_chars() +
decoder.decode(self.buffer.read(), final=True))
decoder.decode(chunk, final=True))
if self._snapshot is not None:
self._set_decoded_chars('')
self._snapshot = None