Skip to content

fix: drop mypy python_version pin that numpy 2.5 stubs now reject - #2

Merged
oneKn8 merged 1 commit into
mainfrom
fix/mypy-target-numpy-pep695-stubs
Oct 11, 2026
Merged

oneKn8 merged 1 commit into
mainfrom
fix/mypy-target-numpy-pep695-stubs

Conversation

@oneKn8

@oneKn8 oneKn8 commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

What failed

The type-check job in .github/workflows/ci.yml fails on an unchanged tree. mypy src/undertone/ --ignore-missing-imports exits 2 without checking any of our own code:

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)

The lint job and all three legs of the test matrix 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:

numpy mypy mypy src/undertone/
2.4.4 1.20.0 exit 0 — Success: no issues found in 18 source files
2.5.3 2.3.1 exit 2 — stub syntax error
2.5.3 1.20.0 exit 2 — stub syntax error
2.4.4 2.3.1 exit 0 — Success: no issues found in 18 source files

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-python to >=3.12 and, now free to use 3.12-only syntax, rewrote numpy/__init__.pyi with PEP 695 type aliases (65 of them, against 0 in 2.4.x).

[tool.mypy] pinned python_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 — the python_version pin 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:

[[tool.mypy.overrides]]
module = "numpy.*"
follow_imports = "skip"

mypy still exits 2 with the same error — the stub is parsed before follow_imports is applied, so the collision can't be scoped away per-module.

No source changes, no test changes, no dependency changes. requires-python stays at >= 3.10, and the floor is still guarded: ruff's target-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:

lint       (py3.12)   ruff check ...          EXIT=0   All checks passed!
                      ruff format --check ... EXIT=0   30 files already formatted
type-check (py3.12)   mypy src/undertone/     EXIT=0   Success: no issues found in 18 source files
test       (py3.10)   pytest tests/           EXIT=0   172 passed
test       (py3.11)   pytest tests/           EXIT=0   172 passed
test       (py3.12)   pytest tests/           EXIT=0   172 passed

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:

src/undertone/sounds.py:32: error: Returning Any from function declared to return "ndarray[Any, Any]"  [no-any-return]

This is not caused by this PR — it reproduces identically with the original unmodified pyproject.toml on that same interpreter, since the pin and the inferred target are both 3.10 there. CI's type-check job 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.

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.
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 991c21c8-1c97-48eb-8ecc-84a1390d3742


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@oneKn8
oneKn8 merged commit 1f565d0 into main Oct 11, 2026
6 checks passed
@oneKn8
oneKn8 deleted the fix/mypy-target-numpy-pep695-stubs branch October 11, 2026 06:11
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.

2 participants