python-typing-patterns

Provide Python typing patterns for type safety with mypy and pyright.

29|6|Updated Nov 27, 2025
One-click install
npx skills add https://github.com/0xDarkMatter/claude-mods --skill python-typing-patterns
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-typing-patterns
Source: https://github.com/0xDarkMatter/claude-mods/tree/main/skills/python-typing-patterns
Command: npx skills add https://github.com/0xDarkMatter/claude-mods --skill python-typing-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill builds a strong typing foundation for Python projects with patterns for type hints, generics, Protocols, and TypedDict.

Core Features & Use Cases

  • Basic to advanced typing patterns
  • Generics, Protocols, TypedDicts, and Literal types
  • Type checking guidance with mypy/pyright

Quick Start

Add type hints to a function and explore static checks with a type checker.

Frequently Asked Questions about python-typing-patterns

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

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

Type hints annotate function parameters and return values with expected types, enabling static type checkers like mypy and pyright to catch errors before runtime. Use basic syntax like `def func(x: int) -> str:` and advance to generics, Protocols, and TypedDict for complex data structures in Python 3.10+.

What are Protocols and TypedDict, and when should I use them instead of classes?▼

Protocols enable structural typing—objects matching a method signature work interchangeably without inheritance. TypedDict defines typed dictionaries with fixed keys and value types. Use Protocols for flexible interfaces and TypedDict for type-safe dictionary data models without class overhead.

How do I use generics and TypeVar to write reusable, type-safe code?▼

TypeVar creates type variables; generics parameterize functions and classes to work with multiple types while preserving type safety. Use `T = TypeVar('T')` and `class Container(Generic[T]):` to write code once that type-checks correctly across different input types.

Can I use type hints with mypy and pyright for IDE hints and static checking?▼

Yes. mypy and pyright integrate with type hints to provide real-time IDE hints, catch type mismatches before runtime, and validate against function signatures. Configure via `mypy.ini` or `pyrightconfig.json` to enforce typing across your Python 3.10+ project.

How do I validate types at runtime in addition to static type checking?▼

Static type checkers verify code at development time but don't enforce checks at runtime. Add runtime validation using `isinstance()` checks, Pydantic models, or type-guard decorators to catch type violations when code executes with unexpected data.

What are Literal types and overload, and how do I use them for precise type definitions?▼

Literal restricts values to specific constants (e.g., `Literal['read', 'write']`). Overload allows multiple valid type signatures for one function. Together they express precise input-output contracts for code generation, type-safe APIs, and utilities with context-dependent behavior.