Skip to content

Run the mypy pre-commit hook the same way as CI#6977

Merged
agners merged 1 commit into
mainfrom
mypy-precommit-whole-program
Jun 25, 2026
Merged

Run the mypy pre-commit hook the same way as CI#6977
agners merged 1 commit into
mainfrom
mypy-precommit-whole-program

Conversation

@agners

@agners agners commented Jun 25, 2026

Copy link
Copy Markdown
Member

Proposed change

Run the mypy pre-commit hook the same way CI does, with mypy supervisor.

mypy is a whole-program checker, but the hook was configured to check only the changed files (the default pass_filenames behavior) and added --ignore-missing-imports. Neither matches the CI command (mypy supervisor), which leads to two problems:

  • Different results than CI. Checking only the changed files instead of the whole package can both miss and invent errors compared to a full run, so the hook and CI can disagree. See python/mypy#13916 for the whole-program-vs-per-file rationale.
  • Intermittent INTERNAL ERROR crashes. When several supervisor/ files change, pre-commit splits the file list and runs the hook concurrently. Since mypy 2.0 the SQLite cache is enabled by default, and the parallel mypy processes race on the shared .mypy_cache/cache.db: SQLite reports database is locked (python/mypy#21525), and an interrupted write can leave the database malformed. This is the failure mode that the cache-cleanup runbook in Add mypy cache-fix skill documentation #6971 works around; this PR addresses the root cause instead.

The fix aligns the hook with CI:

  • pass_filenames: false and an explicit supervisor target so the hook always checks the whole package in a single invocation.
  • require_serial: true as a safeguard against pre-commit ever running the hook concurrently.
  • Drop --ignore-missing-imports, which CI does not use and which is redundant anyway: [tool.mypy] already disables the import-not-found and import-untyped error codes.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Ruff (ruff format supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints or add-on configuration are added/changed:

@agners agners added the chore Other changes that don't modify src or test files label Jun 25, 2026
mypy is a whole-program checker, but the pre-commit hook passed only the
changed files (with pass_filenames on) and added --ignore-missing-imports,
neither of which matches the CI command (mypy supervisor).

Passing only the changed files gives results that differ from a full run,
and because pre-commit splits a long file list and runs the hook
concurrently, the parallel mypy processes race on the shared SQLite cache
that is enabled by default since mypy 2.0 and crash with intermittent
INTERNAL ERRORs (python/mypy#21525). --ignore-missing-imports is also
redundant: the [tool.mypy] config already disables the import-not-found
and import-untyped error codes.

Set pass_filenames: false so the hook always checks the whole supervisor
package in a single invocation, add require_serial: true as a safeguard,
and drop --ignore-missing-imports so the hook matches mypy supervisor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@agners agners force-pushed the mypy-precommit-whole-program branch from cf09261 to 45265d4 Compare June 25, 2026 13:17
@agners agners merged commit efc24f8 into main Jun 25, 2026
21 checks passed
@agners agners deleted the mypy-precommit-whole-program branch June 25, 2026 15:27
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

chore Other changes that don't modify src or test files cla-signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants