From ae53f67076e9c82c6d69aa393e4b6061785475c9 Mon Sep 17 00:00:00 2001 From: An Long Date: Sat, 24 Oct 2026 22:28:55 +0900 Subject: [PATCH 1/3] Fix error message in proactor datagram sendto() --- Lib/asyncio/proactor_events.py | 4 ++-- Lib/test/test_asyncio/test_proactor_events.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index 8350e027604688..46da66f7c4d422 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -489,8 +489,8 @@ def _force_close(self, exc): def sendto(self, data, addr=None): if not isinstance(data, (bytes, bytearray, memoryview)): - raise TypeError('data argument must be bytes-like object (%r)', - type(data)) + raise TypeError(f'data argument must be a bytes-like object, ' + f'not {type(data).__name__!r}') if self._address is not None and addr not in (None, self._address): raise ValueError( diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py index 2f229887ad62cc..d25c5fa47d1dc1 100644 --- a/Lib/test/test_asyncio/test_proactor_events.py +++ b/Lib/test/test_asyncio/test_proactor_events.py @@ -691,7 +691,9 @@ def test_sendto_error_received_connected(self): def test_sendto_str(self): transport = self.datagram_transport() - self.assertRaises(TypeError, transport.sendto, 'str', ()) + self.assertRaisesRegex( + TypeError, "^data argument must be a bytes-like object, not 'str'$", + transport.sendto, 'str', ()) def test_sendto_connected_addr(self): transport = self.datagram_transport(address=('0.0.0.0', 1)) From df3096c2f8fdb1e24eede32ab4f982050ffe4731 Mon Sep 17 00:00:00 2001 From: An Long Date: Sat, 24 Oct 2026 22:32:38 +0900 Subject: [PATCH 2/3] Add news entry --- .../next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst diff --git a/Misc/NEWS.d/next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst b/Misc/NEWS.d/next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst new file mode 100644 index 00000000000000..3da92a82a417f5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst @@ -0,0 +1,2 @@ +Fix the error message for invalid data passed to +:meth:`asyncio.proactor_events.sendto`. From e81835668a7618d85a201c96e0eeac41c456a1f3 Mon Sep 17 00:00:00 2001 From: An Long Date: Sat, 24 Oct 2026 22:38:21 +0900 Subject: [PATCH 3/3] Fix news entry --- .../next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst b/Misc/NEWS.d/next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst index 3da92a82a417f5..c1db616f01d17a 100644 --- a/Misc/NEWS.d/next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst +++ b/Misc/NEWS.d/next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst @@ -1,2 +1,2 @@ Fix the error message for invalid data passed to -:meth:`asyncio.proactor_events.sendto`. +:meth:`!asyncio.proactor_events.sendto`.