Upgrade mypy to 2.1.0 and optimize type checking#29
Merged
Conversation
- Bump mypy from ~=1.20.0 to ~=2.1.0. - Remove local_partial_types from config (enabled by default in 2.1). - Pass --num-workers 4 in CI to match GitHub Actions runner vCPUs. https://claude.ai/code/session_01DSZJX4JKn2or8vLdmoGECt
native-parser is included by default in mypy 2.1. https://claude.ai/code/session_01DSZJX4JKn2or8vLdmoGECt
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Hard-coding
--num-workers 4in the CI workflow may underutilize or oversubscribe cores on different runners; consider either omitting the flag to use mypy’s default parallelism or deriving the worker count dynamically (e.g., via$(nproc)or a matrix/env variable).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Hard-coding `--num-workers 4` in the CI workflow may underutilize or oversubscribe cores on different runners; consider either omitting the flag to use mypy’s default parallelism or deriving the worker count dynamically (e.g., via `$(nproc)` or a matrix/env variable).
## Individual Comments
### Comment 1
<location path="project_name/.github/workflows/ci.yml.jinja" line_range="79-80" />
<code_context>
run: uv pip list
- name: Run mypy
- run: uv run --no-sync mypy
+ run: uv run --no-sync mypy --num-workers 4
dependencies:
</code_context>
<issue_to_address>
**suggestion (performance):** Hardcoding `--num-workers 4` may underuse or oversubscribe CI runners; consider deriving it from available CPUs.
Fixing this at 4 assumes a specific runner size and may slow CI on larger machines or overload smaller ones. Instead, consider deriving the value from available CPUs (e.g. `--num-workers "$(nproc)"` on Linux) or omitting it and relying on mypy’s default unless you have data showing 4 is optimal.
```suggestion
- name: Run mypy
run: uv run --no-sync mypy --num-workers "$(nproc)"
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Adapt the worker count to the runner instead of hardcoding 4. https://claude.ai/code/session_01DSZJX4JKn2or8vLdmoGECt
Mirrors the CI mypy parallelism. Hardcoded since macOS lacks nproc. https://claude.ai/code/session_01DSZJX4JKn2or8vLdmoGECt
dmypy crashes when --num-workers is passed (FileExistsError in worker init) — the parallel-worker mode is incompatible with the daemon. Keep the flag only on the one-shot mypy invocation in CI. https://claude.ai/code/session_01DSZJX4JKn2or8vLdmoGECt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR upgrades mypy from version 1.20.0 to 2.1.0 and optimizes the type checking configuration and CI workflow.
Key Changes
~=1.20.0to~=2.1.0and removed the[native-parser]extra (no longer needed in 2.1.0)local_partial_types = truefrom mypy config, which is no longer necessary with mypy 2.1.0--num-workers 4flag to mypy invocation in CI to parallelize type checking across 4 workersImplementation Details
The removal of
local_partial_typesconfiguration indicates that mypy 2.1.0 has improved its handling of partial types, making this explicit setting redundant. The parallel worker configuration in CI should reduce type checking time without requiring any code changes.https://claude.ai/code/session_01DSZJX4JKn2or8vLdmoGECt