| name | types |
| description | Python Type Hint Generator |
| lifecycle | experimental |
/types - Python Type Hint Generator
Add type hints to untyped Python code.
Usage
/types path/to/file.py # Add types to specific file
/types path/to/module/ # Add types to all files in module
/types --check # Report type coverage without changes
/types --strict # Use strict typing (no Any)
What This Skill Does
- Analyze Code - Parse functions, classes, variables
- Infer Types - From usage, defaults, docstrings
- Add Annotations - Function signatures, class attributes
- Import Types - Add necessary typing imports
- Validate - Run mypy to verify additions
Type Inference Rules
From Default Values
def greet(name, count=1):
...
def greet(name: str, count: int = 1) -> None:
...
From Usage
def process(items):
for item in items:
item.upper()
return len(items)
def process(items: list[str]) -> int:
...
From Docstrings
def fetch(url):
"""
Fetch data from URL.
Args:
url: The URL to fetch
Returns:
Response data as dict
"""
def fetch(url: str) -> dict:
...
Common Patterns
list[str]
dict[str, int]
set[int]
tuple[str, int]
str | None
Optional[str]
Callable[[int, str], bool]
int | str
Any
Output Format
## Type Hints Added: path/to/file.py
### Summary
- Functions typed: 12/15
- Classes typed: 3/3
- Variables typed: 8/10
- Type coverage: 87%
### Changes Made
```python
# Line 23: Added parameter and return types
- def process(data):
+ def process(data: list[dict[str, Any]]) -> ProcessResult:
# Line 45: Added class attribute types
+ items: list[Item]
+ cache: dict[str, bytes]
Imports Added
from typing import Any
from collections.abc import Callable
Unable to Infer
- Line 67:
unknown_param - insufficient context
- Line 89:
dynamic_result - runtime-dependent
## Instructions for Claude
When /types is invoked:
1. **Read the file** - Parse Python AST
2. **Find untyped code** - Functions, methods, class attributes
3. **Infer types** - From defaults, usage, docstrings
4. **Prefer modern syntax** - `list[str]` over `List[str]`
5. **Use | for unions** - `str | None` over `Optional[str]`
6. **Add imports** - Only what's needed
7. **Avoid Any** - Unless truly dynamic
8. **Validate with mypy** - Check additions are correct
9. **Report coverage** - Before/after type coverage