Summary
SyntaxVerifier.verify does import libcst inside the method on every invocation. That adds import overhead per fix/verify cycle even when short-circuiting could be optimized. Also, dangerous-call and import-count logic walks ASTs that could share a single ast.parse if the engine provides it (see related issue on shared AST).
Suggested direction
- Move libcst to module-level lazy import pattern (e.g. import on first use cached in a module global) or top-level import if dependency is always present for verification.
- After shared-parse work lands, reuse one
ast for _find_dangerous_calls / _count_imports where it reduces walks.
Acceptance
- Reduced per-call import cost in profiles or micro-benchmarks.
- Behavior unchanged for CST round-trip failures and dangerous-call detection.
Code
refactron/verification/checks/syntax.py
Summary
SyntaxVerifier.verifydoesimport libcstinside the method on every invocation. That adds import overhead per fix/verify cycle even when short-circuiting could be optimized. Also, dangerous-call and import-count logic walks ASTs that could share a singleast.parseif the engine provides it (see related issue on shared AST).Suggested direction
astfor_find_dangerous_calls/_count_importswhere it reduces walks.Acceptance
Code
refactron/verification/checks/syntax.py