FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-138703: clarify data buffer requirement of `asyncio.StreamWriter.write` by kumaraditya303 · Pull Request #139564 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 3 additions & 2 deletions Doc/library/asyncio-stream.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
kumaraditya303 marked this conversation as resolved.
memoryview object.
Comment thread
kumaraditya303 marked this conversation as resolved.

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)

Expand Down
4 changes: 2 additions & 2 deletions Lib/asyncio/selector_events.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,8 @@ def _read_ready__on_eof(self):

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:
Expand Down
Loading

Back | FazBrowse Home | New Git URL