type-hints
Python type hints, type checking, and static analysis with mypy
When & Why to Use This Skill
Enhance your Python development workflow with advanced type hints and static analysis. This skill provides comprehensive support for PEP 484 type annotations, mypy configuration, and structural typing, enabling developers to catch errors early, improve code readability, and leverage powerful IDE features for more maintainable software. It bridges the gap between dynamic flexibility and static safety, ensuring high-quality, production-ready code.
Use Cases
- Automated Static Analysis: Integrate mypy into your development environment to detect type mismatches and logical errors before code execution.
- Legacy Code Modernization: Apply gradual typing strategies to existing Python projects to improve maintainability and clarify complex data structures.
- API Design & Documentation: Use TypeVar, Protocols, and TypedDict to create clear, self-documenting interfaces for libraries and internal frameworks.
- CI/CD Quality Gates: Configure strict type-checking rules in deployment pipelines to enforce coding standards and prevent type-related regressions.
| name | Type Hints |
|---|---|
| description | Python type hints, type checking, and static analysis with mypy |
| version | "2.1.0" |
| sasmp_version | "1.3.0" |
| bonded_agent | 07-best-practices |
| bond_type | PRIMARY_BOND |
| retry_strategy | exponential_backoff |
| logging | true |
| metrics | type_coverage_percent |
Python Type Hints Skill
Overview
Master Python type hints for better code quality, IDE support, and static type checking with mypy.
Topics Covered
Basic Type Hints
- Variable annotations
- Function signatures
- Return types
- Optional types
- Union types
Advanced Typing
- Generic types
- TypeVar and ParamSpec
- Protocol and structural typing
- Literal types
- TypedDict
Type Checking
- mypy configuration
- Strict mode settings
- Type ignore comments
- Stub files (.pyi)
- Type coverage
Runtime Types
- typing_extensions
- Pydantic validation
- Runtime type checking
- Dataclasses with types
- attrs integration
Best Practices
- Gradual typing strategy
- Third-party type stubs
- CI type checking
- Documentation with types
- Type-driven development
Prerequisites
- Python fundamentals
- OOP concepts
Learning Outcomes
- Write type-annotated code
- Configure mypy properly
- Use generic types
- Implement protocols