Skip to content

io.RawIOBase and typing.IO signatures differ #108411

@kosta

Description

@kosta

Bug report

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

3.11, CPython main branch

Operating systems tested on:

Linux, macOS, Windows

Output from running 'python -VV' on the command line:

Python 3.11.4 (main, Jun 20 2023, 17:23:00) [Clang 14.0.3 (clang-1403.0.22.14.1)]

A clear and concise description of the bug:

The method parameters in python are part of the public interface, due to kwargs.

From typing.IO: undocumented / source

    def read(self, n: int = -1) -> AnyStr:
        pass

From io.RawIOBase: docs / source

    def read(self, size=-1):
        ...

If I implement both IO[bytes] and RawIOBase, should name the variable n or size?

Additionally, RawIOBase.read checks for null, so should the type hint be Optional[int]?

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions