Skip to content

Commit 2d99781

Browse files
committed
extract async topkek
1 parent 35d4f05 commit 2d99781

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

codeflash/code_utils/static_analysis.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,19 @@ def get_first_top_level_object_def_ast(
128128

129129
def get_first_top_level_function_or_method_ast(
130130
function_name: str, parents: list[FunctionParent], node: ast.AST
131-
) -> ast.FunctionDef | None:
131+
) -> ast.FunctionDef | ast.AsyncFunctionDef | None:
132132
if not parents:
133-
return get_first_top_level_object_def_ast(function_name, ast.FunctionDef, node)
133+
result = get_first_top_level_object_def_ast(function_name, ast.FunctionDef, node)
134+
if result is None:
135+
result = get_first_top_level_object_def_ast(function_name, ast.AsyncFunctionDef, node)
136+
return result
134137
if parents[0].type == "ClassDef" and (
135138
class_node := get_first_top_level_object_def_ast(parents[0].name, ast.ClassDef, node)
136139
):
137-
return get_first_top_level_object_def_ast(function_name, ast.FunctionDef, class_node)
140+
result = get_first_top_level_object_def_ast(function_name, ast.FunctionDef, class_node)
141+
if result is None:
142+
result = get_first_top_level_object_def_ast(function_name, ast.AsyncFunctionDef, class_node)
143+
return result
138144
return None
139145

140146

codeflash/optimization/function_optimizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __init__(
110110
test_cfg: TestConfig,
111111
function_to_optimize_source_code: str = "",
112112
function_to_tests: dict[str, set[FunctionCalledInTest]] | None = None,
113-
function_to_optimize_ast: ast.FunctionDef | None = None,
113+
function_to_optimize_ast: ast.FunctionDef | ast.AsyncFunctionDef | None = None,
114114
aiservice_client: AiServiceClient | None = None,
115115
function_benchmark_timings: dict[BenchmarkKey, int] | None = None,
116116
total_benchmark_timings: dict[BenchmarkKey, int] | None = None,

codeflash/optimization/optimizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def get_optimizable_functions(self) -> tuple[dict[Path, list[FunctionToOptimize]
128128
def create_function_optimizer(
129129
self,
130130
function_to_optimize: FunctionToOptimize,
131-
function_to_optimize_ast: ast.FunctionDef | None = None,
131+
function_to_optimize_ast: ast.FunctionDef | ast.AsyncFunctionDef | None = None,
132132
function_to_tests: dict[str, set[FunctionCalledInTest]] | None = None,
133133
function_to_optimize_source_code: str | None = "",
134134
function_benchmark_timings: dict[str, dict[BenchmarkKey, float]] | None = None,

0 commit comments

Comments
 (0)