Skip to content

Commit eafbd3f

Browse files
committed
Display FQN for imported base classes in errors about incompatible overrides
Fixes python#19112.
1 parent 301c3b6 commit eafbd3f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ def check_method_override_for_base_with_name(
22632263
original_type,
22642264
defn.name,
22652265
name,
2266-
base.name,
2266+
base.name if base.module_name == self.tree.fullname else base.fullname,
22672267
original_class_or_static,
22682268
override_class_or_static,
22692269
context,

test-data/unit/check-functions.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,3 +3599,25 @@ class Bar(Foo):
35993599

36003600
def foo(self, value: Union[int, str]) -> Union[int, str]:
36013601
return super().foo(value) # E: Call to abstract method "foo" of "Foo" with trivial body via super() is unsafe
3602+
3603+
[case fullNamesOfImportedBaseClassesDisplayed]
3604+
from a import A
3605+
3606+
class B(A):
3607+
def f(self, x: str) -> None: # E: Argument 1 of "f" is incompatible with supertype "a.A"; supertype defines the argument type as "int" \
3608+
# N: This violates the Liskov substitution principle \
3609+
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
3610+
...
3611+
def g(self, x: str) -> None: # E: Signature of "g" incompatible with supertype "a.A" \
3612+
# N: Superclass: \
3613+
# N: def g(self) -> None \
3614+
# N: Subclass: \
3615+
# N: def g(self, x: str) -> None
3616+
...
3617+
3618+
[file a.py]
3619+
class A:
3620+
def f(self, x: int) -> None:
3621+
...
3622+
def g(self) -> None:
3623+
...

0 commit comments

Comments
 (0)