Module

template.inheritance

Template inheritance mixin — block resolution across extends chain.

Requires host class to define slots: _inheritance_chain_cache, _effective_blocks_cache, _extends_target, _local_blocks_sync, _local_blocks_stream, _local_blocks_async_stream, _env_ref, _name. Requires _get_env_limits() method.

Thread-Safety (free-threaded Python 3.14+): Attribute assignment and dict.setdefault are atomic in CPython. The worst case without locking is benign redundant computation — two threads may compute the same immutable chain and both store it. Since results are idempotent, no lock is needed for correctness.

Classes

TemplateInheritanceMixin 3
Mixin for inherited block resolution. Adds _build_local_block_maps, _inheritance_chain, _effective…

Mixin for inherited block resolution.

Adds _build_local_block_maps, _inheritance_chain, _effective_block_map.

Methods

Internal Methods 3
_build_local_block_maps 1 tuple[dict[str, Any], di…
Precompute per-template block function maps from compiled namespace.
staticmethod
def _build_local_block_maps(namespace: dict[str, Any]) -> tuple[dict[str, Any], dict[str, Any], dict[str, Any]]
Parameters
Name Type Description
namespace
Returns
tuple[dict[str, Any], dict[str, Any], dict[str, Any]]
_inheritance_chain 0 tuple[Template, ...] | l…
Return [self, parent, grandparent, ...] for inherited block resolution.
def _inheritance_chain(self) -> tuple[Template, ...] | list[Any]
Returns
tuple[Template, ...] | list[Any]
_effective_block_map 1 dict[str, Any]
Build nearest-child-wins block map for render_block inheritance. kind: "sync" …
def _effective_block_map(self, kind: str) -> dict[str, Any]

Build nearest-child-wins block map for render_block inheritance.

kind: "sync" | "stream" | "async_stream" Returns dict of block_name -> callable for that kind.

Parameters
Name Type Description
kind
Returns
dict[str, Any]