This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: io.BytesIO does not have peek()
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.11
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, kumaraditya, marcelm, stutzbach
Priority: normal Keywords: patch

Created on 2022-01-14 10:39 by marcelm, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 30808 open marcelm, 2022-01-22 22:08
Messages (2)
msg410552 - (view) Author: Marcel Martin (marcelm) * Date: 2022-01-14 10:39
It would be great to be able to use peek() on BytesIO objects.

I have a function that gets passed a file-like object and uses peek() on it. This works for nearly all types of files relevant in my library, except BytesIO instances (which I use during testing), for which I need to add a small workaround using tell() and seek().
msg411294 - (view) Author: Marcel Martin (marcelm) * Date: 2022-01-22 22:08
I opened a PR, but I now wonder whether the missing peek() is by design.

First, I noticed that instead of using BytesIO directly, I can wrap the instance in an io.BufferedReader, which does have peek(). (It’s just a bit inconvenient.)

The second thing is that BytesIO is currently documented to inherit from BufferedIOBase, but if peek() is implemented, one could argue that BytesIO now should inherit from BufferedReader because it then has all the methods. And that seems to great a change from my perspective.

I’ll defer to someone more knowledgeable and do not mind at all if this issue is closed without action.
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90533
2022-01-22 22:08:29marcelmsetmessages: + msg411294
2022-01-22 22:08:26marcelmsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28996
2022-01-14 10:52:39kumaradityasetnosy: + benjamin.peterson, stutzbach, kumaraditya
2022-01-14 10:39:24marcelmcreate