From 3568f2ab4b3f5dd792ab90797b77e724a1f2a708 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sat, 4 Oct 2025 20:18:02 +0530 Subject: [PATCH 1/3] further clarify docs --- Doc/library/asyncio-stream.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst index e1568ae330b70f..05445219510ca5 100644 --- a/Doc/library/asyncio-stream.rst +++ b/Doc/library/asyncio-stream.rst @@ -316,13 +316,14 @@ StreamWriter If that fails, the data is queued in an internal write buffer until it can be sent. + The *data* buffer should be a bytes, bytearray, or C-contiguous one-dimensional + memoryview object. + The method should be used along with the ``drain()`` method:: stream.write(data) await stream.drain() - .. note:: - The *data* buffer should be a C contiguous one-dimensional :term:`bytes-like object `. .. method:: writelines(data) From cac6d40c5ed7c1ec468c904ee946b88e51cb8079 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sat, 4 Oct 2025 20:39:34 +0530 Subject: [PATCH 2/3] improve err msg --- Lib/asyncio/selector_events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index a7e27ccf0aa856..23f9196b48b3bc 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -1050,7 +1050,7 @@ def _read_ready__on_eof(self): def write(self, data): if not isinstance(data, (bytes, bytearray, memoryview)): - raise TypeError(f'data argument must be a bytes-like object, ' + raise TypeError(f'data argument must be a bytes, bytearray, or memoryview ' f'not {type(data).__name__!r}') if self._eof: raise RuntimeError('Cannot call write() after write_eof()') From f7b243357130a298d4f861f0f323df6f16b89367 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sat, 4 Oct 2025 20:44:32 +0530 Subject: [PATCH 3/3] Update Lib/asyncio/selector_events.py Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Lib/asyncio/selector_events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 23f9196b48b3bc..ff7e16df3c6273 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -1051,7 +1051,7 @@ def _read_ready__on_eof(self): def write(self, data): if not isinstance(data, (bytes, bytearray, memoryview)): raise TypeError(f'data argument must be a bytes, bytearray, or memoryview ' - f'not {type(data).__name__!r}') + f'object, not {type(data).__name__!r}') if self._eof: raise RuntimeError('Cannot call write() after write_eof()') if self._empty_waiter is not None: