Skip to content

ci(pre-commit): pin numpy<2.2 for mypy stub compatibility#1491

Open
dimitri-yatsenko wants to merge 1 commit into
masterfrom
fix/mypy-numpy-pep695
Open

ci(pre-commit): pin numpy<2.2 for mypy stub compatibility#1491
dimitri-yatsenko wants to merge 1 commit into
masterfrom
fix/mypy-numpy-pep695

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

The mypy pre-commit hook fails on a clean checkout:

numpy/__init__.pyi:737: error: Type statement is only supported in Python 3.12 and greater  [syntax]

Cause

The hook’s additional_dependencies pull an unpinned numpy (currently 2.5.1). numpy ≥2.2 ships type stubs written with PEP 695 type statements. mypy refuses that syntax when type-checking against python_version = "3.10" (our support floor, per [tool.mypy]), so the hook errors out before checking any of our code. Bumping mypy (tested through v1.18.2) does not help — the gate is the target version, not the mypy release.

Fix

Pin the mypy hook’s stub dependency to numpy<2.2. This only affects the stubs used for type-checking; runtime numpy is unaffected (unpinned elsewhere). Keeping the target at 3.10 preserves floor coverage rather than masking it by raising python_version.

Verification

  • pre-commit run --all-files → all hooks pass (mypy included).

numpy>=2.2 ships type stubs using PEP 695 `type` statements, which mypy
rejects while type-checking against python_version=3.10 (the project floor):
`numpy/__init__.pyi: error: Type statement is only supported in Python 3.12+`.
Pin the mypy hook's stub dependency to numpy<2.2 so the hook passes; runtime
numpy is unaffected.
@dimitri-yatsenko dimitri-yatsenko added the bug Indicates an unexpected problem or unintended behavior label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Indicates an unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant