8000 Explicitly document the methods · python/cpython@4d50c2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d50c2e

Browse files
committed
Explicitly document the methods
Small improvements to the docstrings and signature
1 parent 5d632a3 commit 4d50c2e

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

Doc/library/typing.rst

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,8 +2821,21 @@ decorated with :func:`@runtime_checkable <runtime_checkable>`.
28212821

28222822
.. class:: Reader[T]
28232823

2824-
Protocol for reading from a file or other input stream. Implementations
2825-
must support the ``read``, ``readline``, and ``__iter__`` methods.
2824+
Protocol for reading from a file or other input stream.
2825+
2826+
.. method:: read(size=...)
2827+
2828+
Read data from the input stream and return it. If ``size`` is
2829+
specified, at most ``size`` items (bytes/characters) will be read.
2830+
2831+
.. method:: readline(size=...)
2832+
2833+
Read a line of data from the input stream and return it. If ``size`` is
2834+
specified, at most ``size`` items (bytes/characters) will be read.
2835+
2836+
.. method:: __iter__()
2837+
2838+
Read a line of data from the input stream and return it.
28262839

28272840
For example::
28282841

@@ -2833,8 +2846,12 @@ decorated with :func:`@runtime_checkable <runtime_checkable>`.
28332846

28342847
.. class:: Writer[T]
28352848

2836-
Protocol for writing to a file or other output stream. Implementations
2837-
must support the ``write`` method.
2849+
Protocol for writing to a file or other output stream.
2850+
2851+
.. method:: write(data)
2852+
2853+
Write data to the output stream and return number of items
2854+
(bytes/characters) written.
28382855

28392856
For example::
28402857

Lib/typing.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,13 +2937,14 @@ class Reader[T](Iterable[T], Protocol):
29372937
__slots__ = ()
29382938

29392939
def read(self, size: int = ..., /) -> T:
2940-
"""Read data from the I/O stream and return it.
2940+
"""Read data from the input stream and return it.
29412941
29422942
If "size" is specified, at most "size" items (bytes/characters) will be
29432943
read.
29442944
"""
2945+
29452946
def readline(self, size: int = ..., /) -> T:
2946-
"""Read a line of data from the I/O stream and return it.
2947+
"""Read a line of data from the input stream and return it.
29472948
29482949
If "size" is specified, at most "size" items (bytes/characters) will be
29492950
read.
@@ -2959,8 +2960,8 @@ class Writer[T](Protocol):
29592960

29602961
__slots__ = ()
29612962

2962-
def write(self, o: T, /) -> int:
2963-
"""Write data to the I/O stream and return number of items written."""
2963+
def write(self, data: T, /) -> int:
2964+
"""Write data to the output stream and return number of items written."""
29642965

29652966

29662967
def _make_nmtuple(name, fields, annotate_func, module, defaults = ()):

0 commit comments

Comments
 (0)
0