python-type-annotator

A tool for adding missing type annotations to Python code. Type annotations describe what values functions, variables, and class attributes are expected to contain.

In plain words
What is it for?
Use it to annotate Python files or modules, prepare mypy checks in continuous integration, add needed imports, and verify the result with mypy.
Why use it?
It makes Python code easier to understand and checks inferred types with mypy, a tool that finds type-related mistakes.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/luqiang-code/claude-code-skills/python-type-annotator
Any agent
npx skills add luqiang-code/claude-code-skills --skill python-type-annotator
Clone the repo
git clone --depth 1 https://github.com/luqiang-code/claude-code-skills

Made for: Claude Code, Codex.

Per session 51 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 736 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00051 $0.00736
Opus 5 $0.00026 $0.00368
Sonnet 5 $0.00010 $0.00147
Haiku 4.5 $0.00005 $0.00074

Measured yesterday against content hash 13140e5db5b8, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

python-type-annotator scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

community-skills/python-type-annotator/SKILL.md · 91 lines

How it starts

The opening of the file, as written. The whole thing — 91 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Python Type Annotator

Add mypy-compatible type annotations to Python code.

When to Use

  • A Python file/module is missing type hints
  • Preparing to enable mypy in CI
  • User mentions "type hints", "type annotate", "mypy"

When NOT to Use

  • The project doesn't use Python 3.8+ (type syntax differs)
  • Code that's intentionally dynamic (use Any sparingly instead)
  • Third-party library stubs (use types-* packages)

Workflow

  1. Read the target file(s)
  2. For each function without type hints:
    • Analyze usage to infer parameter types
    • Trace return statements to infer return type
    • Use Optional[T] for parameters with None default
    • Use Union[T1, T2] for parameters accepting multiple types
  3. Add from __future__ import annotations if Python < 3.10
  4. Add from typing import ... imports as needed
  5. Run mypy <file> to verify annotations are correct
  6. Fix any type errors found by mypy

Annotation Rules

# Functions — always annotate parameters AND return type
def process_items(items: list[dict[str, Any]], limit: int = 10) -> list[dict[str, Any]]:
    ...

# Use | for unions (Python 3.10+) instead of Union
def get_user(user_id: int) -> dict[str, Any] | None:
    ...

# Class methods — include self/cls (unannotated is fine for self)
class UserService:
    def __init__(self, db: Database) -> None:
        self.db = db

    async def find_by_email(self, email: str) -> User | None:
        ...

# Use Protocol for duck-typed interfaces
from typing import Protocol

class HasName(Protocol):
    name: str

def greet(entity: HasName) -> str:
    return f"Hello, {entity.name}"

Key Principles

  • Prefer built-in generics: list[X] over typing.List[X] (Python 3.9+)
  • Use | None over Optional[X] (Python 3.10+)
  • Any is a last resort — prefer object or a Protocol
  • Don't annotate self or cls parameters
  • Run mypy after annotating — fix all errors before declaring done

Notes

  • Run mypy --strict for the strictest checking
  • If the project has pyproject.toml, check for existing mypy config
  • Don't change runtime behavior — only add annotations
  • For large files, annotate one function at a time, running mypy between each

Read the full file on GitHub · 91 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 91 lines · 51 tokens per session scan A 13140e5db5b8

Subscribe to this mod's changes

python-type-annotator is a skill published in the GitHub repository luqiang-code/claude-code-skills (2 stars, last pushed 3mo ago), licensed MIT. It adds 51 tokens to every session and 736 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.