/tiran-skills:ship-type-informationfrom tiran-skills
Adds type annotations to untyped Python code, generates .pyi stubs for compiled C/C++/Rust extensions, ships py.typed marker per PEP 561, and verifies type completeness with mypy, pyright, ty, and stubtest. Use when asked to make a package typed or fix 'module is untyped' errors.
Ships in tiran-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Status: Experimental — grounded in PEP 561, the typing spec, and the current stub-generation tooling (linked below); the workflow is a new draft. Have a human review the generated annotations and stubs — every generator produces drafts.
Make a package's types real, complete, verified, and shipped so downstream users
and their checkers see actual signatures instead of Any. Three problems, often
combined: untyped Python source (add annotations), compiled extensions that are
opaque to type checkers (ship .pyi stubs), and types that exist but never reach
users (declare with py.typed and package them). This skill covers all three and the
verification that keeps them honest.
An extension module or an un-marked package types as Any for every consumer:
incorrect calls pass silently, editors give no completion, and the annotations you
did write reach no checker. py.typed + stubs turn that into real static checking
across mypy, pyright, ty, and pyrefly — a one-time cost that every downstream user
benefits from. Stubs are also Python-version-agnostic, so one set covers an abi3
/ stable-ABI wheel across all versions. For the fuller case (and expert sources to cite
when convincing a maintainer), see reference/why-types.md.
--verifytypes.Guardrails. Read
../GUARDRAILS.mdand follow it: work in a project-local.venvwith uv (uvxfor one-off tools); never touch global/user site-packages; get existing code committed to VCS before editing (ask the user); don't commit/push without approval (never straight tomain); keep comments terse. Auto-generated annotations and stubs are drafts — review them.
Bundled references — open each at the step that cites it:
reference/why-types.md — a primer on why annotations are worth it, with expert
sources (empirical, industrial, and PEP 484 rationale) — for convincing a maintainer.reference/annotating.md — adding annotations to untyped Python (autotyping,
infer-types, pyrefly infer, MonkeyType, com2ann, ruff/pyupgrade); static-vs-runtime
trade-off; strictness ramp.reference/stubs.md — .pyi stubs for compiled extensions per binding (nanobind,
pybind11, PyO3, Cython stubgen-pyx, mypy stubgen), hand-written C
(__text_signature__), pattern files, placement, the CI freshness gate.reference/verify-and-ship.md — checkers (mypy / pyright --verifytypes / ty /
pyrefly), stubtest, PEP 561 packaging (inline vs stubs-beside vs stub-only dist),
and verifying the built wheel carries the type files.Definition of done: the package ships py.typed (or a stub-only distribution);
compiled extensions have committed .pyi that stubtest validates against the
runtime module; mypy, pyright, ty, and pyrefly pass; pyright --verifytypes reports
the intended completeness; the built wheel actually contains the type files; and a CI
gate keeps stubs fresh. Nothing committed without the user's OK.
Establish what's there before changing anything:
py.typed marker and a Typing :: Typed classifier? Are
there existing .pyi files?uvx pyright --verifytypes <import_name> --ignoreexternal
Note what resolves to Any/Unknown (untyped defs vs the opaque extension).Decide scope: annotate untyped Python (step 2), stub the extensions (step 3), or both — then declare (4), verify (5), ship (6).
Only if there's untyped Python source. Deterministic first, review always — every
tool emits drafts. From reference/annotating.md:
autotyping (None/bool returns, trivial params) across the tree.pyrefly infer (formerly autotype) and/or infer-types
add argument/return types without running code (deterministic).MonkeyType (via pytest-monkeytype) records types your test
suite exercises that static analysis can't resolve; apply, then review.com2ann for legacy type comments; ruff/pyupgrade for modern
syntax (PEP 604 X | None, PEP 585 list[...], collections.abc over typing
aliases), gated on the project's requires-python floor (3.11 is a good default
today; 3.10 is the floor for bare X | Y at runtime — see reference/annotating.md).ignore.Untyped dependencies leak Any into your code. At the import boundary, cheapest
first: install published stubs (types-<pkg> / <pkg>-stubs), else write local stubs
in a stubs/ dir, else wrap the dep in a small typed facade, else suppress narrowly
(per-module ignore_missing_imports).
Model structured data (independent of the above) — prefer a real type over a bare
dict/tuple for JSON/config/records: a TypedDict to describe dict-shaped data,
or a @dataclass / attrs / pydantic when you own the model. See
reference/annotating.md.
Checkers don't import compiled modules, so ship .pyi. Pick the generator by binding
(details, commands, and pattern-file examples in reference/stubs.md):
| Binding | Generator |
|---|---|
| nanobind | nanobind's stubgen / nanobind_add_stub (best fidelity via __nb_signature__) — defer to pybind11-to-nanobind |
| pybind11 | pybind11-stubgen |
| Rust / PyO3 | pyo3-stub-gen |
| Cython | stubgen-pyx (parses source, keeps your PEP 484 annotations; bint→bool) |
| hand-written C / fallback | mypy stubgen (runtime-introspects; most types default to Any) |
For hand-written C, expose __text_signature__ (a signature line in the method's
docstring) so introspection tools recover the signature, and ship a hand-written .pyi
for the types. (CPython's Argument Clinic emits __text_signature__ for the stdlib but
is a CPython-internal tool, not supported for third-party use — hand-write the docstring
signature instead.) Patch what generators can't express
(overloads, tuple-widening, None-returning getters, version strings) via nanobind
pattern files or manual edits.
From reference/verify-and-ship.md:
py.typed marker file in the package root — required for checkers
to read either inline annotations or adjacent .pyi beside the modules..pyi next to the
.so, py.typed present) vs a stub-only distribution (<pkg>-stubs) when the
stubs must live apart or you're typing a third-party package you don't own.partial\n marker is stub-only-package-specific: a partial <pkg>-stubs
distribution puts partial\n in its py.typed so checkers merge it with the runtime
package. An inline package's py.typed is empty — there is no inline "partial"
marker; unannotated code simply infers or falls back to Any.Typing :: Typed classifier (see
modernize-python-metadata).Types are only real if a checker confirms them:
uvx mypy <pkg>, uvx pyright <pkg>, uvx ty check,
uvx pyrefly check — from a consumer's perspective; libraries shipping stubs
benefit from the cross-check (they disagree at the edges).pyright --verifytypes <pkg> --ignoreexternal — the type-completeness score;
drive it up to the intended level.stubtest — uvx --from mypy stubtest <import_name> checks each .pyi matches
the runtime module (missing/extra/mismatched symbols); the decisive stub QA.Types that aren't in the wheel don't exist:
py.typed and every .pyi in the wheel — package-data / MANIFEST.in
(setuptools), force-include / default (hatchling), install_sources (meson-python),
maturin include. reference/verify-and-ship.md has the per-backend snippets.uv build, then unzip / check-wheel-contents):
confirm py.typed and the .pyi files are actually present at the right paths.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
type-annotations, pyi-stubs, pep-561, type-checking, stub-generation
Other plugins' skills for the same job
npx claudepluginhub tiran/agent-skills --plugin tiran-skills12 skills in this plugin
/bootstrap-python-projectScaffold a new Python project from zero: src/ layout, PEP 621 metadata, a chosen build backend (hatchling for pure Python; meson-python / scikit-build-core / maturin for compiled) with dynamic VCS versioning, py.typed, ruff, a type checker, pytest + coverage, tox or nox via uv, and hardened GitHub Actions CI (SHA-pinned, Trusted Publisher, CodeQL/Scorecard/Dependabot). Always writes a README, LICENSE, and .gitignore. Orchestrates the choose-python-build-backend, modernize-python-metadata, ship-type-information, and secure-python-release-pipeline skills. Use when asked to start a new package, scaffold/bootstrap a Python project, set up a repo from zero, turn a loose script into a proper package, or bring an existing project up to this standard (adopt the layout, metadata, tooling, or CI it lacks)./choose-python-build-backendRecommend the right PEP 517 build backend for a new or existing Python package, and give enough context to migrate. Chooses by three axes: purelib (pure Python) vs platlib (compiled C/C++/Rust/Torch), static vs dynamic/VCS metadata, and native language/build system. Covers uv-build, flit-core, hatchling (incl. compiled via scikit-build-core[hatchling] / a custom build hook), meson-python, scikit-build-core, maturin, and setuptools (legacy). Weighs compiled-project concerns: Cython, PyTorch extensions, pybind11/nanobind bindings, the stable Python ABI (abi3 / limited API), and fast parallel builds (CMake+Ninja, Meson). Use when asked "which build backend should I use", to pick a backend for a new project, or to decide whether to move an existing project off setuptools./crypto-fips-auditAudit a Python package — and any C/C++/Go/Rust code it ships — for its use of cryptography, across three use cases: inventory what crypto a package uses at all (algorithms, providers, linkage, RNG, CA stores), find insecure or weak cryptography, and assess FIPS 140-3 / NIST compliance. Flags insecure use of approved primitives (AES-ECB, RSA PKCS#1 v1.5, static IV/nonce, `random` for secrets, timing-unsafe compares, disabled TLS verification), weak RSA/EC key sizes, and — for FIPS — refused hashes (MD5, MD4, RIPEMD-160), restricted ones (SHA-1), non-approved primitives (BLAKE2/3, ChaCha20-Poly1305, 3DES, scrypt/Argon2/bcrypt, X25519/X448 key agreement, secp256k1), vendored or statically linked crypto (bundled OpenSSL/BoringSSL/AWS-LC/NSS/GnuTLS/libgcrypt/ nettle/libsodium) that escapes the system validated module, hardcoded TLS versions/ciphers that bypass crypto-policies, bundled CA trust stores, and problematic PyPI deps (bcrypt, pycryptodome, pynacl, ecdsa, rsa, m2crypto, …). Source-first, then confirmed against the built wheel/binaries. Gathers evidence; does not certify compliance./modernize-python-metadataImprove a Python package's metadata and move it into a PEP 621 [project] table in pyproject.toml — filling in what's missing along the way. Covers the readme field (dropping the open().read() hack), SPDX license expressions, trove classifiers, well-known project URLs, authors/keywords/requires-python, dependency version constraints (avoid upper caps), PEP 735 dependency groups vs extras, and the build-system table. Keeps the existing build backend (setuptools is fine). Includes a Poetry → PEP 621 migration lens (the [tool.poetry] field map and caret/tilde → floor translation; PDM too). Use when asked to clean up packaging metadata, move metadata out of setup.py/setup.cfg, migrate a Poetry (or PDM) project to [project]/PEP 621, or improve a project's PyPI page./port-to-free-threaded-pythonMake a Python package work correctly on the free-threaded (no-GIL) CPython build (PEP 703; the cp313t/cp314t "t" ABI) and declare that it does, so importing it does not silently re-enable the GIL. Covers the pure-Python thread-safety pass (mutable global/class state, caches, contextvars vs threading.local) and, for C/C++/Cython/pybind11/nanobind/Rust-PyO3 extensions, declaring support (Py_mod_gil / PyUnstable_Module_SetGIL / the per-binding flag), fixing data races with critical sections (Py_BEGIN_CRITICAL_SECTION), PyMutex, atomics and thread-local state, the borrowed-reference hazards and their strong-reference replacements (PyList_GetItemRef, PyDict_GetItemRef), building cp3Xt wheels (meson-python, scikit-build-core, maturin, setuptools, cibuildwheel), and testing under load with ThreadSanitizer and pytest-run-parallel. Use to add free-threading / no-GIL / nogil / free-threaded / PEP 703 support, ship a cp313t/cp314t wheel, or stop the GIL being re-enabled. For a single stable-ABI abi3t wheel (3.15+) pair it with port-to-python-limited-api./port-to-meson-pythonBuild a Python package (usually with a compiled C/C++/Cython/Fortran/Rust extension) with the meson-python PEP 517 backend, or port one off a bespoke setuptools setup.py. Covers the pyproject.toml backend, the meson.build (project / extension_module / install_sources), VCS/dynamic versioning computed in meson.build, editable installs, config-settings, and abi3 / limited-API wheels. Use when asked to adopt meson-python or Meson, scaffold a new meson-python project, drop setup.py, or produce standards-based wheels.