python / python/mypy

Better message if override violates Liskov substitution principle

Open
#7,994 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation good-first-issue priority-1-normal topic-usability
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Some users don't understand why mypy complains about incompatible overrides. We could add an extra note in cases where the argument type is narrower in an override or the return type is wider (or all incompatible overrides). The note could mention Liskov substitution principle and add a link to mypy documentation (add a new section to https://mypy.readthedocs.io/en/latest/common_issues.html perhaps). We can also mention that # type: ignore[override] can be used to silence this error.

#7992 is an example where this came up, but several users have been confused about this.

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 locating mypy's incompatible-override diagnostic handling and review the common issues documentation linked in the issue. Check issue #7992 for the motivating example. Done means the relevant override cases explain the Liskov substitution principle, link to the documentation, and mention the override type-ignore option, with tests covering the message.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.