Skip to content
Back to skills

Python Typing

ASecurity

Use when adding or tightening Python type annotations — annotation policy and strictness, protocols vs ABCs, and pyright configuration in pyproject.toml. Runtime validation models are covered where they live (python-web-api for pydantic in APIs).

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentpythonapidocumentation

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add missing-bits/claude-plugins --skill python-typing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python Typing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Python Typing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/missing-bits-python-typing/badge)](https://www.skillsdirectory.com/skills/missing-bits-python-typing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: python-typing
description: Use when adding or tightening Python type annotations — annotation policy and strictness, protocols vs ABCs, and pyright configuration in pyproject.toml. Runtime validation models are covered where they live (python-web-api for pydantic in APIs).
---

# Python typing

Annotation standards and the type checker. Cite rules in review
findings as `(standard: python-typing, rule: <id>)`. Each rule names
its source: a PEP, the typing spec, an official doc, or `this standard`
(a recorded house decision).

## Type checker — pyright, watching ty

pyright is the standard type checker: typing-spec conformance, speed,
pydantic v2 support without plugins, and parity with Pylance in the
editor. Astral's `ty` is the watched successor — revisit this choice when
`ty` reaches a stable release; until then it is not part of the toolchain.

Run it as `uv run pyright`; configuration lives in `pyproject.toml`
under `[tool.pyright]` — canonical block in
[reference/pyright-config.toml](reference/pyright-config.toml).
(id: `typing-pyright`; severity: minor; source: the Python typing spec —
typing.python.org — for conformance, pyright documentation for
configuration; the tool choice is this standard)

## Annotation policy

- **Every public function and method is fully annotated** (PEP 484 is
  the foundation) — parameters and return type, including `-> None`.
  Private helpers may rely on inference when the types are obvious from
  one screen of context. (id: `typing-public-api`; severity: important;
  source: PEP 484; the public-minimum policy is this standard)
- **Modern syntax only**: `X | None` over `Optional[X]` (PEP 604),
  `list[str]` over `List[str]` (PEP 585), `collections.abc`
  (`Iterable`, `Callable`) over their deprecated `typing` twins. ruff
  `UP` enforces this. (id: `typing-modern-syntax`; severity: minor;
  source: PEP 604, PEP 585)
- **No `Any` laundering**: an `Any` that enters at a boundary is
  narrowed or validated before it spreads; `cast()` carries a comment
  saying why it is safe. (id: `typing-no-any-laundering`; severity:
  important; source: PEP 484 defines `Any`'s escape-hatch semantics;
  the laundering ban is this standard)

## Strictness

New projects run pyright in **strict** mode. An adopted codebase starts
in `standard` mode with per-directory `strict` overrides, ratcheting up
— never down. Blanket `# type: ignore` is banned; each ignore names the
error code (`# type: ignore[arg-type]`) and survives only with a reason.
(id: `typing-strictness`; severity: minor; source: pyright
documentation — `typeCheckingMode`; the strict-for-new /
ratchet-for-adopted policy is this standard)

Sub-rules:
- an unexplained `# type: ignore` (no error code, or no reason) (id:
  `typing-strictness.unexplained-ignore`; severity: important)

## Protocols vs ABCs

- **Protocol** (structural, PEP 544) when you own the call site but not
  the implementations — plugins, adapters, anything third parties
  provide.
- **ABC** (nominal) when you own the hierarchy and want shared behavior
  or invariants enforced in a base class.
- Never both for one seam. Worked example:
  [reference/typing-patterns.md](reference/typing-patterns.md).
(id: `typing-protocol-vs-abc`; severity: minor; source: PEP 544 for
Protocol, the CPython `abc` module docs for ABCs; the when-which rule
is this standard)

Files in this skill

  • SKILL.md3.3 KB
  • reference/pyright-config.toml580 B
  • reference/typing-patterns.md2.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.