gh-138703: clarify data buffer requirement of asyncio.StreamWriter.write (#139564)

This commit is contained in:
Kumar Aditya
2025-10-04 21:44:05 +05:30
committed by GitHub
parent 04a2f80a60
commit 0b2168275e
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
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)

View 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: