-
Notifications
You must be signed in to change notification settings - Fork 26
⚡️ Speed up function _parse_and_collect_imports by 69% in PR #1498 (cf-simplify-context-extraction)
#1499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KRRT7
merged 4 commits into
cf-simplify-context-extraction
from
codeflash/optimize-pr1498-2026-02-16T20.49.33
Feb 16, 2026
Merged
⚡️ Speed up function _parse_and_collect_imports by 69% in PR #1498 (cf-simplify-context-extraction)
#1499
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bace611
Optimize _parse_and_collect_imports
codeflash-ai[bot] 73e71d0
style: auto-fix linting issues
github-actions[bot] 29c0a66
fix: resolve mypy type errors in collect_imports
github-actions[bot] bfa55cb
fix: handle ast.Match (Python 3.10+) in collect_imports traversal
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missing
ast.Match(Python 3.10+) node typeThe
collect_importsrecursive traversal handlesTry,If,For,While,With, etc., but does not handleast.Match(match/case statements, introduced in Python 3.10). If someone writes:The
ImportFrominside thematch_casebody won't be found by this optimized traversal, whereas the originalast.walk()would find it.Since the project targets Python 3.9+, this is a low-probability edge case (imports inside match/case are very uncommon), but it's a correctness gap vs the original implementation.
Consider adding
ast.Matchandmatch_caseto the isinstance check (guarded by a version check orhasattr).