diff --git a/mypy/messages.py b/mypy/messages.py index 0a9f96ab6589..c9e3d50d27d8 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1293,6 +1293,9 @@ def signature_incompatible_with_supertype( ) else: self.note(override_str, context, offset=ALIGN_OFFSET + 2 * OFFSET, parent_error=error) + self.note( + "This violates the Liskov substitution principle", context, parent_error=error + ) def pretty_callable_or_overload( self, diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index 5a66eff2bd3b..23dc8aed70b8 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -9412,3 +9412,11 @@ from typ import NT def f() -> NT: return NT(x='') [builtins fixtures/tuple.pyi] + +[case testLSPOverrideNote] +class A: + def f(self, x: object) -> object: ... +class B(A): + def f(self, x: int) -> int: ... # E: Argument 1 of "f" is incompatible with supertype "A"; supertype defines the argument type as "object" \ + # N: This violates the Liskov substitution principle \ + # N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides