Skip to content

Commit bbe1e30

Browse files
committed
for python
1 parent 8d25bcc commit bbe1e30

1 file changed

Lines changed: 1 addition & 68 deletions

File tree

codeflash/languages/python/support.py

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -112,74 +112,7 @@ def dir_excludes(self) -> frozenset[str]:
112112
def discover_functions(
113113
self, file_path: Path, filter_criteria: FunctionFilterCriteria | None = None
114114
) -> list[FunctionToOptimize]:
115-
"""Find all optimizable functions in a Python file.
116-
117-
Uses libcst to parse the file and find functions with return statements.
118-
119-
Args:
120-
file_path: Path to the Python file to analyze.
121-
filter_criteria: Optional criteria to filter functions.
122-
123-
Returns:
124-
List of FunctionToOptimize objects for discovered functions.
125-
126-
"""
127-
import libcst as cst
128-
129-
from codeflash.discovery.functions_to_optimize import FunctionVisitor
130-
131-
criteria = filter_criteria or FunctionFilterCriteria()
132-
133-
try:
134-
# Read and parse the file using libcst with metadata
135-
source = file_path.read_text(encoding="utf-8")
136-
try:
137-
tree = cst.parse_module(source)
138-
except Exception:
139-
return []
140-
141-
# Use the libcst-based FunctionVisitor for accurate line numbers
142-
wrapper = cst.metadata.MetadataWrapper(tree)
143-
function_visitor = FunctionVisitor(file_path=str(file_path))
144-
wrapper.visit(function_visitor)
145-
146-
functions: list[FunctionToOptimize] = []
147-
for func in function_visitor.functions:
148-
if not isinstance(func, FunctionToOptimize):
149-
continue
150-
151-
# Apply filter criteria
152-
if not criteria.include_async and func.is_async:
153-
continue
154-
155-
if not criteria.include_methods and func.parents:
156-
continue
157-
158-
# Check for return statement requirement (FunctionVisitor already filters this)
159-
# but we double-check here for consistency
160-
if criteria.require_return and func.starting_line is None:
161-
continue
162-
163-
# Add is_method field based on parents
164-
func_with_is_method = FunctionToOptimize(
165-
function_name=func.function_name,
166-
file_path=file_path,
167-
parents=func.parents,
168-
starting_line=func.starting_line,
169-
ending_line=func.ending_line,
170-
starting_col=func.starting_col,
171-
ending_col=func.ending_col,
172-
is_async=func.is_async,
173-
is_method=len(func.parents) > 0 and any(p.type == "ClassDef" for p in func.parents),
174-
language="python",
175-
)
176-
functions.append(func_with_is_method)
177-
178-
return functions
179-
180-
except Exception as e:
181-
logger.warning("Failed to discover functions in %s: %s", file_path, e)
182-
return []
115+
raise NotImplementedError
183116

184117
def discover_tests(
185118
self, test_root: Path, source_functions: Sequence[FunctionToOptimize]

0 commit comments

Comments
 (0)