diff --git a/mypy/checker.py b/mypy/checker.py index dbd74d5a8132..ab49e1bc8ac3 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -1971,6 +1971,9 @@ def check_method_override_for_base_with_name( original_class_or_static, override_class_or_static, context, + ignore_pos_arg_names=( + not context.is_explicit_override if isinstance(context, FuncDef) else True + ), ) elif is_equivalent(original_type, typ): # Assume invariance for a non-callable attribute here. Note @@ -2058,6 +2061,7 @@ def check_override( original_class_or_static: bool, override_class_or_static: bool, node: Context, + ignore_pos_arg_names: bool, ) -> None: """Check a method override with given signatures. @@ -2071,7 +2075,7 @@ def check_override( # Use boolean variable to clarify code. fail = False op_method_wider_note = False - if not is_subtype(override, original, ignore_pos_arg_names=True): + if not is_subtype(override, original, ignore_pos_arg_names=ignore_pos_arg_names): fail = True elif isinstance(override, Overloaded) and self.is_forward_op_method(name): # Operator method overrides cannot extend the domain, as diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index b9baf9e4cf80..83821cf2369f 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -2742,9 +2742,11 @@ class B(A): class C(A): @override - def f(self, x: str) -> str: pass # E: Argument 1 of "f" is incompatible with supertype "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 f(self, y: int) -> str: pass # E: Signature of "f" incompatible with supertype "A" \ + # N: Superclass: \ + # N: def f(self, x: int) -> str \ + # N: Subclass: \ + # N: def f(self, y: int) -> str def g(self, x: int) -> str: pass class D(A): pass