python-type-safety

Configure mypy or pyright for strict static type checking of Python code.

Updated Mar 3, 2026
One-click install
npx skills add https://github.com/jacexh/skills --skill python-type-safety-jacexh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-type-safety
Source: https://github.com/jacexh/skills/tree/main/skills/python-type-safety
Command: npx skills add https://github.com/jacexh/skills --skill python-type-safety-jacexh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill reduces runtime type-related bugs by applying static type annotations, generics, protocols, and strict type checking so developers catch issues earlier in development and CI.

Core Features & Use Cases

  • Comprehensive type guidance: Annotate public APIs, functions, methods, and class attributes for clearer contracts and better tooling support.
  • Generic and protocol patterns: Create reusable, type-preserving generics and structural interfaces for libraries and services.
  • Tooling and CI configuration: Configure mypy or pyright for strict checking, incremental adoption, and CI enforcement to prevent regressions.

Quick Start

Annotate public functions and classes with explicit type hints and run mypy in strict mode to validate types across the codebase.

Frequently Asked Questions about python-type-safety

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

FAQPage Schema
How do I add static type checking to Python code to catch runtime errors?

Static type checking in Python uses type hints on public APIs to detect incorrect types early. You annotate functions and classes, then run tools like mypy in strict mode to validate types across the codebase.

What is the best way to configure mypy or pyright for strict type validation in CI?

Configuring mypy or pyright for strict type validation involves enabling strict mode and CI enforcement to prevent regressions. This setup applies automated validation to ensure all type annotations are checked continuously.

How do I use Python generics and protocols to build type-safe libraries?

Python generics and protocols build type-safe libraries by creating reusable, type-preserving structures and structural interfaces. Generics preserve types across operations, while protocols define structural typing for flexible contracts.

Can I incrementally adopt type hints in an existing Python codebase without breaking it?

Incremental adoption of type hints in existing Python codebases is supported by configuring mypy or pyright for gradual checking. You can annotate public APIs first, then expand strictness to prevent regressions during migration.

What are type narrowing patterns in Python and when do I need them?

Type narrowing patterns in Python refine types within conditional branches, ensuring static checkers recognize safe operations. You need them when using protocols or generics to guarantee type safety during dynamic runtime checks.