Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't accidentally ignore typeguard validity for staticmethods #14953

Merged
merged 10 commits into from
Mar 26, 2023
Merged
Next Next commit
Fix a slip up I made
A5rocks authored Mar 24, 2023
commit bd99419e3e9be403a88b8ba07283ef35b1db539f
3 changes: 1 addition & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
@@ -869,8 +869,7 @@ def analyze_func_def(self, defn: FuncDef) -> None:
# type guards need to have a positional argument, to spec
if (
result.type_guard
and ARG_POS not in result.arg_kinds[self.is_class_scope() :]
and not defn.is_static
and ARG_POS not in result.arg_kinds[self.is_class_scope() and not defn.is_static :]
):
self.fail(
"TypeGuard functions must have a positional argument",
10 changes: 9 additions & 1 deletion test-data/unit/check-typeguard.test
Original file line number Diff line number Diff line change
@@ -602,7 +602,15 @@ def func(names: Tuple[str, ...]):
from typing_extensions import TypeGuard

class Z:
def typeguard(self, *, x: object) -> TypeGuard[int]: # E: TypeGuard functions must have a positional argument
def typeguard1(self, *, x: object) -> TypeGuard[int]: # E: TypeGuard functions must have a positional argument
...

@staticmethod
def typeguard2(x: object) -> TypeGuard[int]:
...

@staticmethod
def typeguard3(*, x: object) -> TypeGuard[int]: # E: TypeGuard functions must have a positional argument
...

def bad_typeguard(*, x: object) -> TypeGuard[int]: # E: TypeGuard functions must have a positional argument