]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] 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:40:21 +0000 (18:40 +0200)
committerGitHub <noreply@github.com>
Sat, 4 Oct 2025 16:40:21 +0000 (16:40 +0000)
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 6ad84044adf1463152307288713552b4e792f8b6..f8744cbb2230035b1e19294905b139f29bfbdef3 100644 (file)
@@ -1050,8 +1050,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: