Skip to content

Commit 8085f74

Browse files
bpo-34215: Clarify IncompleteReadError message when "expected" is None (GH-21925)
Co-Authored-By: Tyler Bell <[email protected]>
1 parent 5b0194e commit 8085f74

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Lib/asyncio/exceptions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class IncompleteReadError(EOFError):
3434
- expected: total number of expected bytes (or None if unknown)
3535
"""
3636
def __init__(self, partial, expected):
37+
r_expected = 'undefined' if expected is None else repr(expected)
3738
super().__init__(f'{len(partial)} bytes read on a total of '
38-
f'{expected!r} expected bytes')
39+
f'{r_expected} expected bytes')
3940
self.partial = partial
4041
self.expected = expected
4142

Lib/test/test_asyncio/test_streams.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,14 @@ def test_readuntil_multi_chunks_1(self):
444444

445445
def test_readuntil_eof(self):
446446
stream = asyncio.StreamReader(loop=self.loop)
447-
stream.feed_data(b'some dataAA')
447+
data = b'some dataAA'
448+
stream.feed_data(data)
448449
stream.feed_eof()
449450

450-
with self.assertRaises(asyncio.IncompleteReadError) as cm:
451+
with self.assertRaisesRegex(asyncio.IncompleteReadError,
452+
'undefined expected bytes') as cm:
451453
self.loop.run_until_complete(stream.readuntil(b'AAA'))
452-
self.assertEqual(cm.exception.partial, b'some dataAA')
454+
self.assertEqual(cm.exception.partial, data)
453455
self.assertIsNone(cm.exception.expected)
454456
self.assertEqual(b'', stream._buffer)
455457

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Clarify the error message for :exc:`asyncio.IncompleteReadError` when
2+
``expected`` is ``None``.

0 commit comments

Comments
 (0)