From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sat, 4 Oct 2025 16:42:03 +0000 (+0200) Subject: [3.13] gh-138703: clarify data buffer requirement of `asyncio.StreamWriter.write... X-Git-Tag: v3.13.8~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=be388836c0d4a970e83ca5540c512d94afd13435;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-138703: clarify data buffer requirement of `asyncio.StreamWriter.write` (GH-139564) (#139571) gh-138703: clarify data buffer requirement of `asyncio.StreamWriter.write` (GH-139564) (cherry picked from commit 0b2168275e8ec491fe7ea6f8c662e804437dfdab) Co-authored-by: Kumar Aditya --- diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst index e1568ae330b7..05445219510c 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) diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 26bd56ef2803..df5b1e49240f 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -1046,8 +1046,8 @@ class _SelectorSocketTransport(_SelectorTransport): def write(self, data): if not isinstance(data, (bytes, bytearray, memoryview)): - raise TypeError(f'data argument must be a bytes-like object, ' - f'not {type(data).__name__!r}') + raise TypeError(f'data argument must be a bytes, bytearray, or memoryview ' + 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: