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
3 changes: 3 additions & 0 deletions docs/notes/2.32.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ Pants will attempt to only preserve the `mypy` cache when `mypy` returns a [prob

The default version of mypy used by Pants has been updated to [1.19.1](https://mypy-lang.blogspot.com/2025/11/mypy-119-released.html). This includes support for the new "Fixed‑Format" cache.

Copying the `mypy` cache back to the ["named cache"](https://www.pantsbuild.org/2.32/reference/global-options#named_caches_dir) should now be atomic in all cases.


#### Shell

#### Javascript
Expand Down
19 changes: 11 additions & 8 deletions src/python/pants/backend/python/typecheck/mypy/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ async def mypy_typecheck_partition(
#
# If we can hardlink (this means the two sides of the link are on the
# same filesystem), then after mypy runs, we hardlink from the sandbox
# back to the named cache.
# to a temp file in the named cache, then atomically rename it into place.
#
# If we can't hardlink, we resort to copying the result next to the
# cache under a temporary name, and finally doing an atomic mv from the
# tempfile to the real one.
# If we can't hardlink, we resort to copying the result to a temp file
# in the named cache, and finally doing an atomic mv from the tempfile
# to the real one.
#
# In either case, the result is an atomic replacement of the "old" named
# cache db, such that old references (via opened file descriptors) are
Expand Down Expand Up @@ -312,10 +312,13 @@ async def mypy_typecheck_partition(
# left the cache in an inconsistent state.
# See https://github.com/python/mypy/issues/6003 for exit codes
if [ $EXIT_CODE -le 1 ]; then
if ! {ln.path} "$SANDBOX_CACHE_DB" "$NAMED_CACHE_DB" > /dev/null 2>&1; then
TMP_CACHE=$({mktemp.path} "$SANDBOX_CACHE_DB.tmp.XXXXXX")
{cp.path} "$SANDBOX_CACHE_DB" "$TMP_CACHE" > /dev/null 2>&1
{mv.path} "$TMP_CACHE" "$NAMED_CACHE_DB" > /dev/null 2>&1
if LN_TMP=$({mktemp.path} -u "$NAMED_CACHE_DB.tmp.XXXXXX") &&
{ln.path} "$SANDBOX_CACHE_DB" "$LN_TMP" > /dev/null 2>&1; then
{mv.path} "$LN_TMP" "$NAMED_CACHE_DB" > /dev/null 2>&1
else
CP_TMP=$({mktemp.path} "$NAMED_CACHE_DB.tmp.XXXXXX") &&
{cp.path} "$SANDBOX_CACHE_DB" "$CP_TMP" > /dev/null 2>&1 &&
{mv.path} "$CP_TMP" "$NAMED_CACHE_DB" > /dev/null 2>&1
fi
fi

Expand Down
Loading