Visitors
visitors
CST visitors for reference collection and dotted-name extraction.
ReferenceCollector
Bases: CSTVisitor
Collect external referenced names within a CST node.
Visits all Name occurrences and records only the root of any
Attribute chain (foo.bar.baz -> "foo"). Two classes of
names are deliberately excluded from :attr:names:
- Keyword-argument names (
f(x=1)->x): a kwarg label is a parameter name of the callee, never a reference to a surrounding symbol. - Locally-bound names (function/lambda parameters and simple assignment targets inside the visited block): these resolve to the block's own scope, not to an external top-level helper.
Excluding both prevents a homonymous top-level helper from being pulled in as a spurious dependency of a moved block.
Source code in packages/axm-anvil/src/axm_anvil/_cst/visitors.py
names
property
External references: collected names minus locally-bound names.
visit_AnnAssign(node)
Record an annotated-assignment target as a locally-bound name.
visit_Arg(node)
Skip a keyword label (f(x=1) -> x); visit only the value.
visit_Assign(node)
Record simple assignment targets as locally-bound names.
visit_Attribute(node)
Record only the root of an Attribute chain; skip nested visit.
Source code in packages/axm-anvil/src/axm_anvil/_cst/visitors.py
visit_FunctionDef(node)
visit_Lambda(node)
StringForwardRefScanner
Bases: CSTVisitor
Detect string annotations that forward-reference a moved symbol.
Scans Annotation nodes whose value is a SimpleString or
ConcatenatedString. The string content is parsed with
cst.parse_expression and its Name nodes are intersected with
moved_names (whole-identifier match, never a substring). Each hit
appends a structured, actionable message to :attr:warnings. This is
detection-only: the visitor never mutates the tree.
Source code in packages/axm-anvil/src/axm_anvil/_cst/visitors.py
leave_FunctionDef(original_node)
visit_AnnAssign(node)
Scan an annotated assignment's string annotation.
visit_FunctionDef(node)
Track the enclosing function and scan its return annotation.
Source code in packages/axm-anvil/src/axm_anvil/_cst/visitors.py
visit_Param(node)
Scan a parameter's string annotation.
Source code in packages/axm-anvil/src/axm_anvil/_cst/visitors.py
dotted_name(node)
Convert a Name / Attribute chain to its dotted string form.
Returns an empty string for any other node type.