Module

compiler.utils

Typed compiler helpers shared without expanding mixin contracts.

Functions

fix_missing_locations_fast 1 T
Fill missing Python AST locations while preserving the concrete AST type. This…
def fix_missing_locations_fast(node: T) -> T

Fill missing Python AST locations while preserving the concrete AST type.

This mirrorsfix_missing_locations(): each child inherits the current parent location unless it already carries its own value. Kida emits large generated ASTs during compile, so the iterative traversal avoids recursiveast.iter_fields()overhead on the compile hot path.

Parameters
Name Type Description
node T
Returns
T
make_line_marker 1 ast.Assign
Build ``_rc.line = lineno`` for render-time error attribution.
def make_line_marker(lineno: int) -> ast.Assign
Parameters
Name Type Description
lineno int
Returns
ast.Assign
make_template_warning 5 TemplateWarning
Build an immutable compiler warning with template provenance.
def make_template_warning(code: ErrorCode, message: str, *, template_name: str | None, lineno: int | None = None, suggestion: str | None = None) -> TemplateWarning
Parameters
Name Type Description
code ErrorCode
message str
template_name str | None
lineno int | None Default:None
suggestion str | None Default:None
Returns
TemplateWarning
get_binop 1 ast.operator
Map binary operator string to AST operator. Raises KeyError on unknown.
def get_binop(op: str) -> ast.operator
Parameters
Name Type Description
op str
Returns
ast.operator
get_unaryop 1 ast.unaryop
Map unary operator string to AST operator. Raises KeyError on unknown.
def get_unaryop(op: str) -> ast.unaryop
Parameters
Name Type Description
op str
Returns
ast.unaryop
get_cmpop 1 ast.cmpop
Map comparison operator string to AST operator. Raises KeyError on unknown.
def get_cmpop(op: str) -> ast.cmpop
Parameters
Name Type Description
op str
Returns
ast.cmpop