Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2403,7 +2403,7 @@ def check_method_override_for_base_with_name(
and codes.MUTABLE_OVERRIDE in self.options.enabled_error_codes
and self.is_writable_attribute(original_node)
and not always_allow_covariant
and not is_subtype(original_type, typ, ignore_pos_arg_names=True)
and not is_subtype(original_type, typ)
):
base_str, override_str = format_type_distinctly(
original_type, typ, options=self.options
Expand All @@ -2414,8 +2414,7 @@ def check_method_override_for_base_with_name(
)
self.fail(msg, context)
elif isinstance(original_type, UnionType) and any(
is_subtype(typ, orig_typ, ignore_pos_arg_names=True)
for orig_typ in original_type.items
is_subtype(typ, orig_typ) for orig_typ in original_type.items
):
# This method is a subtype of at least one union variant.
if (
Expand Down Expand Up @@ -2497,7 +2496,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):
fail = True
elif isinstance(override, Overloaded) and self.is_forward_op_method(name):
# Operator method overrides cannot extend the domain, as
Expand Down
42 changes: 21 additions & 21 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -3074,11 +3074,11 @@ class B(A):

class C(A):
@overload
def f(self, y: int) -> str: pass
def f(self, x: int) -> str: pass
@override
@overload
def f(self, y: str) -> str: pass
def f(self, y: int | str) -> str: pass
def f(self, x: str) -> str: pass
def f(self, x: int | str) -> str: pass
[typing fixtures/typing-override.pyi]

[case explicitOverrideOnMultipleOverloads]
Expand All @@ -3099,12 +3099,12 @@ class B(A):

class C(A):
@overload
def f(self, y: int) -> str: pass
def f(self, x: int) -> str: pass
@override
@overload
def f(self, y: str) -> str: pass
def f(self, x: str) -> str: pass
@override
def f(self, y: int | str) -> str: pass
def f(self, x: int | str) -> str: pass
[typing fixtures/typing-override.pyi]

[case explicitOverrideCyclicDependency]
Expand Down Expand Up @@ -3142,13 +3142,13 @@ class A:

class B(A):
@override
def f(self, y: int) -> str: pass
def f(self, x: int) -> str: pass

class C(A):
def f(self, y: int) -> str: pass # E: Method "f" is not using @override but is overriding a method in class "__main__.A"
def f(self, x: int) -> str: pass # E: Method "f" is not using @override but is overriding a method in class "__main__.A"

class D(B):
def f(self, y: int) -> str: pass # E: Method "f" is not using @override but is overriding a method in class "__main__.B"
def f(self, x: int) -> str: pass # E: Method "f" is not using @override but is overriding a method in class "__main__.B"
[typing fixtures/typing-override.pyi]

[case requireExplicitOverrideSpecialMethod]
Expand Down Expand Up @@ -3221,26 +3221,26 @@ class A:

class B(A):
@overload
def f(self, y: int) -> str: ...
def f(self, x: int) -> str: ...
@overload
def f(self, y: str) -> str: ...
def f(self, x: str) -> str: ...
@override
def f(self, y): pass
def f(self, x): pass

class C(A):
@overload
@override
def f(self, y: int) -> str: ...
def f(self, x: int) -> str: ...
@overload
def f(self, y: str) -> str: ...
def f(self, y): pass
def f(self, x: str) -> str: ...
def f(self, x): pass

class D(A):
@overload
def f(self, y: int) -> str: ...
def f(self, x: int) -> str: ...
@overload
def f(self, y: str) -> str: ...
def f(self, y): pass # E: Method "f" is not using @override but is overriding a method in class "__main__.A"
def f(self, x: str) -> str: ...
def f(self, x): pass # E: Method "f" is not using @override but is overriding a method in class "__main__.A"
[typing fixtures/typing-override.pyi]

[case requireExplicitOverrideMultipleInheritance]
Expand All @@ -3250,14 +3250,14 @@ from typing import override
class A:
def f(self, x: int) -> str: pass
class B:
def f(self, y: int) -> str: pass
def f(self, x: int) -> str: pass

class C(A, B):
@override
def f(self, z: int) -> str: pass
def f(self, x: int) -> str: pass

class D(A, B):
def f(self, z: int) -> str: pass # E: Method "f" is not using @override but is overriding a method in class "__main__.A"
def f(self, x: int) -> str: pass # E: Method "f" is not using @override but is overriding a method in class "__main__.A"
[typing fixtures/typing-override.pyi]

[case testExplicitOverrideAllowedForPrivate]
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-super.test
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class A:
def f(self, s: str) -> None: pass

class B(A):
def f(self, i: Union[int, str]) -> None: pass
def f(self, s: Union[int, str]) -> None: pass

class C:
def g(self, b: B) -> None:
Expand All @@ -251,7 +251,7 @@ class A:
def f(self, s: str) -> None: pass

class B(A):
def f(self, i: Union[int, str]) -> None: pass
def f(self, s: Union[int, str]) -> None: pass

def g(b: B) -> None:
super(B, b).f('42')
Expand Down
Loading