python-type-hints

Write and validate Python 3.12+ type hints with PEP 695 and TypedDict.

Updated Jan 24, 2026
One-click install
npx skills add https://github.com/amaozhao/MySkills --skill python-type-hints
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-type-hints
Source: https://github.com/amaozhao/MySkills/tree/main/skills/python-type-hints
Command: npx skills add https://github.com/amaozhao/MySkills --skill python-type-hints

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing Python code with clear, strong type hints reduces runtime errors and improves maintainability, especially when leveraging Python 3.12+ features like PEP 695 type parameters, TypedDict with Required/NotRequired/ReadOnly, Final, Self, and LiteralString.

Core Features & Use Cases

  • Modern syntax support: unions with |, type aliases via type, and TypedDict enhancements for precise input shapes.
  • Advanced type constructs: Final constants and Self type to support fluent APIs and safe recursive patterns.
  • Safe SQL hints: LiteralString for restricting risky or dynamic SQL text.
  • Use cases: applying strong typing in new projects, gradually typing existing code, or designing robust library APIs.

Quick Start

Create a small Python snippet that demonstrates a function using a union type, a TypedDict with a required field and an optional field, and a class method using Self. Run a type checker (e.g., mypy or Pyright) to observe type validations.

Frequently Asked Questions about python-type-hints

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

FAQPage Schema
How do I use Python 3.12 type hints like PEP 695 type parameters?

Python 3.12 type hints using PEP 695 type parameters allow defining generics inline. This skill guides you in writing modern syntax with type aliases via the type keyword to improve type safety in new projects or library APIs.

What is the best way to type Python dictionaries with required and optional fields?

TypedDict enhancements provide precise input shapes for Python dictionaries. You can mark specific fields as Required or NotRequired, ensuring type checkers validate both mandatory and optional keys accurately during code refactoring.

How do I restrict dynamic SQL text using Python type hints?

LiteralString restricts risky or dynamic SQL text in Python. By applying this type hint, you prevent SQL injection vulnerabilities by ensuring type checkers enforce only statically known string values are passed to database queries.

Can I use the Self type hint to support fluent APIs and safe recursive patterns?

The Self type hint supports fluent APIs and safe recursive patterns in Python classes. It accurately annotates methods that return an instance of the current class, ensuring type checkers correctly validate method chaining and inheritance.

Does this Python type hinting approach work for gradually typing existing code?

Yes, this approach works for gradually typing existing code. You can incrementally introduce strong typing using modern constructs like Final constants and union types with the pipe operator to reduce runtime errors without a full rewrite.

What are the limitations of using ReadOnly with TypedDict in Python?

ReadOnly with TypedDict prevents modification of dictionary values after creation. While it improves maintainability and type safety, it requires a modern Python 3.12+ environment and compatible type checkers like Pyright to enforce these immutability constraints.