Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.BytesIO does not have peek() #90533

Open
marcelm mannequin opened this issue Jan 14, 2022 · 2 comments · May be fixed by #30808
Open

io.BytesIO does not have peek() #90533

marcelm mannequin opened this issue Jan 14, 2022 · 2 comments · May be fixed by #30808
Labels
3.11 only security fixes stdlib Python modules in the Lib dir topic-IO type-feature A feature request or enhancement

Comments

@marcelm
Copy link
Mannequin

marcelm mannequin commented Jan 14, 2022

BPO 46375
Nosy @benjaminp, @marcelm, @kumaraditya303
PRs
  • gh-90533: Implement BytesIO.peek() #30808
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2022-01-14.10:39:24.835>
    labels = ['type-feature', 'library', '3.11']
    title = 'io.BytesIO does not have peek()'
    updated_at = <Date 2022-01-22.22:08:29.533>
    user = 'https://github.com/marcelm'

    bugs.python.org fields:

    activity = <Date 2022-01-22.22:08:29.533>
    actor = 'marcelm'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2022-01-14.10:39:24.835>
    creator = 'marcelm'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46375
    keywords = ['patch']
    message_count = 2.0
    messages = ['410552', '411294']
    nosy_count = 4.0
    nosy_names = ['benjamin.peterson', 'stutzbach', 'marcelm', 'kumaraditya']
    pr_nums = ['30808']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue46375'
    versions = ['Python 3.11']

    @marcelm
    Copy link
    Mannequin Author

    marcelm mannequin commented Jan 14, 2022

    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().

    @marcelm marcelm mannequin added 3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jan 14, 2022
    @marcelm
    Copy link
    Mannequin Author

    marcelm mannequin commented Jan 22, 2022

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @marcelm marcelm linked a pull request Apr 11, 2022 that will close this issue
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir topic-IO type-feature A feature request or enhancement
    Projects
    None yet
    Development

    Successfully merging a pull request may close this issue.

    1 participant