From d07ccb8a7fbeab61657fa23f65f4ae366f637d3b Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Wed, 12 Jul 2023 20:00:41 +0200 Subject: [PATCH 1/2] Do not trigger on cls in classmethod --- flake8_typehinting/flake8_typehinting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake8_typehinting/flake8_typehinting.py b/flake8_typehinting/flake8_typehinting.py index c1b7ef1..60884cc 100644 --- a/flake8_typehinting/flake8_typehinting.py +++ b/flake8_typehinting/flake8_typehinting.py @@ -35,7 +35,7 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> None: # NOQA N802 def _check_th_100(self, node: ast.FunctionDef) -> None: """Check for TH100.""" for arg in node.args.args: - if not arg.arg == 'self' and arg.annotation is None: + if arg.arg not in ('self', 'cls') and arg.annotation is None: self.problems.append((node.lineno, node.col_offset, f'{TH100} ({arg.arg})')) def _check_th_101(self, node: ast.FunctionDef) -> None: From cab89f0516c29ee6a3c79ef631e384cbc9d555f6 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Wed, 12 Jul 2023 20:08:58 +0200 Subject: [PATCH 2/2] Added test for checking that cls is not triggered --- tests/test_flake8_typehinting.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_flake8_typehinting.py b/tests/test_flake8_typehinting.py index a212944..ad8e60f 100644 --- a/tests/test_flake8_typehinting.py +++ b/tests/test_flake8_typehinting.py @@ -76,3 +76,9 @@ def test_type_hinting_in_function_return_correct() -> None: """Test type hinting in function definitions.""" ret = _results('def my_func(y: int, x: str = "1") -> int:\n return 1') assert ret == set() + + +def test_type_hinting_in_function_definition_cls() -> None: + """Test type hinting in function definitions.""" + ret = _results('def my_func(cls, y: int, x="1") -> None:\n print(x)') + assert ret == {'1:0 TH100 function missing type hints for arguments (x)'}