python / python/mypy

Error deriving from a composite of two incompatible base classes

Open
#10,066 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Simple repro:

class B1:
    def foo(self) -> int:
        ...

class B2:
    def foo(self) -> str:
        ...

class Composite(B1, B2):  # type: ignore
    ...

class AppClass1(Composite):  # <-- no error here
    ...

class AppClass2(Composite, object):  # <-- error here!
    ...

In the real world case, classes B1, B2 and Composite are part of a library (PEP-561-compliant), and classes AppClass1 and AppClass2 are part of the application code that's being type-checked.

The surprising part is that while AppClass2's declaration causes an error (even though AppClass2 didn't introduce the incompatibility), this error isn't seen in AppClass1's declaration.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal reproduction in the issue and compare diagnostics for AppClass1 and AppClass2. Trace how mypy handles inheritance from Composite and the incompatible foo definitions in B1 and B2; done means the behavior is consistently understood and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.