npx skills add ...
npx skills add wshobson/agents --skill python-type-safety
Python type safety with type hints, generics, protocols, and strict type checking. Use when adding type annotations, implementing generic classes, defining structural interfaces, or configuring mypy/pyright.
npx skills add wshobson/agents --skill python-type-safety
Leverage Python's type system to catch errors at static analysis time. Type annotations serve as enforced documentation that tooling validates automatically.
Declare expected types for function parameters, return values, and variables.
Write reusable code that preserves type information across different types.
Define structural interfaces without inheritance (duck typing with type safety).
Use guards and conditionals to narrow types within code blocks.
Every public function, method, and class should have type annotations.
Use mypy --strict or pyright in CI to catch type errors early. For existing projects, enable strict mode incrementally using per-module overrides.
Python 3.10+ provides cleaner union syntax.
Use conditionals to narrow types for the type checker.
Create type-safe reusable containers.
Detailed sections (starting with ## Advanced Patterns) live in references/details.md. Read that file when the navigation summary above is insufficient.
T | None - Modern union syntax over Optional[T]mypy --strict in CIAny - Use specific types or generics. Any is acceptable for truly dynamic data or when interfacing with untyped third-party code