diff --git a/mypy/messages.py b/mypy/messages.py index 3aeaa1c4da3d..a732d612123c 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1157,7 +1157,9 @@ def signature_incompatible_with_supertype( # note: def f(self) -> str # note: Subclass: # note: def f(self, x: str) -> None - self.note("Superclass:", context, offset=ALIGN_OFFSET + OFFSET, code=code) + self.note( + "Superclass:", context, offset=ALIGN_OFFSET + OFFSET, allow_dups=ALLOW_DUPS, code=code + ) if isinstance(original, (CallableType, Overloaded)): self.pretty_callable_or_overload( original, @@ -1168,9 +1170,17 @@ def signature_incompatible_with_supertype( code=code, ) else: - self.note(original_str, context, offset=ALIGN_OFFSET + 2 * OFFSET, code=code) + self.note( + original_str, + context, + offset=ALIGN_OFFSET + 2 * OFFSET, + allow_dups=ALLOW_DUPS, + code=code, + ) - self.note("Subclass:", context, offset=ALIGN_OFFSET + OFFSET, code=code) + self.note( + "Subclass:", context, offset=ALIGN_OFFSET + OFFSET, allow_dups=ALLOW_DUPS, code=code + ) if isinstance(override, (CallableType, Overloaded)): self.pretty_callable_or_overload( override, @@ -1181,7 +1191,13 @@ def signature_incompatible_with_supertype( code=code, ) else: - self.note(override_str, context, offset=ALIGN_OFFSET + 2 * OFFSET, code=code) + self.note( + override_str, + context, + offset=ALIGN_OFFSET + 2 * OFFSET, + allow_dups=ALLOW_DUPS, + code=code, + ) def pretty_callable_or_overload( self, diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index f51e53c0a067..3af20bd1e7ea 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -588,6 +588,32 @@ class B(A): @dec def h(self) -> str: pass +[case testOverrideIncompatibleWithMultipleSupertypes] +class A: + def f(self, *, a: int) -> None: + return + +class B(A): + def f(self, *, b: int) -> None: # E: Signature of "f" incompatible with supertype "A" \ + # N: Superclass: \ + # N: def f(self, *, a: int) -> None \ + # N: Subclass: \ + # N: def f(self, *, b: int) -> None + return + +class C(B): + def f(self, *, c: int) -> None: # E: Signature of "f" incompatible with supertype "B" \ + # N: Superclass: \ + # N: def f(self, *, b: int) -> None \ + # N: Subclass: \ + # N: def f(self, *, c: int) -> None \ + # E: Signature of "f" incompatible with supertype "A" \ + # N: Superclass: \ + # N: def f(self, *, a: int) -> None \ + # N: Subclass: \ + # N: def f(self, *, c: int) -> None + return + [case testOverrideStaticMethodWithStaticMethod] class A: @staticmethod