Skip to content

gh-90533: Implement BytesIO.peek()#150917

Open
marcelm wants to merge 46 commits into
python:mainfrom
marcelm:fix-issue-46375
Open

gh-90533: Implement BytesIO.peek()#150917
marcelm wants to merge 46 commits into
python:mainfrom
marcelm:fix-issue-46375

Conversation

@marcelm

@marcelm marcelm commented Jun 4, 2026

Copy link
Copy Markdown

marcelm and others added 30 commits April 10, 2026 20:37
This allows peek() to use the same optimization that read_bytes() has of
returning a reference to the buffer when possible (without copying).
Semantic change: The default argument for peek is now size=1.
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@read-the-docs-community

read-the-docs-community Bot commented Jun 4, 2026

Copy link
Copy Markdown

Comment thread Doc/library/io.rst Outdated
Co-authored-by: Stan Ulbrych <stan@python.org>
@cmaloney

cmaloney commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Looks like make clinic needs to be re-run and committed (lots of things can cause that)

@cmaloney

cmaloney commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

The "Windows (free threading)" failure looks like a flaky on main test: test.test_logging.TimedRotatingFileHandlerTest.test_rollover_based_on_st_birthtime_only also failed on macOS (free-threading)

@vstinner

vstinner commented Jun 5, 2026

Copy link
Copy Markdown
Member

The "Windows (free threading)" failure looks like a flaky on main test: test.test_logging.TimedRotatingFileHandlerTest.test_rollover_based_on_st_birthtime_only also failed on macOS (free-threading)

I created issue gh-150960 to track the test_logging failure.

@cmaloney

cmaloney commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

CI all green! :)

Comment thread Doc/library/io.rst
.. method:: peek(size=0, /)

Return bytes from the current position onwards without advancing the position.
At least one byte of data is returned if not at EOF.

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.

The size=0 case is not well documented. It's unclear to me when I read the doc if peek() or peek(0) return an empty string or something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

io.BytesIO does not have peek()

5 participants