Skip to content

Upgrade mypy to 2.4.0 and optimize configuration - #79

Merged
tsvikas merged 3 commits into
mainfrom
claude/clever-allen-z8e3iz
Oct 5, 2026
Merged

tsvikas merged 3 commits into
mainfrom
claude/clever-allen-z8e3iz

Conversation

@tsvikas

@tsvikas tsvikas commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Summary

This PR upgrades mypy from version 2.3.0 to 2.4.0 and optimizes the mypy configuration to leverage the new version's capabilities.

Key Changes

  • Dependency upgrade: Updated mypy constraint from ~=2.3.0 to ~=2.4.0
  • Configuration modernization:
    • Replaced deprecated fixed_format_cache = true with num_workers = "auto" for better parallel processing
    • Added warn_unused_configs = true to catch unused configuration options
    • Updated mypy version comment from 2.3 to 2.4
  • CI simplification: Removed explicit --num-workers "$(nproc)" flag from mypy invocation in CI workflow, allowing mypy to use its configured num_workers = "auto" setting instead

Implementation Details

The num_workers = "auto" setting allows mypy to automatically determine the optimal number of worker processes based on the system's CPU count, replacing the previous manual cache format configuration. The CI workflow now relies on the pyproject.toml configuration rather than passing command-line arguments, reducing duplication and improving maintainability.

https://claude.ai/code/session_0188obxQFxxkZRKmsy9fstfd

claude added 2 commits October 5, 2026 17:57
- Set `num_workers = "auto"` in [tool.mypy]: parallel checking is no
  longer experimental in 2.4, and "auto" picks the worker count from the
  available CPUs (capped at 8). This replaces the CI-only
  `--num-workers "$(nproc)"` flag, so local `mypy` runs are parallel too.
  dmypy forces num_workers=0, so `just lint` is unaffected.
- Drop `fixed_format_cache = true`: it has been the default since mypy 2.0.
- The native parser is now the default; nothing to configure.
- No new documented strictness flags or error codes in 2.4 (the new
  `--check-unreachable` is a hidden flag), so the enable-checks list is
  unchanged; only the "last updated" marker moves to 2.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188obxQFxxkZRKmsy9fstfd
Reports [[tool.mypy.overrides]] sections that match no checked module,
e.g. a stale ignore_missing_imports for a dropped dependency. It is not
part of --strict. mypy 2.4 removed the docs caveat that it requires
incremental mode to be off; verified it reports with a warm cache, in
parallel mode, and under dmypy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188obxQFxxkZRKmsy9fstfd

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="project_name/pyproject.toml.jinja" line_range="189" />
<code_context>
 files = ["src", "tests"]
 mypy_path = "stubs"
-fixed_format_cache = true
+num_workers = "auto"
 # set the platform
 python_version = "3.{{ python_min }}"
</code_context>
<issue_to_address>
**Pre-commit mypy remains serial**

When local lint is run through `just lint`, `just lint` runs `prek run --all-files`, whose mypy hook passes `--config-file ''` without a `--num-workers` option, so it ignores this setting and checks files serially. That local mypy entry point does not get the parallelism the commit says local runs gain.

Add `--num-workers=auto` to the pre-commit mypy hook if that hook is intended to share the parallelism improvement.
</issue_to_address>

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread project_name/pyproject.toml.jinja Outdated
validate-pyproject (with the schema store) rejects num_workers = "auto":
SchemaStore's partial-mypy.json still types num_workers as an integer,
so generated projects failed `just lint`. Keep the parallel run in CI
via the CLI flag, which accepts "auto" since mypy 2.4, until the schema
catches up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188obxQFxxkZRKmsy9fstfd
@tsvikas
tsvikas merged commit dd4a9e0 into main Oct 5, 2026
5 checks passed
@tsvikas
tsvikas deleted the claude/clever-allen-z8e3iz branch October 5, 2026 18:15
tsvikas added a commit that referenced this pull request Oct 5, 2026
#79 moved this to a CI-only `--num-workers auto` flag because
validate-pyproject rejects the value: SchemaStore's mypy schema still
types num_workers as an integer. Put it back in [tool.mypy], so local
`mypy` runs are parallel too, and disable only the mypy schema in the
validate-pyproject hook until the schema catches up.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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