Skip to content

Commit 1159836

Browse files
authored
gh-160596: Fix error message in asyncio.proactor_events.sendto() (#160597)
1 parent 00c5450 commit 1159836

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎Lib/asyncio/proactor_events.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ def _force_close(self, exc):
489489

490490
def sendto(self, data, addr=None):
491491
if not isinstance(data, (bytes, bytearray, memoryview)):
492-
raise TypeError('data argument must be bytes-like object (%r)',
493-
type(data))
492+
raise TypeError(f'data argument must be a bytes-like object, '
493+
f'not {type(data).__name__!r}')
494494

495495
if self._address is not None and addr not in (None, self._address):
496496
raise ValueError(

‎Lib/test/test_asyncio/test_proactor_events.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,9 @@ def test_sendto_error_received_connected(self):
691691

692692
def test_sendto_str(self):
693693
transport = self.datagram_transport()
694-
self.assertRaises(TypeError, transport.sendto, 'str', ())
694+
self.assertRaisesRegex(
695+
TypeError, "^data argument must be a bytes-like object, not 'str'$",
696+
transport.sendto, 'str', ())
695697

696698
def test_sendto_connected_addr(self):
697699
transport = self.datagram_transport(address=('0.0.0.0', 1))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the error message for invalid data passed to
2+
:meth:`!asyncio.proactor_events.sendto`.

0 commit comments

Comments
 (0)