Skip to content

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

Closed

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

Activity

  1. JelleZijlstra commented on May 28, 2020

    @JelleZijlstra
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions