Repository navigation
chore(ty): close the ty error gate over the last 6 src modules - #523
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Advances the
tytyping rollout by promoting the last unlistedsrc/gradwavemodules into the error-gated include list in
pyproject.toml's[[tool.ty.overrides]], taking the gate to the whole ofsrc/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.pysrc/gradwave/scf/_woodbury.pysrc/gradwave/solvers/native/__init__.pySmall annotation/narrowing fix, then listed (no runtime behavior change):
src/gradwave/postscf/magnons.py—from_shells' barelist[dict]→list[dict[str, Any]]; the twoExchangeBond(...)constructions usecast(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 Nonein_local_frames(moments is set unconditionally in__post_init__).src/gradwave/postscf/unfold.py— theNone-prefilledcoeffs_by_K/millers_by_Kcontainers retyped tolist[Tensor | None], with anassert ... is not Noneat each read (every unique K is filled before any read).src/gradwave/solvers/native_davidson.py— re-derive the bound Hamiltonian viagetattr(apply_H, "__self__", None)+assert isinstance(h, BatchedHamiltonian)(the exact invariant
_unsupported_reasonalready gates on) so ty sees theconcrete type instead of a plain
Callable's missing__self__.Also adds a one-line class docstring to the central
Inputschema(
inputs/models.py).Behavior
All three Step-B fixes are pure annotation/narrowing: the
casts are runtimeidentities, and every added
assertencodes an invariant that already holds onall reachable paths (moments set in
__post_init__; all unique K filled beforeread; the
_unsupported_reasongate guarantees the boundBatchedHamiltonian).No runtime behavior changes.
Validation
uv run ty checkexits 0 (zero error-level diagnostics; was 9 across the threeStep-B files before the fixes).
uv run ruff checkclean.uv run lint-importsclean (7 kept, 0 broken).Note: this edits
pyproject.toml's[[tool.ty.overrides]]include list only; asibling PR touches the ruff mccabe setting in a different section, so a trivial
clean rebase is expected.
🤖 Generated with Claude Code