https://github.com/python/cpython/commit/2d55ec48a29acdc8b7612bb2624e199bbeb7f52b
commit: 2d55ec48a29acdc8b7612bb2624e199bbeb7f52b
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2026-10-27T10:49:41+02:00
summary:

[3.14] gh-160596: Fix error message in asyncio.proactor_events.sendto() 
(GH-160597) (#160603)

Co-authored-by: An Long <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-10-24-22-32-23.gh-issue-160596.RKll-Z.rst
M Lib/asyncio/proactor_events.py
M Lib/test/test_asyncio/test_proactor_events.py

diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index 59dda68e2daf4a4..0366bd7ba65fb0e 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 edfad5e11db35e4..2e9e0828f405628 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))
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 000000000000000..c1db616f01d17a4
--- /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`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to