Skip to content

Type-check numba in the pyrefly hook; follow-up fixes to #51 - #52

Open
mcdigman wants to merge 3 commits into
devfrom
typecheck-deps-numba
Open

mcdigman wants to merge 3 commits into
devfrom
typecheck-deps-numba

Conversation

@mcdigman

Copy link
Copy Markdown
Owner

Targets dev. Follow-up to #51, carrying review fixes that were written for it but not pushed before it merged, plus the numba typing change they led to.

Changes

Use the stored PN reduced spin in TaylorF2. TaylorF2_aligned_inplace re-derived chi_pn = chis*(1 - 76/113*eta) + delta*chia inline, while BinaryIntrinsicParamsManager already computes the same value as chi_postnewtonian. The removed IMRPhenomD module was that field's only reader, so it had become dead in production. TaylorF2 now reads params_intrinsic.chi_postnewtonian. Aligned-spin waveform output (F, TF, TFp, PF, AF with amplitude_pn_mode=2 and nonzero spins) is bit-identical before and after.

Make the spin checks in test_binary_load round-trip. The local chi_postnewtonian_reference helper added in #51 only built the packed input; every spin assertion compared manager fields to each other. The test now also checks that chi_postnewtonian_norm, chi_postnewtonian, chi_a, chi_s, chi_1z, chi_2z and chi_eff recovered by the manager match the test inputs. The tolerance on the spins scales like the existing mass_delta tolerance for nearly equal masses. Flipping the sign of the delta*chia term in the helper now fails the test; before, it passed.

Type-check numba in the pyrefly hook. numba ships py.typed since 0.66, so the hook now installs numba>=0.66 and numba is removed from [tool.pyrefly].ignore-missing-imports. The rationale comments in pyproject.toml and .pre-commit-config.yaml, which #51 had reworded to say numba ships no py.typed, are corrected.

Use pyrefly-specific ignores on prange loops. With real numba types, pyrefly reports for ... in prange(...) as not iterable. Pyright does not: it infers prange(...) as range from numba's __new__. The eight existing # type: ignore[not-iterable] comments were therefore only needed by pyrefly, and pyright reports them as unnecessary when reportUnnecessaryTypeIgnoreComment is on. They are now # pyrefly: ignore[not-iterable], which pyright does not inspect.

Dependency audit

Every third-party import in the tracked Python files was checked against what the pyrefly hook and the pyright CI job install. Nothing else is missing.

Package pyrefly hook pyright CI job
numpy, matplotlib, pytest installed, py.typed installed
numba installed, py.typed (new) base dependency
scipy, h5py, pandas stub packages installed
PyYAML types-PyYAML dev extra
jsonschema installed, inferred from source dev extra
astropy, WDMWaveletTransforms ignored, no py.typed installed

Verification

  • tests/test_binary_load.py: 13689 passed
  • tests/test_algebra_tools.py: 24646 passed
  • pyrefly hook on all files: 0 errors. Compared with the previous hook environment without numba, the only new diagnostics are the eight prange loops, all covered by the ignores above.
  • pyright: 0 errors locally
  • mypy with the CI flags and numba not installed, as in CI: no issues in 75 files
  • prek on all changed files: passed

Known

  • pyright CI stays red on the pre-existing tests/test_wavemaket.py:150 error (np.gradient return type under numpy 2.5.3 stubs). It is unrelated and unchanged here.
  • mypy with numba visible reports the prange loops as attr-defined. The CI mypy job does not install numba, so this does not affect CI. The old type: ignore[not-iterable] comments did not cover it either.

🤖 Generated with Claude Code

…ix numba py.typed comment

- TaylorF2_aligned_inplace now reads params_intrinsic.chi_postnewtonian
  instead of re-deriving the PN reduced spin inline; the manager was
  already computing it and the removed IMRPhenomD module was its only
  reader. Waveform output is bit-identical.
- test_binary_load asserts that chi_s, chi_a, chi_1z, chi_2z, chi_eff and
  chi_postnewtonian recovered from the packed chi_postnewtonian_norm match
  the test inputs, so chi_postnewtonian_reference is now load-bearing.
- Correct the pyrefly rationale comments: numba ships py.typed since 0.66;
  it stays ignored only because it is not installed in the hook env.
numba ships py.typed since 0.66, so install numba>=0.66 in the pyrefly
hook environment and drop it from [tool.pyrefly].ignore-missing-imports.
The only errors real numba types surface are eight `for ... in prange(...)`
not-iterable errors, all already covered by existing
`# type: ignore[not-iterable]` comments; the hook stays at 0 errors.
Pyright infers prange(...) as range from numba's __new__ and never
flags these loops, so the generic `# type: ignore[not-iterable]` was
only needed by pyrefly and showed up as an unnecessary ignore under
pyright's reportUnnecessaryTypeIgnoreComment. Switch the eight loops
to `# pyrefly: ignore[not-iterable]`, which pyright does not inspect.
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