# type_checker

URL: /kida/api/analysis/type_checker/
Section: analysis
Description: Template type checker for Kida.

Validates that template variables match ``{% template %}`` declarations.
Catches typos, missing variables, and undeclared context access at
compile time.

Usage::

    from kida.analysis.type_checker import check_types
    issues = check_types(template_ast)
    for issue in issues:
        print(f"Line {issue.lineno}: {issue.message}")

CLI::

    kida check --typed templates/

---

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

Open LLM text
(/kida/api/analysis/type_checker/index.txt)

Share with AI

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

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

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

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

Module

#
`analysis.type_checker`

Template type checker for Kida.

Validates that template variables match`{% template %}`declarations.
Catches typos, missing variables, and undeclared context access at
compile time.

Usage::

```
from kida.analysis.type_checker import check_types
issues = check_types(template_ast)
for issue in issues:
    print(f"Line {issue.lineno}: {issue.message}")
```

CLI::

```
kida check --typed templates/
```

2Classes3Functions

## Classes

`TypeIssue`

5

▼

A single type-checking finding.

A single type-checking finding.

#### Attributes

Name
Type
Description

`lineno`

`int`

—

`col_offset`

`int`

—

`rule`

`str`

—

`message`

`str`

—

`severity`

`str`

—

`_TypeCheckVisitor`

12

▼

Collects variable references and local bindings for type checking.

Collects variable references and local bindings for type checking.

#### Methods

`visit_Name`

1

▼

`def visit_Name(self, node: Name) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

`visit_Set`

1

▼

`def visit_Set(self, node: Set) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

`visit_Let`

1

▼

`def visit_Let(self, node: Let) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

`visit_Export`

1

▼

`def visit_Export(self, node: Export) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

`visit_Capture`

1

▼

`def visit_Capture(self, node: Capture) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

`visit_For`

1

▼

`def visit_For(self, node: For) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

`visit_With`

1

▼

`def visit_With(self, node: With) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

`visit_Def`

1

▼

`def visit_Def(self, node: Def) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

`visit_Import`

1

▼

`def visit_Import(self, node: Import) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

`visit_FromImport`

1

▼

`def visit_FromImport(self, node: FromImport) -> None`

##### Parameters

Name
Type
Description

`node`
`—`

Internal Methods
2

▼

`__init__`

1

▼

`def __init__(self, declared_names: frozenset[str]) -> None`

##### Parameters

Name
Type
Description

`declared_names`
`—`

`_add_target_names`

1

▼

Extract names from for-loop target (single name or tuple).

`def _add_target_names(self, target: Node) -> None`

##### Parameters

Name
Type
Description

`target`
`—`

## Functions

`_suggest_typo`

2

`str | None`

▼

Suggest a declared name if the given name looks like a typo.

`def _suggest_typo(name: str, candidates: list[str]) -> str | None`

##### Parameters

Name
Type
Description

`name`
`str`

`candidates`
`list[str]`

##### Returns

`str | None`

`_edit_distance_one`

2

`bool`

▼

Check if two strings have edit distance <= 1.

`def _edit_distance_one(a: str, b: str) -> bool`

##### Parameters

Name
Type
Description

`a`
`str`

`b`
`str`

##### Returns

`bool`

`check_types`

1

`list[TypeIssue]`

▼

Type-check a template against its ``{% template %}`` declarations.

If the temp…

`def check_types(template: Template) -> list[TypeIssue]`

Type-check a template against its`{% template %}`declarations.

If the template has no`{% template %}`declaration, returns an
empty list (no declarations = no constraints).

##### Parameters

Name
Type
Description

`template`
`Template`

Parsed Template AST node.

##### Returns

`list[TypeIssue]`
