| name | ty |
| description | Use this skill for Python type checking with ty. Activated when:
- Running ty check
- Fixing type errors
- Adding type annotations
|
| version | 0.1.0 |
| globs | ["*.py","pyproject.toml","ty.toml"] |
ty: Python Type Checking
ty is an extremely fast Python type checker and language server. It serves as a modern replacement for mypy and Pyright.
When to Use ty
- Always use for Python type checking
- Look for
[tool.ty] in pyproject.toml or ty.toml config files
- Use when you see type annotations in the codebase
Running ty
uv run ty check .
uvx ty check .
uv run ty check src/main.py
uv run ty check --python-version 3.11 .
Configuration
In pyproject.toml:
[tool.ty]
python-version = "3.11"
[tool.ty.rules]
unresolved-import = "error"
unresolved-attribute = "warning"
invalid-type-form = "error"
[tool.ty.environment]
python = ".venv/bin/python"
Or in ty.toml:
python-version = "3.11"
[rules]
unresolved-import = "error"
[environment]
python = ".venv/bin/python"
Common Type Errors
Unresolved Import
from nonexistent import foo
Type Mismatch
def greet(name: str) -> str:
return f"Hello, {name}"
greet(42)
greet("Alice")
Missing Return Type
def add(a: int, b: int):
return a + b
def add(a: int, b: int) -> int:
return a + b
Optional Handling
def process(value: str | None) -> str:
return value.strip()
def process(value: str | None) -> str:
if value is None:
return ""
return value.strip()
Type Annotation Best Practices
Use Modern Syntax (Python 3.10+)
from typing import List, Dict, Optional, Union
def foo(items: List[str]) -> Optional[Dict[str, int]]:
...
def foo(items: list[str]) -> dict[str, int] | None:
...
Use Type Aliases for Complex Types
type UserId = int
type UserMap = dict[UserId, User]
def get_users() -> UserMap:
...
Annotate Function Signatures
def calculate_total(
items: list[Item],
discount: float = 0.0,
) -> float:
...
Ignoring Errors
When necessary, use targeted ignores:
value = some_dynamic_thing
value = thing
Migration from mypy
| mypy | ty |
|---|
mypy . | ty check . |
# type: ignore | # ty: ignore |
mypy.ini | ty.toml or pyproject.toml |
Integration with Sahaidachny
The agentic loop runs ty check during the Code Quality phase. Type errors will cause the iteration to fail with fix_info listing the type issues to resolve.