python-typing

Designs, reviews, and verifies Python static type contracts including Protocols, generics, overloads, and narrowing.

Updated Aug 12, 2026
One-click install
npx skills add https://github.com/schattenspiegel/skill-foundry-skills --skill python-typing-schattenspiegel
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-typing
Source: https://github.com/schattenspiegel/skill-foundry-skills/tree/main/skills/python-typing
Command: npx skills add https://github.com/schattenspiegel/skill-foundry-skills --skill python-typing-schattenspiegel

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires mypy, typing_extensions, and includes references (resource) components.

What problem does it solve? Python type annotations are easy to write but hard to get right: incorrect variance, broken overloads, and annotations that pass a checker yet fail at runtime are common. This Skill provides a disciplined workflow for designing, reviewing, debugging, and testing static type contracts so that Protocols, generics, TypedDicts, and narrowing predicates behave correctly under mypy or Pyright and at runtime. ## Core Features & Use Cases - Type contract design: Choose between nominal classes, structural Protocols, TypedDicts, unions, and generic parameters based on runtime semantics, with explicit variance and mutability boundaries. - Evaluated recipes: Anchored patterns for structural reader Protocols, ParamSpec decorators that preserve wrapped signatures, and TypeIs narrowing of unknown mappings to precise TypedDicts, each paired with a verification recipe. - Verification matrix: Run mypy or Pyright in strict mode plus runtime tests covering empty, malformed, and failure inputs, with failure classification routing before any code change. - Use Case: When a decorator silently erases a function's signature, apply the ParamSpec recipe to preserve parameter types through the wrapper, then verify with inspect.signature and a strict mypy run. ## Quick Start Ask the assistant to design or review the type annotations for your Python function, Protocol, or decorator and verify them with mypy or Pyright.

Frequently Asked Questions about python-typing

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

FAQPage Schema
How do I preserve a function signature through a Python decorator?▼

Use ParamSpec with TypeVar to capture the wrapped callable's parameters and return type, and apply functools.wraps to preserve runtime metadata. Verify with inspect.signature and a strict mypy run to confirm both static and runtime behavior.

When should I use Protocol instead of a base class in Python?▼

Use Protocol when a function only needs a narrow structural capability and callers should not be forced into inheritance. Accept the narrowest Protocol the function needs, and remember that mutable protocol attributes are invariant.

What is the difference between TypeGuard and TypeIs for narrowing?▼

TypeIs narrows both the positive and negative branches, but only when its output type is assignable to the input type. TypeGuard narrows only the positive branch, so choose TypeIs when bidirectional narrowing is required.

Does TypedDict validate data at runtime?▼

No, TypedDict is a static mapping shape and remains a plain dict at runtime with no validation. To narrow an unknown mapping at runtime, write a predicate using TypeIs that checks keys and value types explicitly.

Why does mypy pass but my code still fails at runtime?▼

Static correctness does not prove runtime behavior because annotations normally perform no runtime validation. Run the project's configured checker plus runtime tests that exercise empty, malformed, and failure inputs before declaring completion.

When should I avoid using overloads in Python?▼

Use overloads only when argument forms determine return types and the implementation accepts every declared form. If a union return type or a generic parameter expresses the relationship, prefer that simpler contract instead.