From 82cbd1b2a2328a92e47ad32da0751ef42462dca3 Mon Sep 17 00:00:00 2001 From: Shantanu Jain Date: Sat, 28 Dec 2024 17:50:48 -0800 Subject: [PATCH 1/3] Be strict about arg names in LSP checks Python 3.7 has been dead for a long time, people can use PEP 570. Let's see primer, this might need to be an option --- mypy/checker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index b2c4f2263262..9d974bed456a 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -2155,7 +2155,7 @@ def check_method_override_for_base_with_name( and original_node and codes.MUTABLE_OVERRIDE in self.options.enabled_error_codes and self.is_writable_attribute(original_node) - 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 @@ -2166,7 +2166,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) + is_subtype(typ, orig_typ) for orig_typ in original_type.items ): # This method is a subtype of at least one union variant. @@ -2293,7 +2293,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 From 208dddf0eaa3766cfb9b7662c365206c5eea2d69 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 29 Dec 2024 01:58:06 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/checker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index 9d974bed456a..31402bf48f33 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -2166,8 +2166,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) - 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 ( From b0b1902ee07df371bd8a3af15f7e700fe72ceecf Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 8 Jan 2026 13:03:28 -0800 Subject: [PATCH 3/3] test fixes --- test-data/unit/check-functions.test | 42 ++++++++++++++--------------- test-data/unit/check-super.test | 4 +-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index b54dffe836b8..3e6d355f2905 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] diff --git a/test-data/unit/check-super.test b/test-data/unit/check-super.test index 8816322a270a..9caf4d930e11 100644 --- a/test-data/unit/check-super.test +++ b/test-data/unit/check-super.test @@ -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: @@ -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')