Skip to content

Spurious "incompatible with supertype" error with double inheritance from a generic #5027

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

Closed
JelleZijlstra opened this issue May 13, 2018 · 1 comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-type-variables

Comments

@JelleZijlstra
Copy link
Member

The following file:

from typing import TypeVar, Generic

T = TypeVar('T')

class A(Generic[T]):
    def x(self) -> T: ...

class B:
    def x(self) -> bytes: ...

class C(B, A[bytes]): ...

produces

$ mypy samples/doubleinh.py 
samples/doubleinh.py:11: error: Definition of "x" in base class "B" is incompatible with definition in base class "A"

with mypy 0.600 and python 3.7.0b4.

This should be accepted because the class inherits from A[bytes], which means that its x method should indeed return bytes. This is only a problem with double inheritance: if I make B inherit from A[bytes], mypy shows no error for B.

My use case was that I wanted to make a typeshed class inherit from both io.BufferedIOBase (to reflect the implementation) and IO[bytes] (to make it compatible with type hints that accept IO[bytes]).

@ilevkivskyi ilevkivskyi added bug mypy got something wrong topic-type-variables priority-1-normal false-positive mypy gave an error on correct code labels May 14, 2018
JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue Jun 12, 2018
Fixes python#2189

The errors from mypy are a false positive (see python/mypy#5027).
gvanrossum pushed a commit to python/typeshed that referenced this issue Jun 12, 2018
Fixes #2189.

The errors from mypy are a false positive (see python/mypy#5027).
JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue Jun 17, 2018
Matches the implementation in https://github.com/python/cpython/blob/3.4/Lib/http/client.py#L308

The ignore works around python/mypy#5027 (commented further up in the 3.5 branch).

Part of python#1476.
ilevkivskyi pushed a commit to python/typeshed that referenced this issue Jun 17, 2018
Matches the implementation in https://github.com/python/cpython/blob/3.4/Lib/http/client.py#L308

The ignore works around python/mypy#5027 (commented further up in the 3.5 branch).

Part of #1476.
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this issue Jan 23, 2019
Fixes python#2189.

The errors from mypy are a false positive (see python/mypy#5027).
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this issue Jan 23, 2019
Matches the implementation in https://github.com/python/cpython/blob/3.4/Lib/http/client.py#L308

The ignore works around python/mypy#5027 (commented further up in the 3.5 branch).

Part of python#1476.
@JelleZijlstra
Copy link
Member Author

This got fixed somewhere; the sample in my post above now passes mypy. I'm going to close this and remove the related type ignores in typeshed.

JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue May 28, 2020
The mypy issue got fixed by the good people of mypy. I did have to add an
override for __enter__ similar to what we're doing in python#4082.
JelleZijlstra added a commit to python/typeshed that referenced this issue May 28, 2020
The mypy issue got fixed by the good people of mypy. I did have to add an
override for __enter__ similar to what we're doing in #4082.
vishalkuo pushed a commit to vishalkuo/typeshed that referenced this issue Jun 26, 2020
The mypy issue got fixed by the good people of mypy. I did have to add an
override for __enter__ similar to what we're doing in python#4082.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-type-variables
Projects
None yet
Development

No branches or pull requests

2 participants