refactor: consolidate Python function discovery to CST path only#1689
refactor: consolidate Python function discovery to CST path only#1689
Conversation
Remove the AST-based discovery path for Python, routing all languages through the unified CST-based `_find_all_functions_via_language_support`. Delete dead code: `find_functions_with_return_statement`, `_find_all_functions_in_python_file`, `function_has_return_statement`, `function_is_a_property`, and associated constants. Fix FunctionVisitor to skip nested functions and exclude @property/@cached_property, and let parse errors propagate for correct empty-dict behavior on invalid files.
PR Review SummaryPrek ChecksAll checks pass (ruff check, ruff format) — no issues found. MypyAll mypy errors on changed files are pre-existing (not introduced by this PR). Errors include missing type exports from codeflash.languages.base, missing type params on list/dict generics in support.py, and missing annotations on test functions — all present on main as well. Code ReviewOverall this is a clean refactor that removes ~100 lines of dead AST-based code and unifies Python discovery through the CST path. Minor issue (non-blocking):
No critical bugs, security issues, or breaking API changes found. Key observations:
Test Coverage
Last updated: 2026-02-27 |
Nested functions are now skipped by FunctionVisitor, and discover_functions no longer swallows parse/IO errors — callers handle them. Update test expectations accordingly.
|
@claude Test results: 2463 passed, 13 failed, 57 skipped. The 13 failures are pre-existing (same failures occur on main). what failures are those? |
- Change FunctionVisitor.file_path from str to Path - Unify dict keys to Path across discovery functions (get_all_files_and_functions, get_functions_within_lines, get_functions_within_git_diff, etc.) - Remove redundant isinstance check in discover_functions - Add assert for found_function narrowing after exit_with_message - Fix closest_matching_file_function_name return type narrowing
|
@claude is the JUnit XML parsing logic actually being used for JS / TS? |
⚡️ Codeflash found optimizations for this PR📄 175% (1.75x) speedup for
|
Summary
find_functions_with_return_statement,_find_all_functions_in_python_file,function_has_return_statement,function_is_a_property, and associated constants)_find_all_functions_via_language_supportlike all other languagesFunctionVisitorto skip nested functions and exclude@property/@cached_propertydecorated functionsPythonSupport.discover_functionsso invalid files correctly return{}Test plan
uv run pytest tests/test_function_discovery.py -x -q— 23 passeduv run pytest tests/test_async_function_discovery.py -x -q— all passeduv run ruff check/ruff format— clean