Skip to content

Return type "str" of "readline" incompatible with return type "bytes" in supertype "IOBase" [override] #9643

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

Open
blueyed opened this issue Oct 26, 2020 · 1 comment
Labels
bug mypy got something wrong

Comments

@blueyed
Copy link
Contributor

blueyed commented Oct 26, 2020

Since python/typeshed#4145 (released with mypy 0.790) mypy fails with:

import io

class MyStringIO(io.StringIO):
    def readline(self, size=None) -> str:
        return super().readline(size)

Return type "str" of "readline" incompatible with return type "bytes" in supertype "IOBase" [override]

According to python/typeshed#4145 (comment) this is likely a bug in mypy.

(mypy 0.800+dev.f220ce50725ed7f117832b9f03aed4d1a9508e00 (current master))

@blueyed blueyed added the bug mypy got something wrong label Oct 26, 2020
blueyed added a commit to blueyed/pytest that referenced this issue Oct 26, 2020
@blueyed blueyed changed the title IOBase: Return type "str" of "readline" incompatible with return type "bytes" in supertype "IOBase" [override] Return type "str" of "readline" incompatible with return type "bytes" in supertype "IOBase" [override] Oct 26, 2020
blueyed added a commit to blueyed/pytest that referenced this issue Oct 26, 2020
* Update mypy 0.782 -> 0.790

* pytester: ignore type with EchoingInput.readline

Ref: python/mypy#9643

* tox: mypy_ci: --warn-unused-ignores

* Remove unused type-ignore comments
@srittau
Copy link
Contributor

srittau commented Jul 25, 2024

Currently, mypy only stops checking for LSP violations in the class hierarchy once it encounters a super class with a violation. Instead, it should stop after first encountering the method while walking up the inheritance tree, no matter whether that is a violation or not.

Here is an example not using typeshed:

class Base:
    def foo(self, x: int) -> None:
        pass


class Sub1(Base):
    def foo(self, x: str) -> None:  # type: ignore[override]
        pass


class Sub2(Sub1):
    def foo(self, x: str) -> None:  # Argument 1 of "foo" is incompatible with supertype "Base"; supertype defines the argument type as "int"  [override]
        pass

Sub2.foo should only be checked against Sub1.foo, not Base.foo as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants