Skip to content

Static type checking in CI via mypy + baseline ratchet (WIP) - #248

Open
naumitch wants to merge 3 commits into
NVIDIA:developfrom
naumitch:nicholas/static-type-checks-in-ci
Open

Static type checking in CI via mypy + baseline ratchet (WIP)#248
naumitch wants to merge 3 commits into
NVIDIA:developfrom
naumitch:nicholas/static-type-checks-in-ci

Conversation

@naumitch

Copy link
Copy Markdown

WIP — foundation + first burndown slice. Strategy & contributor guide: docs/source/internals/type_checking.md.

  • Adds mypy to CI, gated on new errors only via a committed .mypy-baseline.txt ratchet — green from day one; never blocks PRs on the ~450 pre-existing errors.
  • Ships a py.typed marker so consumers (e.g. Megatron-LM) receive Energon's type annotations.
  • Config + tooling: [tool.mypy] pragmatic floor; mypy/mypy-baseline/types-* in the dev extra (uv.lock regenerated); just typecheck / typecheck-baseline / typecheck-progress recipes; typecheck.yml mirroring ruff.yml.
  • First burndown: graduates 10 already-clean modules to per-module strict and fixes 19 var-annotated errors → baseline 471 → 450. No runtime change beyond one behaviour-preserving list() materialization.
  • Guarantees (documented): no new type debt admitted, backlog can only shrink, fixes are annotation-only unless they change behaviour (then a test is required).
  • Verified: full unittest suite passes (138 tests); ruff, license-header, and type-check gates green.

🤖 Generated with Claude Code

naumitch and others added 3 commits June 23, 2026 16:05
Introduce static type checking that is green from day one and never blocks CI
on pre-existing debt.

- Add mypy + mypy-baseline + type stubs to the dev extra; regenerate uv.lock.
- Add [tool.mypy] (pragmatic floor) and [tool.mypy-baseline] config.
- Commit .mypy-baseline.txt (471 pre-existing errors) so CI fails only on NEW
  type errors; the baseline is the burndown ledger and can only shrink.
- Ship a py.typed marker so consumers (e.g. Megatron-LM) get our annotations.
- Add justfile recipes (typecheck / typecheck-baseline / typecheck-progress)
  and a typecheck.yml workflow mirroring ruff.yml.
- Document the strategy and contributor workflow in
  docs/source/internals/type_checking.md (wired into the toctree) and link it
  from CONTRIBUTING.md.

No runtime code changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Nicholas Autio Mitchell <naumitch@nvidia.com>
…ated

Demonstrate the baseline ratchet end-to-end:

- Graduate 10 fully-strict-clean modules (incl. the public loader.py and
  source_info.py) to per-module strict via [[tool.mypy.overrides]], locking
  them so they cannot regress to loose typing.
- Fix 19 of 20 var-annotated errors with precise variable annotations across
  12 modules (the 20th, in lint.py, is left in the baseline because annotating
  it perturbs unrelated overload inference).
- Materialize a Sequence into a list in MetadatasetV2.prepare() so 'files' is
  consistently list[EPath] (behaviour-preserving).

Baseline shrinks 471 -> 450 errors (63 -> 60 files). Gate stays green.
Full unittest suite passes (138 tests).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Nicholas Autio Mitchell <naumitch@nvidia.com>
Make the type-checking doc front-load what contributors actually need:

- New 'TL;DR - what this means for you': the no-negative-impact guarantees in
  plain language (PRs are not blocked by old errors, you never fix code you did
  not touch, no runtime risk, the backlog can only shrink).
- New 'Using it day to day': the simple loop, a green/red gate table, and how to
  lock a finished file in. Replaces the terse bottom cheat-sheet.
- Relabel the metrics as the starting baseline (live count via
  just typecheck-progress); fix stale numbers and a leftover 'pipefail' reference
  that contradicted the corrected gate recipe.

Docs build clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Nicholas Autio Mitchell <naumitch@nvidia.com>
@naumitch
naumitch marked this pull request as ready for review June 24, 2026 22:17
@naumitch
naumitch force-pushed the nicholas/static-type-checks-in-ci branch from dbf2cb3 to 9b2121c Compare June 25, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant