Skip to content

FunctionAnalyzer

Handsdown API Index / Handsdown / AST Parser / Analyzers / FunctionAnalyzer

Auto-generated documentation for handsdown.ast_parser.analyzers.function_analyzer module.

FunctionAnalyzer

Show source in function_analyzer.py:12

AST analyzer for ast.FunctionDef records.

Signature

class FunctionAnalyzer(BaseAnalyzer):
    def __init__(self) -> None:
        ...

See also

FunctionAnalyzer().generic_visit

Show source in function_analyzer.py:161

Do nothing for unknown ast.AST nodes.

Arguments

  • node - AST node.

Signature

def generic_visit(self, node: ast.AST) -> None:
    ...

FunctionAnalyzer().visit_AsyncFunctionDef

Show source in function_analyzer.py:142

Entrypoint for the analyzer for asynchronous functions.

Visits each node from node.args. Adds new ast.expr entry to decorator_nodes for each node from node.decorator_list. Sets return_type_hint to node.returns if it defined.

Examples

async def my_func():
    return await result

Arguments

  • node - AST node.

Signature

def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None:
    ...

FunctionAnalyzer().visit_FunctionDef

Show source in function_analyzer.py:123

Entrypoint for the analyzer.

Visits each node from node.args. Adds new ast.expr entry to decorator_nodes for each node from node.decorator_list. Sets return_type_hint to node.returns if it defined.

Examples

def my_func():
    return result

Arguments

  • node - AST node.

Signature

def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
    ...

FunctionAnalyzer().visit_arguments

Show source in function_analyzer.py:38

Parse info about class method statements.

Adds new ArgumentRecord entry to argument_records for each argument.

Examples

# simple arguments
def my_func(
    arg1,
    arg_default="value",
    *args,
    **kwargs,
):
    pass

# type annotated arguments
def my_func_typed(
    arg1: str,
    arg_default: str = "value",
):
    pass

# keyword-only arguments
def my_func_kw_only(
    *,
    kw_only_arg
):
    pass

# pos-only arguments for py38
def my_func_kw_only(
    pos_only_arg,
    /
):
    pass

Arguments

  • node - AST node.

Signature

def visit_arguments(self, node: ast.arguments) -> None:
    ...