ctfsolver.find_usage.function_definition_class

function_definition_class.py

Provides a class for traversing Python Abstract Syntax Trees (AST) to locate specific function definitions.

This module defines the FunctionDefFinder class, which extends ast.NodeVisitor to search for a function definition node by name within a Python AST. It is useful for static code analysis, refactoring tools, or any application that requires inspection of Python source code structure.

Classes:

FunctionDefFinder: AST NodeVisitor to find a specific function definition by name.

Example

finder = FunctionDefFinder(function_target=”my_function”) finder.visit(ast.parse(source_code)) found_node = finder.function_def

Classes

FunctionDefFinder

AST NodeVisitor to find a specific function definition in a Python AST.

Module Contents

class FunctionDefFinder(*args, **kwargs)[source]

Bases: ast.NodeVisitor

AST NodeVisitor to find a specific function definition in a Python AST.

function_def[source]

The found function definition node.

Type:

Optional[ast.FunctionDef]

function_target[source]

The name of the function to search for.

Type:

Optional[str]

visit_list[source]

List of visited function definition nodes.

Type:

List[ast.FunctionDef]

Functions:

visit_FunctionDef: Visits a function definition node in the AST.

tree[source]
function_target: str | None[source]
source_file: str | None[source]
function_def: ast.FunctionDef | None = None[source]
visit_list: list[ast.FunctionDef] = [][source]
info[source]
visit_FunctionDef(node)[source]

Visits a function definition node in the AST.

Parameters:

node (ast.FunctionDef) – The function definition node to visit.

Return type:

None