Skip to content

Commit 94840af

Browse files
committed
Check names of positional arguments for @OverRide
1 parent 10cd4aa commit 94840af

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

mypy/checker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,9 @@ def check_method_override_for_base_with_name(
19711971
original_class_or_static,
19721972
override_class_or_static,
19731973
context,
1974+
ignore_pos_arg_names=(
1975+
not context.is_explicit_override if isinstance(context, FuncDef) else True
1976+
),
19741977
)
19751978
elif is_equivalent(original_type, typ):
19761979
# Assume invariance for a non-callable attribute here. Note
@@ -2058,6 +2061,7 @@ def check_override(
20582061
original_class_or_static: bool,
20592062
override_class_or_static: bool,
20602063
node: Context,
2064+
ignore_pos_arg_names: bool,
20612065
) -> None:
20622066
"""Check a method override with given signatures.
20632067
@@ -2071,7 +2075,7 @@ def check_override(
20712075
# Use boolean variable to clarify code.
20722076
fail = False
20732077
op_method_wider_note = False
2074-
if not is_subtype(override, original, ignore_pos_arg_names=True):
2078+
if not is_subtype(override, original, ignore_pos_arg_names=ignore_pos_arg_names):
20752079
fail = True
20762080
elif isinstance(override, Overloaded) and self.is_forward_op_method(name):
20772081
# Operator method overrides cannot extend the domain, as

test-data/unit/check-functions.test

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,9 +2742,11 @@ class B(A):
27422742

27432743
class C(A):
27442744
@override
2745-
def f(self, x: str) -> str: pass # E: Argument 1 of "f" is incompatible with supertype "A"; supertype defines the argument type as "int" \
2746-
# N: This violates the Liskov substitution principle \
2747-
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
2745+
def f(self, y: int) -> str: pass # E: Signature of "f" incompatible with supertype "A" \
2746+
# N: Superclass: \
2747+
# N: def f(self, x: int) -> str \
2748+
# N: Subclass: \
2749+
# N: def f(self, y: int) -> str
27482750
def g(self, x: int) -> str: pass
27492751

27502752
class D(A): pass

0 commit comments

Comments
 (0)