gh-90533: Implement BytesIO.peek() by marcelm · Pull Request #150917 · python/cpython · GitHub

github.com

Tin mới

marcelm:fix-issue-46375

GitHub CopilotWrite better code with AI

GitHub Copilot appDirect agents from issue to merge

ActionsAutomate any workflow

CodespacesInstant dev environments

IssuesPlan and track work

Code ReviewManage code changes

Code QualityEnforce quality at merge

GitHub Advanced SecurityFind and fix vulnerabilities

Code securitySecure your code as you build

Secret protectionStop leaks before they start

View all use cases

Financial services

View all industries

Software Development

GitHub SponsorsFund open source developers

Copilot for BusinessEnterprise-grade AI features

Premium SupportEnterprise-grade 24/7 support

Pull requests 2.6k

Security and quality 0

io.BytesIO does not have peek() #90533

Implement BytesIO.peek()

📜🤖 Added by blurb_it.

Document BytesIO.peek()

Implement with the help of read_bytes()

versionadded: 3.12 -> 3.13

Remove unused variable

Test tell() after peek()

Update docs, factor out peek_bytes, semantics

Update Misc/NEWS.d/next/Library/2022-04-10-20-10-59.

Update Modules/_io/bytesio.c

Update Modules/_io/bytesio.c

Use SemBr Co-authored-by: Erlend E. Aasland <[email protected]>

Update Doc/whatsnew/3.13.rst

Apply suggestions from code review

Use a context manager around memio in test_peek

Add more tests for tell() after peek()

Document why size < 0 can happen

Update Modules/_io/bytesio.c

Do not update pos if peek_bytes failed

Size can be negative after truncate or seek

Test with size<0 and size>len(buf)

Test peek() after write()

Document BufferedReader.peek and BytesIO.peek similarly

Make it more explicit that size is ignored

Return an empty bytes object for size=0

Test peek(3) and peek(5)

View reviewed changes

Learn more about hiding disruptive comments

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

Clarify what peek(0) does