Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b833b83
Implement BytesIO.peek()
marcelm Jan 22, 2022
50a2cfb
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 10, 2022
eaa7672
Document BytesIO.peek()
marcelm Nov 9, 2022
00457ae
Implement with the help of read_bytes()
marcelm Nov 9, 2022
882579d
Add to What’s New
marcelm Jul 8, 2023
c1eed72
versionadded: 3.12 -> 3.13
marcelm Jul 8, 2023
afc200c
Remove unused variable
marcelm Jul 8, 2023
79ab9a4
Test tell() after peek()
marcelm Sep 22, 2023
b493914
Update docs, factor out peek_bytes, semantics
marcelm Sep 22, 2023
2a1c85c
Update Misc/NEWS.d/next/Library/2022-04-10-20-10-59.bpo-46375.8j1ogZ.rst
marcelm Sep 28, 2023
d398717
Update Modules/_io/bytesio.c
marcelm Sep 28, 2023
26d1e81
Update Modules/_io/bytesio.c
marcelm Sep 28, 2023
9a19ff9
Use SemBr
marcelm Sep 28, 2023
9300ade
Update Doc/whatsnew/3.13.rst
marcelm Sep 28, 2023
d214089
Apply suggestions from code review
marcelm Sep 28, 2023
d6691b8
Use a context manager around memio in test_peek
marcelm Sep 28, 2023
3e51adb
Add more tests for tell() after peek()
marcelm Sep 28, 2023
3661b65
Document why size < 0 can happen
marcelm Sep 28, 2023
cd40d77
Update Modules/_io/bytesio.c
marcelm Sep 29, 2023
04372bd
Do not update pos if peek_bytes failed
marcelm Sep 29, 2023
6b9ae8c
Size can be negative after truncate or seek
marcelm Sep 29, 2023
f7406f6
Test with size<0 and size>len(buf)
marcelm Sep 29, 2023
d9528e2
Test peek() after write()
marcelm Sep 29, 2023
bc8134b
Document BufferedReader.peek and BytesIO.peek similarly
marcelm Sep 29, 2023
b6ffca8
Comment
marcelm Sep 29, 2023
5fe5645
Make it more explicit that size is ignored
marcelm Sep 29, 2023
4126a64
Return an empty bytes object for size=0
marcelm Oct 23, 2023
1ea40c2
Simplify
marcelm Oct 23, 2023
77e04d6
Test peek(3) and peek(5)
marcelm Oct 23, 2023
4d2f2dd
Run clinic.py
marcelm Apr 10, 2026
c16bebf
Apply suggestions from code review
marcelm Apr 13, 2026
08bd7da
Do not return an empty bytes object for size=0
marcelm Apr 11, 2026
6174fca
Decorate BytesIO.peek with `@critical_section`
marcelm Apr 15, 2026
b8b8cf4
Test peek returns EOF after seeking to EOF
marcelm Apr 21, 2026
7ac914e
Free-threading test for peek
marcelm Apr 21, 2026
abbd8f0
Fix free-threading test
marcelm Apr 27, 2026
07d9e4d
Default to size=0; cap to DEFAULT_BUFFER_SIZE
marcelm Apr 29, 2026
3d57f45
Revert changes to BufferedReader.peek documentation
marcelm Apr 30, 2026
023ad25
Test peek after seek or truncate
marcelm May 1, 2026
203749b
Merge branch 'main' into fix-issue-46375
emmatyping May 1, 2026
32fd791
Do not cap at DEFAULT_BUFFER_SIZE
marcelm Jun 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
versionadded: 3.12 -> 3.13
  • Loading branch information
marcelm committed Apr 10, 2026
commit c1eed72ef5ebbe6e157e78491fc778f1681193fe
2 changes: 1 addition & 1 deletion Doc/library/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ than raw I/O does.

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

.. versionadded:: 3.12
.. versionadded:: 3.13

Return bytes from the current position onwards but without advancing the
position. The number of bytes returned may be less or more than requested.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait. Why can it more than requested?

Apparently size=0 means "read all". Please document it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just copied from the documentation for BufferedReader.peek(), but I agree that it could be written better. Changed now.

Wait. Why can it more than requested?

BufferedReader.peek() ignores the size argument and just returns whatever it has in its internal buffer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that BytesIO.peek() documents its behavior, rather than BufferedReader.peek() behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, it’s already changed.

(BTW, is there a policy on who clicks the "Resolve conversation" button?)

Expand Down