Skip to content
Merged
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
6 changes: 4 additions & 2 deletions codeflash/languages/python/instrument_codeflash_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def __init__(
self._starred_args = ast.Starred(value=self._args_name_load, ctx=self._load_ctx)
self._kwargs_keyword = ast.keyword(arg=None, value=self._kwargs_name_load)

# Pre-parse the import statement to avoid repeated parsing in visit_Module
self._import_stmt = ast.parse("from codeflash.verification.codeflash_capture import codeflash_capture").body[0]

def visit_ImportFrom(self, node: ast.ImportFrom) -> ast.ImportFrom:
# Check if our import already exists
if node.module == "codeflash.verification.codeflash_capture" and any(
Expand All @@ -155,8 +158,7 @@ def visit_Module(self, node: ast.Module) -> ast.Module:

# Add import statement
if not self.has_import and self.inserted_decorator:
import_stmt = ast.parse("from codeflash.verification.codeflash_capture import codeflash_capture").body[0]
node.body.insert(0, import_stmt)
node.body.insert(0, self._import_stmt)

return node

Expand Down
Loading