python-type-system

Add type annotations and configure mypy for static type checking.

1|Updated Jun 18, 2025
One-click install
npx skills add https://github.com/knopki/dotfiles --skill python-type-system-knopki
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-type-system
Source: https://github.com/knopki/dotfiles/tree/main/home/private_dot_config/opencode/skills/python-type-system
Command: npx skills add https://github.com/knopki/dotfiles --skill python-type-system-knopki

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you write more robust, maintainable, and understandable Python code by leveraging its advanced type hinting and static analysis capabilities.

Core Features & Use Cases

  • Type Hinting: Add type annotations to your Python code for improved readability and IDE support.
  • Static Type Checking: Use tools like mypy to catch type errors before runtime.
  • Advanced Typing: Utilize Protocol, TypedDict, Generic, Literal, and TypeGuard for sophisticated type definitions.
  • Use Case: Ensure that a function expecting a list of strings actually receives one, preventing runtime errors and making code easier to refactor.

Quick Start

Configure mypy for strict type checking in your Python project.

Frequently Asked Questions about python-type-system

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

FAQPage Schema
How do I use Python type hints to catch errors before runtime?

Python type hints combined with static analysis tools like mypy catch type errors before runtime by checking annotations against actual code usage. This prevents common runtime failures and improves overall code maintainability.

What is the best way to define structural subtyping in Python?

Structural subtyping in Python is defined using Protocol classes. Protocols allow you to specify implicit structural types, enabling static type checkers to verify that objects implement the required methods without needing explicit inheritance.

When should I use generics instead of Any in my Python project?

Use generics when you need to preserve type relationships across function inputs and outputs, such as ensuring a function returning a list item matches the input list type. Avoid Any when strict type checking is required for complex projects.

How do I narrow union types with TypeGuard for safer function returns?

TypeGuard narrows union types by allowing custom type checking functions to inform static analysis tools. This enables mypy to understand complex runtime checks, ensuring subsequent code operates on the correctly narrowed type.

Does mypy support strict type checking for complex Python projects?

Yes, mypy supports strict type checking configurations for complex Python projects. It validates primitive types, collections, generics, and advanced typing constructs like protocols and literals to enforce type safety across the codebase.