Classes
WithBlockMixin
2
▼
Mixin for compiling with-block statements.
Host attributes and cross-mixin dependencies are declar…
WithBlockMixin
2
▼
Mixin for compiling with-block statements.
Host attributes and cross-mixin dependencies are declared via inline TYPE_CHECKING blocks.
Methods
Internal Methods 2 ▼
_compile_with
1
list[ast.stmt]
▼
Compile {% with var=value, ... %}...{% endwith %.
Creates temporary variable b…
_compile_with
1
list[ast.stmt]
▼
def _compile_with(self, node: With) -> list[ast.stmt]
Compile {% with var=value, ... %}...{% endwith %.
Creates temporary variable bindings scoped to the with block. We store old values and restore them after the block.
Parameters
| Name | Type | Description |
|---|---|---|
node |
— |
Returns
list[ast.stmt]
_compile_with_conditional
1
list[ast.stmt]
▼
Compile {% with expr as target %}...{% end %} (conditional form).
Renders body…
_compile_with_conditional
1
list[ast.stmt]
▼
def _compile_with_conditional(self, node: WithConditional) -> list[ast.stmt]
Compile {% with expr as target %}...{% end %} (conditional form).
Renders body only if expr is truthy. Binds expr result to target. Supports multiple bindings and structural unpacking. Provides nil-resilience: block is silently skipped when expr is falsy.
Generates:
_with_val_N = expr
if _with_val_N:
# [save old values]
# [bind new values]
... body ...
# [restore old values]
Parameters
| Name | Type | Description |
|---|---|---|
node |
— |
Returns
list[ast.stmt]