Skip to content

BinaryIO does not have peek method #3951

@vegarsti

Description

@vegarsti

When opening a file with binary mode, typing.BinaryIO is inferred.
This type should have the https://docs.python.org/3/library/io.html#io.BufferedReader.peek method.
It looks like this is known, judging by the TODO on this line in the typing.pyi stub:

# TODO peek?

(There are also other TODOs there for BinaryIO - if those should be added, I could of course do those in the same change if that's not a problem.)

A reproducible example:

with open("some-file", 'rb') as f:
    f.peek()

Running mypy on this results in error: "BinaryIO" has no attribute "peek".

This issue has also been reported earlier in mypy.

I'd be glad to submit a PR for this. Is it as simple as adding peek to BinaryIO in typing.pyi? Or should there also be tests for these changes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: ioI/O related issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions