From d41e267ee64a500a3844d91b54a50bca21a0b654 Mon Sep 17 00:00:00 2001 From: Thomas Bean <47thomasj@gmail.com> Date: Tue, 24 Jun 2025 12:05:47 -0600 Subject: [PATCH] function fix probably --- StandardCheck.py | 2 +- checkers/common_nodes.py | 24 ++++++++++++------------ checkers/complexity.py | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/StandardCheck.py b/StandardCheck.py index e8c4874..7bf9cfe 100644 --- a/StandardCheck.py +++ b/StandardCheck.py @@ -32,7 +32,7 @@ def visit_node(node: ast.AST, file_path: str, ignore_codes: set[str], ignore_nam if isinstance(node, ast.ClassDef): return common_nodes_module.check_class(node, file_path, ignore_codes, ignore_names) - elif isinstance(node, ast.FunctionDef): + elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): return common_nodes_module.check_function(node, file_path, ignore_codes, ignore_names) elif isinstance(node, ast.Name) and isinstance(node.ctx, ast.Store): return common_nodes_module.check_variable(node, file_path, ignore_codes, ignore_names) diff --git a/checkers/common_nodes.py b/checkers/common_nodes.py index 869096f..b77bf36 100644 --- a/checkers/common_nodes.py +++ b/checkers/common_nodes.py @@ -98,7 +98,7 @@ def _is_valid_class_name(name: str) -> bool: return False -def check_function(node: ast.FunctionDef, file_path: str, ignore_codes: set[str], ignore_names: set[str] = None) -> list[models.StyleError]: +def check_function(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str], ignore_names: set[str] = None) -> list[models.StyleError]: """Check function definition. Args: @@ -126,7 +126,7 @@ def check_function(node: ast.FunctionDef, file_path: str, ignore_codes: set[str] return errors -def _check_function_name(node: ast.FunctionDef, file_path: str, ignore_codes: set[str], is_test_file: bool) -> list[models.StyleError]: +def _check_function_name(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str], is_test_file: bool) -> list[models.StyleError]: """Check function naming convention. Args: @@ -150,7 +150,7 @@ def _check_function_name(node: ast.FunctionDef, file_path: str, ignore_codes: se return [] -def _check_name_mangling(node: ast.FunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: +def _check_name_mangling(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: """Check for inappropriate name mangling. Args: @@ -169,7 +169,7 @@ def _check_name_mangling(node: ast.FunctionDef, file_path: str, ignore_codes: se return [] -def _has_overload_decorator(node: ast.FunctionDef) -> bool: +def _has_overload_decorator(node: ast.FunctionDef | ast.AsyncFunctionDef) -> bool: """Check if function has @overload decorator. Args: @@ -188,7 +188,7 @@ def _has_overload_decorator(node: ast.FunctionDef) -> bool: return False -def _check_function_docstrings(node: ast.FunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: +def _check_function_docstrings(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: """Check for missing or incorrect function docstring. Args: @@ -218,7 +218,7 @@ def _check_function_docstrings(node: ast.FunctionDef, file_path: str, ignore_cod return errors -def _check_docstring_format(node: ast.FunctionDef|ast.ClassDef, docstring: str, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: +def _check_docstring_format(node: ast.FunctionDef | ast.AsyncFunctionDef | ast.ClassDef, docstring: str, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: """Check docstring formatting rules. Args: @@ -253,7 +253,7 @@ def _check_docstring_format(node: ast.FunctionDef|ast.ClassDef, docstring: str, return errors -def _check_function_docstring(node: ast.FunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: +def _check_function_docstring(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: """Check function docstring completeness. Args: @@ -282,7 +282,7 @@ def _check_function_docstring(node: ast.FunctionDef, file_path: str, ignore_code return errors -def _check_missing_doc_args(node: ast.FunctionDef, func_args: list[str], doc_args: set[str], file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: +def _check_missing_doc_args(node: ast.FunctionDef | ast.AsyncFunctionDef, func_args: list[str], doc_args: set[str], file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: """Check for arguments in signature that are missing in the docstring. Args: @@ -303,7 +303,7 @@ def _check_missing_doc_args(node: ast.FunctionDef, func_args: list[str], doc_arg errors.append(error) return errors -def _check_extra_doc_args(node: ast.FunctionDef, func_args: list[str], doc_args: set[str], file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: +def _check_extra_doc_args(node: ast.FunctionDef | ast.AsyncFunctionDef, func_args: list[str], doc_args: set[str], file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: """Check for arguments documented in the docstring but missing from the signature. Args: @@ -325,7 +325,7 @@ def _check_extra_doc_args(node: ast.FunctionDef, func_args: list[str], doc_args: errors.append(error) return errors -def _check_missing_returns_section(node: ast.FunctionDef, docstring: str, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: +def _check_missing_returns_section(node: ast.FunctionDef | ast.AsyncFunctionDef, docstring: str, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: """Check if a Returns section is missing from the docstring. Args: @@ -405,7 +405,7 @@ def _parse_docstring_args(docstring: str) -> set[str]: return args_section -def _check_function_annotations(node: ast.FunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: +def _check_function_annotations(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: """Check function type annotations. Args: @@ -436,7 +436,7 @@ def _check_function_annotations(node: ast.FunctionDef, file_path: str, ignore_co return errors -def _check_mutable_defaults(node: ast.FunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: +def _check_mutable_defaults(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str]) -> list[models.StyleError]: """Check for mutable default arguments. Args: diff --git a/checkers/complexity.py b/checkers/complexity.py index 68a9b31..0c79ffe 100644 --- a/checkers/complexity.py +++ b/checkers/complexity.py @@ -19,7 +19,7 @@ def check_complexity(tree: ast.Module, content: str, file_path: str, ignore_code """ errors = [] for node in ast.walk(tree): - if not isinstance(node, ast.FunctionDef): + if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): continue functional_error = _check_function_complexity(node, file_path, ignore_codes, max_complexity) if functional_error: @@ -30,7 +30,7 @@ def check_complexity(tree: ast.Module, content: str, file_path: str, ignore_code return errors -def _check_function_complexity(node: ast.FunctionDef, file_path: str, ignore_codes: set[str], max_complexity: int) -> Optional[models.StyleError]: +def _check_function_complexity(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str], max_complexity: int) -> Optional[models.StyleError]: """Check cyclomatic complexity of a single function. Args: @@ -55,7 +55,7 @@ def _check_function_complexity(node: ast.FunctionDef, file_path: str, ignore_cod ) -def _calculate_cyclomatic_complexity(node: ast.FunctionDef) -> int: +def _calculate_cyclomatic_complexity(node: ast.FunctionDef | ast.AsyncFunctionDef) -> int: """Calculate cyclomatic complexity of a function. Args: @@ -85,7 +85,7 @@ def _calculate_cyclomatic_complexity(node: ast.FunctionDef) -> int: return complexity -def _is_too_deeply_indented(node: ast.FunctionDef, content: str, file_path: str, ignore_codes: set[str], max_allowed_depth: int) -> Optional[models.StyleError]: +def _is_too_deeply_indented(node: ast.FunctionDef | ast.AsyncFunctionDef, content: str, file_path: str, ignore_codes: set[str], max_allowed_depth: int) -> Optional[models.StyleError]: """Check indentation depth of a single function. Args: @@ -116,7 +116,7 @@ def _is_too_deeply_indented(node: ast.FunctionDef, content: str, file_path: str, ) -def _get_max_indent_depth_from_source(node: ast.FunctionDef, content: str) -> int: +def _get_max_indent_depth_from_source(node: ast.FunctionDef | ast.AsyncFunctionDef, content: str) -> int: """Calculate maximum indentation depth within a function using source code. Args: