bpo-34215: Clarify IncompleteReadError message when "expected" is Non… · python/cpython@8085f74 (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -34,8 +34,9 @@ class IncompleteReadError(EOFError):
34 34 - expected: total number of expected bytes (or None if unknown)
35 35 """
36 36 def __init__(self, partial, expected):
37 +r_expected = 'undefined' if expected is None else repr(expected)
37 38 super().__init__(f'{len(partial)} bytes read on a total of '
38 -f'{expected!r} expected bytes')
39 +f'{r_expected} expected bytes')
39 40 self.partial = partial
40 41 self.expected = expected
41 42
Original file line number Diff line number Diff line change
@@ -444,12 +444,14 @@ def test_readuntil_multi_chunks_1(self):
444 444
445 445 def test_readuntil_eof(self):
446 446 stream = asyncio.StreamReader(loop=self.loop)
447 -stream.feed_data(b'some dataAA')
447 +data = b'some dataAA'
448 +stream.feed_data(data)
448 449 stream.feed_eof()
449 450
450 -with self.assertRaises(asyncio.IncompleteReadError) as cm:
451 +with self.assertRaisesRegex(asyncio.IncompleteReadError,
452 +'undefined expected bytes') as cm:
451 453 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)
453 455 self.assertIsNone(cm.exception.expected)
454 456 self.assertEqual(b'', stream._buffer)
455 457
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 +Clarify the error message for :exc:`asyncio.IncompleteReadError` when
2 +``expected`` is ``None``.