Skip to content
Merged

Dev #31

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
2 changes: 1 addition & 1 deletion StandardCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions checkers/common_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions checkers/complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Loading