summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-11-28 14:44:34 (GMT)
committerGitHub <noreply@github.com>2020-11-28 14:44:34 (GMT)
commit4498e98a6bdf017d3b65fa679baf4c797909beb6 (patch)
tree76f446ded56a774ce79e1e36ee202f211c58df8f
parent01fcde89d7d56321078be1739e759fece61d0a2b (diff)
downloadcpython-4498e98a6bdf017d3b65fa679baf4c797909beb6.zip
cpython-4498e98a6bdf017d3b65fa679baf4c797909beb6.tar.gz
cpython-4498e98a6bdf017d3b65fa679baf4c797909beb6.tar.bz2
bpo-34215: Clarify IncompleteReadError message when "expected" is None (GH-21925) (#23540)
Co-Authored-By: Tyler Bell <mrbell321@gmail.com> (cherry picked from commit 8085f742f4adfbc85f13fc734dfab036aa23acfb) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
-rw-r--r--Lib/asyncio/exceptions.py3
-rw-r--r--Lib/test/test_asyncio/test_streams.py8
-rw-r--r--Misc/NEWS.d/next/Library/2020-08-19-20-17-51.bpo-34215._Cv8c-.rst2
3 files changed, 9 insertions, 4 deletions
diff --git a/Lib/asyncio/exceptions.py b/Lib/asyncio/exceptions.py
index e03602e..f07e448 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 12bd536..84c031c 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 0000000..4d91678
--- /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``.