python-type-safety

Enforce strict Python type safety with mypy and pyright static analysis.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Python's dynamic typing leads to runtime errors and fragile codebases. This skill provides guidance and patterns to introduce explicit type hints, generics, and structural typing using tools like mypy and pyright, improving reliability and maintainability.

Core Features & Use Cases

  • Type annotations everywhere: annotate functions, classes, and data models to unlock static analysis.
  • Generics & Protocols: build reusable, type-safe components with structural typing.
  • Tooling & CI: configure strict mypy/pyright checks in continuous integration to catch regressions early.
  • Real-world use case: migrate a legacy module to be fully typed and validated by static analysis.

Quick Start

Add type hints to an existing module and run mypy --strict to reveal and fix type errors.

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 strict type safety to my Python codebase?

Strict type safety in Python is enforced by adding type hints to functions and data models, then running static analysis tools like mypy or pyright in strict mode to catch type errors before runtime.

What is the best way to build reusable generics with TypeVar in Python?

Generics with TypeVar in Python allow you to build reusable, type-safe components by defining parameterized classes and functions, enabling structural typing and strict validation via mypy and pyright.

How do I use Protocols for structural typing in Python?

Protocols enable structural typing in Python by defining implicit interfaces, allowing static type checkers like mypy and pyright to validate that classes implement the required methods without explicit inheritance.

Can I configure mypy and pyright strict checks in CI for Python libraries?

Yes, you can configure strict mypy and pyright checks in your continuous integration pipeline to automatically catch type regressions and enforce type safety across Python libraries and APIs.

How do I migrate a legacy Python module to be fully typed?

Migrating a legacy Python module to be fully typed involves progressively adding type annotations to existing functions and data models, then resolving static analysis errors reported by running mypy --strict.

Why does Python dynamic typing cause runtime errors and how to prevent it?

Python dynamic typing causes runtime errors because type mismatches are only checked during execution. You prevent this by applying PEP 484+ type hints and validating code with static analysis tools like mypy or pyright.