[3.14] gh-138703: clarify data buffer requirement of asyncio.StreamWriter.write (GH-139564) (#139570)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
Miss Islington (bot) 2025-10-04 18:40:21 +02:00 committed by GitHub
parent 6f2635787b
commit 8566ee2507
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View file

@ -316,13 +316,14 @@ StreamWriter
If that fails, the data is queued in an internal write buffer until it can be If that fails, the data is queued in an internal write buffer until it can be
sent. 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:: The method should be used along with the ``drain()`` method::
stream.write(data) stream.write(data)
await stream.drain() await stream.drain()
.. note::
The *data* buffer should be a C contiguous one-dimensional :term:`bytes-like object <bytes-like object>`.
.. method:: writelines(data) .. method:: writelines(data)

View file

@ -1050,8 +1050,8 @@ def _read_ready__on_eof(self):
def write(self, data): def write(self, data):
if not isinstance(data, (bytes, bytearray, memoryview)): 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}') f'object, not {type(data).__name__!r}')
if self._eof: if self._eof:
raise RuntimeError('Cannot call write() after write_eof()') raise RuntimeError('Cannot call write() after write_eof()')
if self._empty_waiter is not None: if self._empty_waiter is not None: