Skip to content

Commit 061fbed

Browse files
committed
Check names of positional arguments for @OverRide
1 parent 6c2355a commit 061fbed

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
@@ -1940,6 +1940,9 @@ def check_method_override_for_base_with_name(
19401940
original_class_or_static,
19411941
override_class_or_static,
19421942
context,
1943+
ignore_pos_arg_names=(
1944+
not context.is_explicit_override if isinstance(context, FuncDef) else True
1945+
),
19431946
)
19441947
elif is_equivalent(original_type, typ):
19451948
# Assume invariance for a non-callable attribute here. Note
@@ -2005,6 +2008,7 @@ def check_override(
20052008
original_class_or_static: bool,
20062009
override_class_or_static: bool,
20072010
node: Context,
2011+
ignore_pos_arg_names: bool,
20082012
) -> None:
20092013
"""Check a method override with given signatures.
20102014
@@ -2018,7 +2022,7 @@ def check_override(
20182022
# Use boolean variable to clarify code.
20192023
fail = False
20202024
op_method_wider_note = False
2021-
if not is_subtype(override, original, ignore_pos_arg_names=True):
2025+
if not is_subtype(override, original, ignore_pos_arg_names=ignore_pos_arg_names):
20222026
fail = True
20232027
elif isinstance(override, Overloaded) and self.is_forward_op_method(name):
20242028
# 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
@@ -2743,9 +2743,11 @@ class B(A):
27432743

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

27512753
class D(A): pass

0 commit comments

Comments
 (0)