Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aiskillstore avatar

Python Typing Patterns

  • 1 installs
  • 404 repo stars
  • Updated August 5, 2026
  • aiskillstore/marketplace

python-typing-patterns is a skill that provides modern Python type-hint patterns and mypy/pyright configuration for type-safe code.

About

This skill covers Python type hints and type-safety patterns for Python 3.10+. It includes annotations, collections, Union and Optional, TypedDict, Callable, Generics, Protocols, type guards, and Literal or Final. A developer uses it to add type safety and to configure mypy or pyright.

  • Modern Python type hints for 3.10+ union syntax
  • TypedDict, Protocol, Generics, TypeGuard, Literal, Final
  • mypy and pyright commands and config

Python Typing Patterns by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #240 of 290 Python skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
At a glance

python-typing-patterns capabilities & compatibility

Capabilities
refactoring · code review
Use cases
refactoring · code review
Pricing
Free
From the docs

What python-typing-patterns says it does

Python type hints and type safety patterns. Triggers on: type hints, typing, TypeVar, Generic, Protocol, mypy, pyright, type annotation, overload, TypedDict.
SKILL.md
Modern type hints for safe, documented Python code.
SKILL.md
npx skills add https://github.com/aiskillstore/marketplace --skill python-typing-patterns

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
repo stars404
Last updatedAugust 5, 2026
Repositoryaiskillstore/marketplace

What it does

Add modern Python type hints and configure mypy or pyright for type-safe code.

Who is it for?

Python developers adding type hints or configuring static type checkers.

Skip if: Runtime schema validation beyond type hints, or non-Python languages.

When should I use this skill?

Adding type annotations, using TypeVar/Protocol/TypedDict, or running mypy or pyright.

What you get

Produces type-safe Python code with TypedDict, Protocol, Generics, and a mypy/pyright config.

  • typed Python code
  • mypy/pyright config

By the numbers

  • 9-row typing quick-reference table
  • 6 reference docs plus a pyproject typing config asset

Files

SKILL.mdMarkdownGitHub ↗

Python Typing Patterns

Modern type hints for safe, documented Python code.

Basic Annotations

# Variables
name: str = "Alice"
count: int = 42
items: list[str] = ["a", "b"]
mapping: dict[str, int] = {"key": 1}

# Function signatures
def greet(name: str, times: int = 1) -> str:
    return f"Hello, {name}!" * times

# None handling
def find(id: int) -> str | None:
    return db.get(id)  # May return None

Collections

from collections.abc import Sequence, Mapping, Iterable

# Use collection ABCs for flexibility
def process(items: Sequence[str]) -> list[str]:
    """Accepts list, tuple, or any sequence."""
    return [item.upper() for item in items]

def lookup(data: Mapping[str, int], key: str) -> int:
    """Accepts dict or any mapping."""
    return data.get(key, 0)

# Nested types
Matrix = list[list[float]]
Config = dict[str, str | int | bool]

Optional and Union

# Modern syntax (3.10+)
def find(id: int) -> User | None:
    pass

def parse(value: str | int | float) -> str:
    pass

# With default None
def fetch(url: str, timeout: float | None = None) -> bytes:
    pass

TypedDict

from typing import TypedDict, Required, NotRequired

class UserDict(TypedDict):
    id: int
    name: str
    email: str | None

class ConfigDict(TypedDict, total=False):  # All optional
    debug: bool
    log_level: str

class APIResponse(TypedDict):
    data: Required[list[dict]]
    error: NotRequired[str]

def process_user(user: UserDict) -> str:
    return user["name"]  # Type-safe key access

Callable

from collections.abc import Callable

# Function type
Handler = Callable[[str, int], bool]

def register(callback: Callable[[str], None]) -> None:
    pass

# With keyword args (use Protocol instead)
from typing import Protocol

class Processor(Protocol):
    def __call__(self, data: str, *, verbose: bool = False) -> int:
        ...

Generics

from typing import TypeVar

T = TypeVar("T")

def first(items: list[T]) -> T | None:
    return items[0] if items else None

# Bounded TypeVar
from typing import SupportsFloat

N = TypeVar("N", bound=SupportsFloat)

def average(values: list[N]) -> float:
    return sum(float(v) for v in values) / len(values)

Protocol (Structural Typing)

from typing import Protocol

class Readable(Protocol):
    def read(self, n: int = -1) -> bytes:
        ...

def load(source: Readable) -> dict:
    """Accepts any object with read() method."""
    data = source.read()
    return json.loads(data)

# Works with file, BytesIO, custom classes
load(open("data.json", "rb"))
load(io.BytesIO(b"{}"))

Type Guards

from typing import TypeGuard

def is_string_list(val: list[object]) -> TypeGuard[list[str]]:
    return all(isinstance(x, str) for x in val)

def process(items: list[object]) -> None:
    if is_string_list(items):
        # items is now list[str]
        print(", ".join(items))

Literal and Final

from typing import Literal, Final

Mode = Literal["read", "write", "append"]

def open_file(path: str, mode: Mode) -> None:
    pass

# Constants
MAX_SIZE: Final = 1024
API_VERSION: Final[str] = "v2"

Quick Reference

TypeUse Case
`X \None`
list[T]Homogeneous list
dict[K, V]Dictionary
Callable[[Args], Ret]Function type
TypeVar("T")Generic parameter
ProtocolStructural typing
TypedDictDict with fixed keys
Literal["a", "b"]Specific values only
FinalCannot be reassigned

Type Checker Commands

# mypy
mypy src/ --strict

# pyright
pyright src/

# In pyproject.toml
[tool.mypy]
strict = true
python_version = "3.11"

Additional Resources

  • ./references/generics-advanced.md - TypeVar, ParamSpec, TypeVarTuple
  • ./references/protocols-patterns.md - Structural typing, runtime protocols
  • ./references/type-narrowing.md - Guards, isinstance, assert
  • ./references/mypy-config.md - mypy/pyright configuration
  • ./references/runtime-validation.md - Pydantic v2, typeguard, beartype
  • ./references/overloads.md - @overload decorator patterns

Scripts

  • ./scripts/check-types.sh - Run type checkers with common options

Assets

  • ./assets/pyproject-typing.toml - Recommended mypy/pyright config

---

See Also

This is a foundation skill with no prerequisites.

Related Skills:

  • python-pytest-patterns - Type-safe fixtures and mocking

Build on this skill:

  • python-async-patterns - Async type annotations
  • python-fastapi-patterns - Pydantic models and validation
  • python-database-patterns - SQLAlchemy type annotations

Related skills

FAQ

Which Python version does this target?

Python 3.10+ using the X | Y union syntax, with some patterns needing 3.11+.

Does it cover runtime validation?

Its references mention Pydantic v2, typeguard, and beartype for runtime validation.

Pythonbackend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.