Skip to content

Run mypy on the CI Python version matrix - #22

Open
bjmorgan wants to merge 1 commit into
masterfrom
ci/mypy-on-python-matrix
Open

Run mypy on the CI Python version matrix#22
bjmorgan wants to merge 1 commit into
masterfrom
ci/mypy-on-python-matrix

Conversation

@bjmorgan

@bjmorgan bjmorgan commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

mypy lattice_mc currently fails in any environment newer than Python 3.11 with an error inside the third-party numpy_typing_compat stubs ("Type statement is only supported in Python 3.12 and greater"). The cause is the python_version = "3.11" pin in [tool.mypy]: mypy applied 3.11 syntax rules to packages installed for a newer interpreter, and those packages legitimately use 3.12+ syntax on newer Pythons. The CI lint job (Python 3.13) hits exactly this mismatch.

Changes

  • Remove the python_version pin from [tool.mypy] in pyproject.toml, so mypy defaults to the interpreter it runs under and always checks semantics consistent with the installed environment.
  • Move the type-check step from the lint job into the test matrix job, so mypy runs under each supported version (3.11-3.14) with the correspondingly installed dependencies. This is what genuinely verifies 3.11 semantics, rather than emulating them from a newer environment. The lint job retains ruff.

Verified locally (Python 3.12): mypy lattice_mc passes with the pin removed, and the full test suite passes.

Remove the python_version pin from the mypy configuration and move the
type-check step from the lint job into the test matrix. Pinning mypy to
3.11 semantics while running under a newer interpreter made mypy analyse
installed third-party packages built for that newer interpreter with the
older syntax rules; numpy_typing_compat legitimately uses 3.12+ syntax
in such environments, so mypy failed before reaching the package code.

With the pin removed, mypy defaults to the interpreter it runs under, so
each matrix environment (3.11 to 3.14) type-checks its own semantics
against its own installed stubs.
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