add-or-fix-type-checking

Diagnose and fix mypy, ty, and pyrefly typing errors in Python codebases.

1|1|Updated Apr 21, 2025
One-click install
npx skills add https://github.com/jrp2014/check_models --skill add-or-fix-type-checking-jrp2014
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: add-or-fix-type-checking
Source: https://github.com/jrp2014/check_models/tree/main/.agents/skills/add-or-fix-type-checking
Command: npx skills add https://github.com/jrp2014/check_models --skill add-or-fix-type-checking-jrp2014

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Typing failures from mypy, ty, or pyrefly block CI pipelines and make quality gates, and fixing them requires knowing which narrowing patterns, annotations, and stub strategies each checker accepts. ## Core Features & Use Cases - Multi-checker triage: Runs mypy, ty, and pyrefly individually to build a focused baseline of failing files before fixing anything. - Prioritized fix patterns: Applies a strict fix order from isinstance narrowing and local-variable narrowing through @overload, generics, cast(), and finally targeted # type: ignore[code]. - Stub management: Regenerates third-party stubs in typings/ with make stubs when stub gaps cause errors. - Use Case: A PR fails CI with mypy errors about X | None attribute access; the Skill narrows the union with if x is None: raise, re-runs the checkers, and confirms the full make quality gate passes. ## Quick Start Fix the mypy and ty typing errors reported in src/check_models.py and verify the full quality gate passes.

Frequently Asked Questions about add-or-fix-type-checking

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix mypy errors about X | None attribute access?▼

Narrow the union with an explicit check such as `if x is None: raise ValueError(...)` before accessing attributes. All three checkers (mypy, ty, pyrefly) track this narrowing, including negative isinstance forms. Never use assert for narrowing since it is stripped by python -O.

How to run mypy, ty, and pyrefly on a single Python file?▼

Run mypy from the src directory with `mypy --config-file pyproject.toml <file>`, run ty from the repo root with `make ty`, and run pyrefly through `make quality`. Activate the conda environment first so all checkers resolve the correct interpreter.

When should I use cast() versus @overload in Python typing?▼

Prefer @overload when a method's return type depends on input types, since it gives checkers precise signatures and eliminates casts at call sites. Use cast() only after structural validation when the checker cannot infer the type, and before resorting to type: ignore.

Why does mypy report errors from missing third-party stubs?▼

Third-party packages may ship incomplete stubs missing kwargs or attributes. Regenerate stubs into the typings directory with `make stubs`, which all three checkers reference via mypy_path, extra-paths, and search-path configuration.

When is it acceptable to use # type: ignore?▼

Use it only for genuine third-party stub defects that cannot be solved by narrowing, overloads, generics, or cast. Always include the specific error code such as `# type: ignore[call-arg]` and document the reason; bare ignores are prohibited.