Strict pyrefly checking: type torch/_numpy/_funcs_impl.py (#194529)
Removes `# mypy: ignore-errors` from torch/_numpy/_funcs_impl.py and enables strict
pyrefly checking via a per-file sub-config, with no net-new pyrefly errors.
_funcs_impl.py is the numpy-compat function layer; its functions are decorated by
`@normalizer` (in _funcs.py), which dispatches on the string form of each
parameter annotation. Existing marker annotations (ArrayLike, OutArray, etc.) are
preserved unchanged; only return types and previously-unannotated parameters were
added. The one sanctioned marker change is `casting: CastingModes | None` ->
`casting: CastingModes` (the `| None` is spurious -- the casting normalizer raises
on None), which lets casting flow into _util's str-typed helpers cleanly.
Several torch ops accept arguments at runtime that their stubs do not model
(scalar/tensor bounds, `axis=` aliases, python-type dtypes); those calls carry
targeted `# pyrefly: ignore` comments. Two latent bugs surfaced and are preserved
here (not fixed, since a fix needs a failing test first) with comments flagging
them: arange(step=None) raises rather than treating None as 1, and fill_diagonal's
empty-val branch passes a tensor to Tensor.fill_diagonal_ (which requires a
scalar).
Test Plan:
No net-new pyrefly errors (156 before and after):
pyrefly check
Behavior unchanged:
python -m pytest test/torch_np/ -q
Lint clean:
lintrunner -a torch/_numpy/_funcs_impl.py
Authored with Claude.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/194529
Approved by: https://github.com/Skylion007 A
Aaron Orenstein committed
988dc63f869224e8d58ddf2a2b0ba8d5e30d9f73
Parent: c2143af
Committed by PyTorch MergeBot <pytorchmergebot@users.noreply.github.com>
on 8/25/2026, 10:37:42 PM