Skip to content

Commit bfa55cb

Browse files
fix: handle ast.Match (Python 3.10+) in collect_imports traversal
The optimized collect_imports missed match/case statements where imports can legally appear. Add hasattr-guarded handling for ast.Match nodes. Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
1 parent 29c0a66 commit bfa55cb

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

codeflash/languages/python/context/code_context_extractor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,10 @@ def collect_imports(nodes: list[ast.stmt]) -> None:
589589
if hasattr(node, "handlers"):
590590
for handler in node.handlers:
591591
collect_imports(handler.body)
592+
# Handle match/case statements (Python 3.10+)
593+
elif hasattr(ast, "Match") and isinstance(node, ast.Match):
594+
for case in node.cases:
595+
collect_imports(case.body)
592596

593597
collect_imports(tree.body)
594598
return tree, imported_names

0 commit comments

Comments
 (0)