Skip to content

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

@JelleZijlstra

Description

@JelleZijlstra

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]).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions