Skip to content

Show more context about the base class on incompatible override #19112

Closed
@JukkaL

Description

@JukkaL
Collaborator

Feature

When an override is incompatible with the base class, mypy only shows the short name of the base class (e.g. MyClass). Change that to show the full name (e.g. pkg.mod.MyClass) when the base class is defined in a different module.

Example where this would make a difference:

# a.py
class A:
    def f(self, x: int) -> None:
        ...
    def g(self) -> None:
        ...
# b.py
from a import A

class B(A):
    def f(self, x: str) -> None:
        ...
    def g(self, x: str) -> None:
        ...

This is the current output:

b.py:4: error: Argument 1 of "f" is incompatible with supertype "A"; supertype defines the argument type as "int"  [override]
b.py:4: note: This violates the Liskov substitution principle
b.py:4: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
b.py:6: error: Signature of "g" incompatible with supertype "A"  [override]
b.py:6: note:      Superclass:
b.py:6: note:          def g(self) -> None
b.py:6: note:      Subclass:
b.py:6: note:          def g(self, x: str) -> None

The desired output would be ... with supertype "a.A" ... instead of ... with supertype "A" ....

Pitch

There can be a complex class hierarchy, and different base classes in the MRO can be in different modules. Currently finding the base class of the method is inconvenient, especially for somebody not using an IDE that allows them to quickly look it up. Also, it's not uncommon to have multiple classes with the same short name, so the current message is ambiguous.

Activity

east825

east825 commented on May 19, 2025

@east825
Contributor

I'm going to look at this at PyCon US 2025 sprints.

added 3 commits that reference this issue on May 19, 2025
7939672
561a8ce
eafbd3f
added a commit that references this issue on Jun 6, 2025
325f776
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

      Participants

      @east825@JukkaL

      Issue actions

        Show more context about the base class on incompatible override · Issue #19112 · python/mypy