]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-138703: clarify data buffer requirement of `asyncio.StreamWriter.write...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 4 Oct 2025 16:42:03 +0000 (18:42 +0200)
committerGitHub <noreply@github.com>
Sat, 4 Oct 2025 16:42:03 +0000 (22:12 +0530)
gh-138703: clarify data buffer requirement of `asyncio.StreamWriter.write` (GH-139564)
(cherry picked from commit 0b2168275e8ec491fe7ea6f8c662e804437dfdab)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Doc/library/asyncio-stream.rst
Lib/asyncio/selector_events.py

index e1568ae330b70fa78b39bd0e53404b350fa07344..05445219510ca546e5f591d7d7877c38a3c69de2 100644 (file)
@@ -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 <bytes-like object>`.
 
    .. method:: writelines(data)
 
index 26bd56ef2803b8d3f6a8e2f2b0bfff8a622de0a6..df5b1e49240fe0867b8cd26a63386eb09b696f0d 100644 (file)
@@ -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: