Classes
VariableAssignmentMixin
6
▼
Mixin for compiling variable assignment statements.
Host attributes and cross-mixin dependencies a…
VariableAssignmentMixin
6
▼
Mixin for compiling variable assignment statements.
Host attributes and cross-mixin dependencies are declared via inline TYPE_CHECKING blocks.
Methods
Internal Methods 6 ▼
_compile_set
1
list[ast.stmt]
▼
Compile {% set %} - block-scoped variable assignment.
Variables assigned with …
_compile_set
1
list[ast.stmt]
▼
def _compile_set(self, node: Any) -> list[ast.stmt]
Compile {% set %} - block-scoped variable assignment.
Variables assigned with {% set %} are scoped to the current block (if/for/while/etc.) and are not accessible outside the block.
Handles both single names and structural unpacking:
{% set x = value %}
{% set a, b = 1, 2 %}
{% set (a, b), c = ([1, 2], 3) %}
Parameters
| Name | Type | Description |
|---|---|---|
node |
— |
Returns
list[ast.stmt]
_compile_let
1
list[ast.stmt]
▼
Compile {% let %} - template-scoped variable assignment.
Variables assigned wi…
_compile_let
1
list[ast.stmt]
▼
def _compile_let(self, node: Any) -> list[ast.stmt]
Compile {% let %} - template-scoped variable assignment.
Variables assigned with {% let %} are available throughout the template. Supports structural unpacking: {% let a, b = 1, 2 %}
Parameters
| Name | Type | Description |
|---|---|---|
node |
— |
Returns
list[ast.stmt]
_compile_export
1
list[ast.stmt]
▼
Compile {% export %} - export variable to outer scope.
Variables assigned with…
_compile_export
1
list[ast.stmt]
▼
def _compile_export(self, node: Any) -> list[ast.stmt]
Compile {% export %} - export variable to outer scope.
Variables assigned with {% export %} are promoted from inner scope (e.g., inside a loop) to the outer scope (e.g., outside the loop).
Supports structural unpacking: {% export a, b = 1, 2 %}
Parameters
| Name | Type | Description |
|---|---|---|
node |
— |
Returns
list[ast.stmt]
_compile_block_scoped_assignment
2
list[ast.stmt]
▼
Compile block-scoped assignment ({% set %}).
Assigns to current scope: _scope_…
_compile_block_scoped_assignment
2
list[ast.stmt]
▼
def _compile_block_scoped_assignment(self, target: Any, value: Any) -> list[ast.stmt]
Compile block-scoped assignment ({% set %}).
Assigns to current scope: _scope_stack[-1][name] = value If no scope exists (top level), falls back to ctx (template-scoped).
Parameters
| Name | Type | Description |
|---|---|---|
target |
— |
|
value |
— |
Returns
list[ast.stmt]
_compile_export_assignment
2
list[ast.stmt]
▼
Compile export assignment ({% export %}).
Export always assigns to ctx (templa…
_compile_export_assignment
2
list[ast.stmt]
▼
def _compile_export_assignment(self, target: Any, value: Any) -> list[ast.stmt]
Compile export assignment ({% export %}).
Export always assigns to ctx (template scope) to ensure the variable persists after blocks end. This matches the common use case of promoting values from loops/conditionals to template scope.
Parameters
| Name | Type | Description |
|---|---|---|
target |
— |
|
value |
— |
Returns
list[ast.stmt]
_compile_assignment
2
list[ast.stmt]
▼
Common logic for template-scoped assignments ({% let %}).
Handles recursive st…
_compile_assignment
2
list[ast.stmt]
▼
def _compile_assignment(self, target: Any, value: Any) -> list[ast.stmt]
Common logic for template-scoped assignments ({% let %}).
Handles recursive structural unpacking using ctx dict for all variables.
Parameters
| Name | Type | Description |
|---|---|---|
target |
— |
|
value |
— |
Returns
list[ast.stmt]