Repository navigation
Description
Prerequisite for #119 (enforcing `ty check` in CI + pre-commit): `uv run ty check .`
currently reports 496 diagnostics. Root cause for the large majority: stateful
estimator classes (`AMICATorchNG`, `AMICA_NumPy`, MLX backends) initialize
fit-dependent attributes (`self.W`, `self.A`, `self.sphere`, `self.c`,
`self.comp_list`, ...) to `None` in `init` and only assign real tensors/
arrays in `fit()`. ty correctly infers these as `Tensor | None` (etc.) and
flags every downstream use (inside the class's own methods, and in test files
that access `model.W`/`model.A` directly after `fit()`) as a potential
None-subscript/None-attribute/wrong-argument-type error.
Breakdown (excluding `.venv`/stdlib stub false positives):
- `pyAMICA/torch_impl/core.py`: 170
- `pyAMICA/tests/torch_tests/test_ng_sharing.py`: 107
- `pyAMICA/numpy_impl/core.py`: 91
- `pyAMICA/tests/torch_tests/test_ng_backend.py`: 87
- `pyAMICA/tests/torch_tests/test_ng_pdf_families.py`: 35
- `pyAMICA/numpy_impl/data.py`: 27
- `pyAMICA/mlx_impl/core.py`: 24
- remainder scattered across smaller files/tests
Fix approach
Not renaming the public `W`/`A`/`sphere`/... attributes (breaking API change,
used directly by tests/docs) and not silencing with `cast()`/`# type: ignore`
(defeats the point, matches none of this project's "no silent failures"
ethos). Instead: narrow with `assert x is not None` at point of use --
internal EM-loop call sites treat this as an enforced invariant ("trust
internal code", per CLAUDE.md); public accessor methods
(`get_unmixing_matrix`, `get_mixing_matrix`, `transform`, `save`, ...) get a
real `RuntimeError` guard since a user could call them before `fit()`; test
files get an `assert` right after the relevant `fit()` call, which also
documents "fit succeeded" as a precondition for the rest of the test.
Definition of done
- `uv run ty check .` reports 0 diagnostics outside `.venv`/stdlib stubs.
- Full test suite green, no behavior change (this is a type-annotation/
assertion-only change, not a logic change). - Then wire `ty check` into CI (CI: enforce ty type-checking + add pre-commit config (ruff + ty) #119) as a hard gate, plus the pre-commit
config.
Activity
Scope-suppress irreducible mlx.core unresolved-import (2 -> 0)
Fix ty type-check diagnostics repo-wide (496 -> 0) (#124)