# inheritance

URL: /kida/api/template/inheritance/
Section: template
Description: 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.

---

> For a complete page index, fetch /kida/llms.txt.

Open LLM text
(/kida/api/template/inheritance/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Ftemplate%2Finheritance%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Ftemplate%2Finheritance%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Ftemplate%2Finheritance%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Ftemplate%2Finheritance%2Findex.txt)

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.

1Class

## 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]`
