Skip to content

Commit ffc8b09

Browse files
author
Ubuntu
committed
Improve LSP override error message
1 parent d99e2c9 commit ffc8b09

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

mypy/messages.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,9 @@ def signature_incompatible_with_supertype(
12931293
)
12941294
else:
12951295
self.note(override_str, context, offset=ALIGN_OFFSET + 2 * OFFSET, parent_error=error)
1296+
self.note(
1297+
"This violates the Liskov substitution principle", context, parent_error=error
1298+
)
12961299

12971300
def pretty_callable_or_overload(
12981301
self,

test-data/unit/check-classes.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9412,3 +9412,11 @@ from typ import NT
94129412
def f() -> NT:
94139413
return NT(x='')
94149414
[builtins fixtures/tuple.pyi]
9415+
9416+
[case testLSPOverrideNote]
9417+
class A:
9418+
def f(self, x: object) -> object: ...
9419+
class B(A):
9420+
def f(self, x: int) -> int: ... # E: Argument 1 of "f" is incompatible with supertype "A"; supertype defines the argument type as "object" \
9421+
# N: This violates the Liskov substitution principle \
9422+
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides

0 commit comments

Comments
 (0)