diff --git a/mypy/checker.py b/mypy/checker.py index aceb0291926a..c910f3c6fc47 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -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, diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index ac93c6c20354..9f6e6e1655e1 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -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: + ...