Skip to content

Display FQN for imported base classes in errors about incompatible ov… #19115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,7 @@ def check_method_override_for_base_with_name(
original_type,
defn.name,
name,
base.name,
base.name if base.module_name == self.tree.fullname else base.fullname,
original_class_or_static,
override_class_or_static,
context,
Expand Down
22 changes: 22 additions & 0 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -3599,3 +3599,25 @@ class Bar(Foo):

def foo(self, value: Union[int, str]) -> Union[int, str]:
return super().foo(value) # E: Call to abstract method "foo" of "Foo" with trivial body via super() is unsafe

[case fullNamesOfImportedBaseClassesDisplayed]
from a import A

class B(A):
def f(self, x: str) -> None: # E: Argument 1 of "f" is incompatible with supertype "a.A"; supertype defines the argument type as "int" \
# N: This violates the Liskov substitution principle \
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
...
def g(self, x: str) -> None: # E: Signature of "g" incompatible with supertype "a.A" \
# N: Superclass: \
# N: def g(self) -> None \
# N: Subclass: \
# N: def g(self, x: str) -> None
...

[file a.py]
class A:
def f(self, x: int) -> None:
...
def g(self) -> None:
...
Loading