type-safety

Reviews Python code for type hints, generics, protocols, and static type checking compliance.

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/Dazlarus/karl-code --skill type-safety-dazlarus
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: type-safety
Source: https://github.com/Dazlarus/karl-code/tree/main/.agents/skills/type-safety
Command: npx skills add https://github.com/Dazlarus/karl-code --skill type-safety-dazlarus

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python codebases without consistent type annotations are harder to refactor, review, and maintain. This Skill provides a structured checklist and concrete patterns for adding type hints, enabling strict static type checking, and catching type errors before runtime. ## Core Features & Use Cases - Type Annotation Guidance: Enforces complete type hints on all functions, including return types, generics with TypeVar, and variance annotations. - Advanced Typing Patterns: Covers Protocols for structural subtyping, NewType for semantic types, Literal for constrained values, TypedDict for dictionary shapes, and TypeGuard for type narrowing. - Strict Checking Setup: Recommends pyright strict mode configuration and flags unjustified Any usage or type: ignore comments. - Use Case: When reviewing a pull request, activate this Skill to produce a structured type safety review listing missing annotations, unsafe Any usage, and positive patterns with line-by-line fix suggestions. ## Quick Start Review this Python file for type safety issues and suggest complete type hints for every function.

Frequently Asked Questions about type-safety

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

FAQPage Schema
How do I add type hints to Python functions?▼

Add type hints by annotating every parameter and return type, such as def process(data: list[dict], user_id: int) -> list[dict]. Use TypeVar for generic functions and enable pyright strict mode to catch missing annotations.

What is the difference between Protocol and TypedDict in Python typing?▼

Protocol defines structural subtyping for classes, so any object with matching methods satisfies the interface. TypedDict defines the required keys and value types of a dictionary, validating dictionary shapes at type-check time.

How do I enable strict type checking with pyright?▼

Set "typeCheckingMode": "strict" and "pythonVersion": "3.12" in pyrightconfig.json or pyproject.toml. Strict mode flags missing annotations, implicit Any types, and unsafe operations across the codebase.

When should I use NewType instead of a plain type alias?▼

Use NewType when you need semantic distinction, such as UserId = NewType("UserId", int), so the type checker rejects passing a plain int where a UserId is expected. Plain aliases provide no such protection.

When should I not apply strict type safety rules?▼

Skip strict typing during quick prototyping where annotations slow iteration, and on legacy codebases without existing type hints unless you are actively refactoring them. The Skill explicitly excludes these scenarios.