Repository navigation
fix: drop mypy python_version pin that numpy 2.5 stubs now reject - #2
Merged
Merged
Conversation
numpy 2.5.0 raised its own requires-python to >=3.12 and rewrote numpy/__init__.pyi using PEP 695 `type` aliases. The type-check job runs on Python 3.12, so the resolver now picks numpy 2.5.x there, and because [tool.mypy] pinned python_version to our 3.10 floor, mypy applied 3.10 syntax rules to those stubs and bailed out: numpy/__init__.pyi:737: error: Type statement is only supported in Python 3.12 and greater [syntax] Found 1 error in 1 file (errors prevented further checking) That aborts the run before any of our own modules are checked, so the type-check job fails on an unchanged tree. Lint and the full test matrix are unaffected. A per-module override for numpy does not help: mypy parses the stub before follow_imports applies. Letting mypy follow the running interpreter does, and keeps the check meaningful on every version we support. requires-python stays at >=3.10; ruff's target-version = "py310" and the 3.10 leg of the test matrix continue to guard the floor.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
What failed
The
type-checkjob in.github/workflows/ci.ymlfails on an unchanged tree.mypy src/undertone/ --ignore-missing-importsexits 2 without checking any of our own code:The
lintjob and all three legs of thetestmatrix are unaffected.Control run
The last commit here is dated 2026-03-30. Rebuilt the environment with the dependency set as of that date (
uv pip install --exclude-newer 2026-03-31 -e ".[dev]") on the same Python 3.12 the job uses:mypy src/undertone/It passed then and fails now, so this is a genuine regression rather than something that was already broken. Holding mypy fixed and moving only numpy reproduces the failure; holding numpy fixed and moving only mypy does not. The numpy upgrade is the cause.
Root cause
numpy 2.5.0 raised its own
requires-pythonto>=3.12and, now free to use 3.12-only syntax, rewrotenumpy/__init__.pyiwith PEP 695typealiases (65 of them, against 0 in 2.4.x).[tool.mypy]pinnedpython_version = "3.10"to match our declared floor. mypy applies that target version when parsing third-party stubs too, not just our own sources — so on the 3.12 interpreter the type-check job sets up, where the resolver picks numpy 2.5.x, it parses 3.12-only stub syntax under 3.10 rules and aborts.The two halves of the configuration have drifted apart: the installed stubs track the interpreter, while the analysis target was frozen at our floor.
What changed
One line in
pyproject.toml— thepython_versionpin is removed, so mypy follows the interpreter it runs under. A comment records why, so the pin doesn't get reinstated.A narrower fix that keeps the pin does not work; I tried it first:
mypy still exits 2 with the same error — the stub is parsed before
follow_importsis applied, so the collision can't be scoped away per-module.No source changes, no test changes, no dependency changes.
requires-pythonstays at>= 3.10, and the floor is still guarded: ruff'starget-version = "py310"and the 3.10 leg of the test matrix both continue to run.Verification
Every CI job's exact commands, after the change:
Pre-existing issue left alone
Running mypy on a Python 3.10 interpreter (where the resolver picks numpy 2.2.6, whose stubs are less precise) reports one error under
warn_return_any:This is not caused by this PR — it reproduces identically with the original unmodified
pyproject.tomlon that same interpreter, since the pin and the inferred target are both 3.10 there. CI'stype-checkjob only runs on 3.12, so it is outside both the failing gate and the scope of this change. Flagging it so it isn't a surprise; it needs a separate decision about whether to annotate the return or leave it.