Skip to content

How to correctly override BinaryIO.write? #5275

Answered by erictraut
rpmrmartin asked this question in Q&A
Discussion options

You must be logged in to vote

There is a bug in the logic for overloaded overrides, which I added recently. I'll fix this in the next release.

That said, to avoid the reportIncompatibleMethodOverride error, you'll need to copy the overload signatures from typeshed exactly. That includes the use of a positional-only parameter __s rather than a named parameter s. It also includes type annotations for the self parameter on the first two overloads.

class Decorator(BinaryIO):
    def __init__(self, file: BinaryIO) -> None:
        self._file = file

    @overload
    def write(self: IO[str], s: str, /) -> int:
        ...

    @overload
    def write(self: IO[bytes], s: ReadableBuffer, /) -> int:
        ...

    @overload

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rpmrmartin
Comment options

@erictraut
Comment options

@rpmrmartin
Comment options

Answer selected by rpmrmartin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants