type-strengthener

Audits Python type safety using targeted mutations to find errors the type checker misses.

Updated Apr 3, 2021
One-click install
npx skills add https://github.com/shrik450/dotfiles --skill type-strengthener-shrik450
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-strengthener
Source: https://github.com/shrik450/dotfiles/tree/main/dot_claude/skills/type-strengthener
Command: npx skills add https://github.com/shrik450/dotfiles --skill type-strengthener-shrik450

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Python code often passes type checking while still allowing plausible mistakes—misspelled fields, swapped identifiers, lost generic relationships, or unvalidated external data—to slip through to runtime. This Skill audits a Python codebase to find where stronger types would let the configured checker catch more errors before they reach production. ## Core Features & Use Cases - Mutation-based gap detection: Applies targeted edits (renames, retypes, added enum variants, broken generic relationships) in a temporary copy and runs the project's checker to find consumers that receive no error. - Type improvement recommendations: Reviews Any usage, casts, dynamic access, weak domain models, boundary validation, and lost type relationships, then recommends concrete designs such as NewType, TypedDict, tagged unions, ParamSpec, and protocols. - Prioritized report: Produces decision cards ranked by priority, evidence level, and effort, with verified compatibility across the project's Python, checker, and typing_extensions versions. - Use Case: Before merging a large refactor, run the audit to confirm that renaming a field or adding an enum variant would actually fail type checking in every consumer, and get a ranked list of type designs that close the gaps. ## Quick Start Ask the AI to audit the type safety of your Python project with the type-strengthener skill and report which plausible mistakes the current type checker fails to catch.

Frequently Asked Questions about type-strengthener

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

FAQPage Schema
How do I find type safety gaps in my Python code?

Run a mutation-based audit that applies plausible edits—renaming fields, changing types, adding enum variants—to a temporary copy of your code and reruns your type checker. Consumers that receive no new error reveal gaps where stronger types would help.

How to test whether mypy or pyright catches a specific mistake?

Create a small probe file with one valid use and one plausible misuse of the type design, then run the project's exact checker command. Use assert_type or reveal_type when inference matters, and test both branches for narrowing functions.

Does this work with pyright, basedpyright, and other type checkers?

The audit uses whichever checker the project already configures rather than introducing a new one. The mutation script parses pyright and basedpyright JSON output directly, and supports any other checker through a custom command template.

When should I use NewType versus a dataclass value object?

Use NewType for a low-cost static distinction between same-typed values like UserId and OrderId when no runtime behavior is needed. Choose a frozen dataclass or validated value object when construction must enforce rules at runtime.

Why does my type checker pass code that still breaks at runtime?

Common causes include Any propagation, unchecked casts, excluded paths, nonblocking CI jobs, and untyped libraries erasing type information. Confirm coverage by adding a deliberate invalid assignment in a temporary copy and verifying the checker reports it.

Can newer typing features like TypeIs or ReadOnly be used on older Python versions?

Support must be verified separately for syntax parsing, runtime objects, typing_extensions backports, checker behavior, and runtime annotation consumers. The audit builds a capability profile and probes each feature with the project's exact versions before recommending it.