python-type-safety

Add type hints, generics, and protocols to Python code with mypy or pyright strict mode.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Many Python codebases lack consistent type annotations, which leads to runtime errors, unclear APIs, and brittle refactors; this Skill helps developers surface and fix type-related issues at static analysis time so bugs are caught before runtime.

Core Features & Use Cases

  • Annotate public APIs: Add or enforce type hints on functions, methods, and class attributes to make contracts explicit.
  • Generics and TypeVars: Create reusable, type-preserving containers and abstractions for safer APIs.
  • Protocols and Structural Typing: Define interfaces without inheritance to enable duck-typed but type-checked code.
  • Type narrowing and guards: Use conditional checks to narrow union types for safer downstream usage.
  • CI enforcement: Configure mypy or pyright in strict mode to catch regressions during continuous integration.
  • Use Case: Incrementally add strict typing to a legacy service, enable mypy --strict in CI, and eliminate a class of runtime errors during deployments.

Quick Start

Use the python-type-safety skill to add or validate type annotations across a codebase, enable mypy strict mode, and report remaining 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 checking to a Python codebase?

To add strict type checking to a Python codebase, apply static type annotations to public APIs and configure mypy or pyright strict mode in CI to catch type errors at static analysis time.

What is the best way to use generics and TypeVars for type-safe Python APIs?

The best way to use generics and TypeVars for type-safe Python APIs is to create reusable, type-preserving containers and abstractions, ensuring safer APIs and consistent type checking.

How do protocols and structural typing work in Python?

Protocols and structural typing in Python work by defining interfaces without inheritance, enabling duck-typed but type-checked code to catch type errors before runtime.

Can I use mypy and pyright for CI enforcement of type hints?

Yes, you can use mypy and pyright for CI enforcement by configuring strict mode to catch type regressions during continuous integration and eliminate runtime errors during deployments.

How do I narrow union types in Python for safer downstream usage?

To narrow union types in Python for safer downstream usage, use conditional checks and type guards to narrow union types, ensuring safer downstream usage and preventing type errors.

When should I use modern union syntax for Python type annotations?

You should use modern union syntax for Python type annotations when adding type hints to public APIs, satisfying requirements for annotated functions, methods, and class attributes.