Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

"typing.BinaryIO" missing "readinto" method #133492

Open
Labels
stdlibPython modules in the Lib dirtopic-typingtype-bugAn unexpected behavior, bug, or error
@DRayX

Description

@DRayX

Bug report

Bug description:

typeing.BinaryIO is completely missing thereadinto method. All binary mode return values ofopen support thereadinto method, and the lack of it on theBinaryIO type makes type-hinting difficult when using this method. One could try to useio.RawIOBase | io.BufferedIOBase but this looses the fact that the result ofopen has aname property. This has been brought up inpython/typing#659 andpython/typeshed#2166.

Furthmore, thewrite method inBinaryIO is declared to only be compatible withUnion[bytes, bytearray] when it should be anything that satisfiescollections.abc.Buffer.

I propose that BinaryIO should look something more like:

classBinaryIO(IO[bytes]):"""Typed version of the return of open() in binary mode."""__slots__= ()@abstractmethoddefreadinto(self,b:collections.abc.Buffer)->int:pass@abstractmethoddefwrite(self,s:collections.abc.Buffer)->int:pass@abstractmethoddef__enter__(self)->'BinaryIO':pass

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp