Stub Drift
When the library updates, your stub can fall behind. Typhon catches drift via two tools:
tyc check --stubs— AST-level diff between the.dtyand the sibling.ty/.py.tyc stubtest— runtime introspection viapython -m mypy.stubtest.
Both are useful; neither subsumes the other.
tyc check --stubs (AST diff)
Compares every .dty against the runtime symbols of the implementation module:
tyc check --stubsSurfaces:
- Names declared in the stub but missing at runtime.
- Names present at runtime but missing in the stub.
- Signature drift (parameter shapes, return types).
Reported as tyc::stub_mismatch diagnostics.
What it sees
The AST diff sees what the parser sees:
- Top-level functions and classes.
- Class methods and fields.
- Parameter shapes (name, type, default-present-or-not).
What it doesn’t see
- Dynamically-injected attributes (
__init_subclass__, metaclass tricks). - Pydantic auto-generated fields.
- Attributes set by
__init__rather than declared.
For those, use tyc stubtest.
tyc stubtest (runtime introspection)
Runs python -m mypy.stubtest on every emitted .pyi:
tyc stubtestImports the module at build time and introspects the actual runtime symbols — catches dynamic surface the AST can’t see. Requires mypy installed in the chosen interpreter.
Combine both
For thorough CI:
- name: Stub drift (AST) run: tyc check --stubs
- name: Stub drift (runtime) run: tyc stubtest -- --allowlist stubtest-allow.txtThe runtime probe is slower (it imports the module), so consider nightly rather than per-PR if compile-time matters.
Recommended workflow
- Write the stub.
src/stubs/<library>.dty(anywhere under your configuredsrc/directory). - Run
tyc check --stubsto verify the AST surface matches. - Run
tyc stubtestto catch dynamic mismatches. - Add both to CI so library upgrades surface drift immediately.
When the library upgrades:
- CI catches the drift.
- Update the stub (or pin the library version until you do).
- Re-run.
Allowlists for unavoidable drift
mypy.stubtest supports --allowlist FILE for entries you want to ignore:
some_module._internal_helpersome_module.OldDeprecatedClassUse sparingly — every allowlisted entry is one the checker won’t catch in future.
Where next
- Writing .dty Stubs — stub authoring.
tyc check --stubs— the AST-diff command.tyc stubtest— the runtime-probe command.