Skip to content

Commit cc3db3b

Browse files
Python: Isolate per-package mypy cache in test-typing fan-out
The parallel test-typing fan-out runs many mypy processes concurrently, all defaulting to a single shared ./.mypy_cache. Concurrent writes corrupt the cache and mypy aborts with INTERNAL ERROR (intermittently, depending on worker timing) -- which is why CI's Test Typing job failed on a shifting set of packages while a single-package run was fine. Give each mypy invocation an isolated cache dir keyed by its target paths so incremental caching still works per package without races. Other checkers (zuban/pyrefly/ty/pyright) maintain their own caches and are unaffected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3c8ccd2 commit cc3db3b

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

python/scripts/workspace_poe_tasks.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from __future__ import annotations
1111

1212
import argparse
13+
import hashlib
1314
import subprocess
1415
import sys
1516
from dataclasses import dataclass
@@ -353,12 +354,20 @@ def _gating_checker_args() -> list[str]:
353354

354355

355356
def _mypy_command(paths: list[str], *, samples: bool) -> list[str]:
357+
# The test-typing fan-out runs many mypy processes concurrently. mypy defaults to a
358+
# single shared ``.mypy_cache`` in the working directory; concurrent writes corrupt it
359+
# and mypy aborts with ``INTERNAL ERROR``. Give each invocation an isolated cache dir
360+
# keyed by its target paths so incremental caching still works per package without races.
361+
cache_key = hashlib.sha1("\0".join(sorted(paths)).encode()).hexdigest()[:16]
362+
cache_dir = Path(".mypy_cache") / ("samples" if samples else "tests") / cache_key
356363
command = [
357364
"uv",
358365
"run",
359366
"mypy",
360367
"--config-file",
361368
"pyproject.toml",
369+
"--cache-dir",
370+
str(cache_dir),
362371
"--explicit-package-bases",
363372
"--namespace-packages",
364373
]

0 commit comments

Comments
 (0)