From df6c8bcffef3380869c8f76317610ce452880b25 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sat, 28 Nov 2020 07:07:51 -0800 Subject: [PATCH] bpo-34215: Clarify IncompleteReadError message when "expected" is None (GH-21925) (GH-23539) Co-Authored-By: Tyler Bell (cherry picked from commit 8085f742f4adfbc85f13fc734dfab036aa23acfb) Co-authored-by: Zackery Spytz Co-authored-by: Zackery Spytz --- Lib/asyncio/exceptions.py | 3 ++- Lib/test/test_asyncio/test_streams.py | 8 +++++--- .../next/Library/2020-08-19-20-17-51.bpo-34215._Cv8c-.rst | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2020-08-19-20-17-51.bpo-34215._Cv8c-.rst diff --git a/Lib/asyncio/exceptions.py b/Lib/asyncio/exceptions.py index e03602ef576..f07e4486577 100644 --- a/Lib/asyncio/exceptions.py +++ b/Lib/asyncio/exceptions.py @@ -34,8 +34,9 @@ class IncompleteReadError(EOFError): - expected: total number of expected bytes (or None if unknown) """ def __init__(self, partial, expected): + r_expected = 'undefined' if expected is None else repr(expected) super().__init__(f'{len(partial)} bytes read on a total of ' - f'{expected!r} expected bytes') + f'{r_expected} expected bytes') self.partial = partial self.expected = expected diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index 1e9d115661d..71de82dfc7e 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -452,12 +452,14 @@ class StreamTests(test_utils.TestCase): def test_readuntil_eof(self): stream = asyncio.StreamReader(loop=self.loop) - stream.feed_data(b'some dataAA') + data = b'some dataAA' + stream.feed_data(data) stream.feed_eof() - with self.assertRaises(asyncio.IncompleteReadError) as cm: + with self.assertRaisesRegex(asyncio.IncompleteReadError, + 'undefined expected bytes') as cm: self.loop.run_until_complete(stream.readuntil(b'AAA')) - self.assertEqual(cm.exception.partial, b'some dataAA') + self.assertEqual(cm.exception.partial, data) self.assertIsNone(cm.exception.expected) self.assertEqual(b'', stream._buffer) diff --git a/Misc/NEWS.d/next/Library/2020-08-19-20-17-51.bpo-34215._Cv8c-.rst b/Misc/NEWS.d/next/Library/2020-08-19-20-17-51.bpo-34215._Cv8c-.rst new file mode 100644 index 00000000000..4d91678948f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-08-19-20-17-51.bpo-34215._Cv8c-.rst @@ -0,0 +1,2 @@ +Clarify the error message for :exc:`asyncio.IncompleteReadError` when +``expected`` is ``None``.