Skip to content
Closed
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
9 changes: 8 additions & 1 deletion codeflash/discovery/functions_to_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,14 @@ def filter_files_optimized(file_path: Path, tests_root: Path, ignore_paths: list


def function_has_return_statement(function_node: FunctionDef | AsyncFunctionDef) -> bool:
return any(isinstance(node, ast.Return) for node in ast.walk(function_node))
# Custom DFS, return True as soon as a Return node is found
stack = [function_node]
while stack:
node = stack.pop()
if isinstance(node, ast.Return):
return True
stack.extend(ast.iter_child_nodes(node))
return False


def function_is_a_property(function_node: FunctionDef | AsyncFunctionDef) -> bool:
Expand Down
Loading
Loading