Skip to content

Commit df6c8bc

Browse files
bpo-34215: Clarify IncompleteReadError message when "expected" is None (GH-21925) (GH-23539)
Co-Authored-By: Tyler Bell <[email protected]> (cherry picked from commit 8085f74) Co-authored-by: Zackery Spytz <[email protected]> Co-authored-by: Zackery Spytz <[email protected]>
1 parent 761c5a1 commit df6c8bc

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Lib/asyncio/exceptions.py

Lines changed: 2 additions & 1 deletion
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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,14 @@ def test_readuntil_multi_chunks_1(self):
452452

453453
def test_readuntil_eof(self):
454454
stream = asyncio.StreamReader(loop=self.loop)
455-
stream.feed_data(b'some dataAA')
455+
data = b'some dataAA'
456+
stream.feed_data(data)
456457
stream.feed_eof()
457458

458-
with self.assertRaises(asyncio.IncompleteReadError) as cm:
459+
with self.assertRaisesRegex(asyncio.IncompleteReadError,
460+
'undefined expected bytes') as cm:
459461
self.loop.run_until_complete(stream.readuntil(b'AAA'))
460-
self.assertEqual(cm.exception.partial, b'some dataAA')
462+
self.assertEqual(cm.exception.partial, data)
461463
self.assertIsNone(cm.exception.expected)
462464
self.assertEqual(b'', stream._buffer)
463465

Lines changed: 2 additions & 0 deletions
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)