Skip to content

Commit bc8134b

Browse files
committed
Document BufferedReader.peek and BytesIO.peek similarly
1 parent d9528e2 commit bc8134b

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Doc/library/io.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,10 @@ than raw I/O does.
742742
.. method:: peek(size=1, /)
743743

744744
Return bytes from the current position onwards without advancing the position.
745+
At least one byte of data is returned if not at EOF.
746+
Return an empty :class:`bytes` object at EOF.
745747
If the size argument is less than one or larger than the number of available bytes,
746748
a copy of the buffer from the current position until the end is returned.
747-
Return an empty bytes object at EOF.
748749

749750
.. versionadded:: 3.15
750751

@@ -780,8 +781,12 @@ than raw I/O does.
780781

781782
.. method:: peek(size=0, /)
782783

783-
Return bytes from the stream without advancing the position. The number of
784-
bytes returned may be less or more than requested. If the underlying raw
784+
Return bytes from the current position onwards without advancing the position.
785+
At least one byte of data is returned if not at EOF.
786+
Return an empty :class:`bytes` object at EOF.
787+
At most one single read on the underlying raw stream is done to satisfy the call.
788+
The exact number of bytes returned is unspecified
789+
(*size* is ignored). If the underlying raw
785790
stream is non-blocking and the operation would block, returns empty bytes.
786791

787792
.. method:: read(size=-1, /)

0 commit comments

Comments
 (0)