Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,8 @@ enabled by default starting from mypy 2.0.

Use ``NUMBER`` parallel worker processes (in addition to the coordinator
process) to perform type-checking. Specifying ``--num-workers 0`` (default)
disables parallel checking. Automatic detection of the optimal number
of workers is not supported yet.
disables parallel checking. Automatic detection of the physical CPU core count
is possible through ``--num-workers auto```.

This setting will override the ``MYPY_NUM_WORKERS`` environment
variable if it is set.
Expand Down
11 changes: 9 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import argparse
import multiprocessing
import os
import platform
import subprocess
Expand Down Expand Up @@ -1179,12 +1180,18 @@ def add_invertible_flag(
internals_group.add_argument("--export-ref-info", action="store_true", help=argparse.SUPPRESS)

# Experimental parallel type-checking support.
def _num_workers_type(value: str) -> int:
if value == "auto":
return multiprocessing.cpu_count()

return int(value)

internals_group.add_argument(
"-n",
"--num-workers",
type=int,
type=_num_workers_type,
default=0,
help="Number of separate mypy worker processes (experimental)",
help="Number of separate mypy worker processes (experimental). With `auto` detects (and uses) physical CPU count.",
)

report_group = parser.add_argument_group(
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -1321,3 +1321,13 @@ error: Cache must be enabled in parallel mode
from foo.api import bar as bar
[file foo-stubs/api/bar.pyi]
[out]

[case testParallelAutoRunWithSyntaxError]
# cmd: mypy a.py --num-workers=auto --pretty
[file a.py]
1 2
[out]
a.py:1: error: Simple statements must be separated by newlines or semicolons
1 2
^
== Return code: 2
Loading