Loading...
Loading...
Systematic resolution of pyright/mypy type errors with categorization and fix templates. Use when pyright fails, type errors are reported, adding type annotations, or enforcing type safety. Analyzes Python type errors, categorizes them (missing annotations, incorrect types, generic issues, Optional/None handling), and applies fix patterns. Works with .py files and pyright output.
npx skill4agent add dawiddutoit/custom-claude python-best-practices-type-safetypytest-configurationpython-best-practices-fail-fast-imports# Parse and categorize errors
uv run pyright src/ | python .claude/skills/debug-type-errors/scripts/parse_pyright_errors.py
# Auto-fix missing annotations
python .claude/skills/debug-type-errors/scripts/fix_missing_annotations.py src/file.py --all --dry-run
# Auto-fix Optional handling
python .claude/skills/debug-type-errors/scripts/fix_optional_handling.py src/file.py --dry-run# Run pyright and capture errors
uv run pyright src/ > type_errors.txt
# Analyze errors by category
grep "is not assignable" type_errors.txt
grep "Cannot access member" type_errors.txt
grep "is not defined" type_errors.txt
# Fix using MultiEdit for multiple errors in same file# Project-wide check
uv run pyright src/ --verbose > type_errors.txt
# Specific file check
uv run pyright src/path/to/file.py --verbose
# Check with stats
uv run pyright src/ --stats--verbose--statserror: Type of "variable" is unknown
error: Return type of function is unknown
error: Parameter "param" type is unknownerror: Argument of type "X" cannot be assigned to parameter "Y"
error: Expression of type "X" cannot be assigned to declared type "Y"
error: Type "X" is not assignable to type "Y"error: "None" is not assignable to "X"
error: Argument of type "X | None" cannot be assigned to parameter "X"
error: Object of type "None" cannot be used as iterable valueerror: Type argument "X" is missing
error: Expected 1 type argument
error: Type "X[Y]" is incompatible with "X[Z]"error: Cannot access member "X" for type "Y"
error: "X" is not a known member of "Y"error: Import "X" could not be resolved
error: Stub file not found for "X"references/reference.md# Before
def process_data(data):
return data.strip()
# After
def process_data(data: str) -> str:
return data.strip()# Before
result: ServiceResult[bool] = service.get_data() # Returns ServiceResult[dict]
# After
result: ServiceResult[dict] = service.get_data()# Before
def get_value(config: Settings | None) -> str:
return config.value # Error: config might be None
# After
def get_value(config: Settings | None) -> str:
if not config:
raise ValueError("Config required")
return config.value# Before
items: list = [] # Missing type argument
# After
items: list[str] = []# ❌ WRONG - Sequential edits (wastes tokens)
Edit("file.py", old1, new1)
Edit("file.py", old2, new2)
# ✅ CORRECT - Single MultiEdit operation
MultiEdit("file.py", [
{"old_string": old1, "new_string": new1},
{"old_string": old2, "new_string": new2}
])# Run pyright on specific file
uv run pyright src/path/to/file.py
# Run full type check
uv run pyright src/
# Run quality gates
./scripts/check_all.shsrc/application/services/indexing_service.py:45:5 - error: Return type of "process" is unknown# Before
def process(self, data: dict):
return ServiceResult.success(data)
# After
def process(self, data: dict) -> ServiceResult[dict]:
return ServiceResult.success(data)src/infrastructure/neo4j_repository.py:23:9 - error: Argument of type "Settings | None" cannot be assigned to parameter "settings" of type "Settings"# Before
def __init__(self, settings: Settings | None = None):
self.settings = settings
# After
def __init__(self, settings: Settings):
if not settings:
raise ValueError("Settings required")
self.settings = settingssrc/domain/entities/chunk.py:12:5 - error: Type argument for "list" is missing# Before
class Chunk:
entities: list
# After
class Chunk:
entities: list[str]references/reference.md| Error Pattern | Fix Template |
|---|---|
| Add type annotation |
| Add None check with fail-fast |
| Add generic type parameter |
| Check type narrowing/guards |
| Install stub package or add type: ignore |
SettingsSettings | NoneServiceResult[T]ServiceResult.failure()list[str]listuv pip install pyrightpyrightconfig.jsonscripts/if not param: raise ValueError()