Skip to content

chore(ty): close the ty error gate over the last 6 src modules - #523

Merged
wladerer merged 1 commit into
mainfrom
chore/ty-rollout-advance
Sep 26, 2026
Merged

wladerer merged 1 commit into
mainfrom
chore/ty-rollout-advance

Conversation

@wladerer

Copy link
Copy Markdown
Owner

Advances the ty typing rollout by promoting the last unlisted src/gradwave
modules into the error-gated include list in pyproject.toml's
[[tool.ty.overrides]], taking the gate to the whole of src/gradwave.

What changed

Already clean — just listed (each verified with zero error-level diagnostics
by adding it and running ty check, not inferred from absence):

  • src/gradwave/_matmul.py
  • src/gradwave/scf/_woodbury.py
  • src/gradwave/solvers/native/__init__.py

Small annotation/narrowing fix, then listed (no runtime behavior change):

  • src/gradwave/postscf/magnons.py — from_shells' bare list[dict] →
    list[dict[str, Any]]; the two ExchangeBond(...) constructions use cast
    (identity at runtime) to narrow the tuple[int, ...]/tuple[float, ...]
    comprehensions to the fixed 3-tuple fields, replacing the mypy-form
    # type: ignore[arg-type] that ty does not honor; assert model.moments is not None in _local_frames (moments is set unconditionally in __post_init__).
  • src/gradwave/postscf/unfold.py — the None-prefilled coeffs_by_K /
    millers_by_K containers retyped to list[Tensor | None], with an
    assert ... is not None at each read (every unique K is filled before any read).
  • src/gradwave/solvers/native_davidson.py — re-derive the bound Hamiltonian via
    getattr(apply_H, "__self__", None) + assert isinstance(h, BatchedHamiltonian)
    (the exact invariant _unsupported_reason already gates on) so ty sees the
    concrete type instead of a plain Callable's missing __self__.

Also adds a one-line class docstring to the central Input schema
(inputs/models.py).

Behavior

All three Step-B fixes are pure annotation/narrowing: the casts are runtime
identities, and every added assert encodes an invariant that already holds on
all reachable paths (moments set in __post_init__; all unique K filled before
read; the _unsupported_reason gate guarantees the bound BatchedHamiltonian).
No runtime behavior changes.

Validation

  • uv run ty check exits 0 (zero error-level diagnostics; was 9 across the three
    Step-B files before the fixes).
  • uv run ruff check clean.
  • uv run lint-imports clean (7 kept, 0 broken).

Note: this edits pyproject.toml's [[tool.ty.overrides]] include list only; a
sibling PR touches the ruff mccabe setting in a different section, so a trivial
clean rebase is expected.

🤖 Generated with Claude Code

Closes the ty error gate over the last unlisted src/gradwave modules (236/236).
Three were already clean (zero error-level diagnostics, verified by listing and
running `ty check`): _matmul.py, scf/_woodbury.py, solvers/native/__init__.py.
The other three each needed one small annotation/narrowing fix, no runtime
behavior change:

* postscf/magnons.py: from_shells' bare `list[dict]` -> `list[dict[str, Any]]`;
  the two ExchangeBond(...) constructions use `cast` (identity at runtime) to
  narrow the tuple[int,...]/tuple[float,...] comprehensions to the fixed 3-tuple
  fields, replacing the mypy-form `# type: ignore` ty does not honor;
  `assert model.moments is not None` in _local_frames (moments is set
  unconditionally in __post_init__).
* postscf/unfold.py: the None-prefilled coeffs_by_K/millers_by_K containers
  retyped to `list[Tensor | None]`, with an `assert ... is not None` at each read
  (every unique K is filled before any read).
* solvers/native_davidson.py: re-derive the bound Hamiltonian via
  `getattr(apply_H, "__self__", None)` + `assert isinstance(h,
  BatchedHamiltonian)` (the exact invariant _unsupported_reason already gates on)
  so ty sees the concrete type instead of a plain Callable's missing __self__.

Also adds a one-line class docstring to the central `Input` schema.

`uv run ty check` exits 0 (zero errors), `ruff check` and `lint-imports` clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wladerer
wladerer merged commit b1092db into main Sep 26, 2026
15 checks passed
@wladerer
wladerer deleted the chore/ty-rollout-advance branch September 26, 2026 20:53
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