Skip to content
Closed
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
5 changes: 4 additions & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3056,7 +3056,10 @@ def is_fresh(self) -> bool:
# same for suppressed dependencies, even if the first check is OK.
return (
self.meta is not None
and self.dependencies == self.meta.dependencies
# Loading and suppressing dependencies can change their iteration order.
and self.dependencies_set == set(self.meta.dependencies)
and len(self.dependencies_set) == len(self.dependencies)
and len(self.dependencies) == len(self.meta.dependencies)
and (
self.options.fine_grained_incremental
or self.meta.suppressed_deps_opts == self.suppressed_deps_opts()
Expand Down
56 changes: 56 additions & 0 deletions mypy/test/testbuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Tests for incremental build behavior."""

from __future__ import annotations

import os
import subprocess
import sys
import tempfile
from pathlib import Path

from mypy.test.helpers import Suite


class BuildSuite(Suite):
def test_reuses_cache_when_dependency_order_changes(self) -> None:
with tempfile.TemporaryDirectory() as temporary_directory:
tmp_path = Path(temporary_directory)
site = tmp_path / "site"
typed_subpackage = site / "ns" / "sub"
typed_subpackage.mkdir(parents=True)
(typed_subpackage / "__init__.py").write_text("", encoding="utf8")
(typed_subpackage / "py.typed").touch()

(tmp_path / "a.py").write_text(
"import ns.missing\nimport os\n\ny = os.environ\n", encoding="utf8"
)
(tmp_path / "b.py").write_text("import ns.sub\n", encoding="utf8")
(tmp_path / "e.py").write_text("import b\n", encoding="utf8")

env = os.environ.copy()
env.pop("MYPY_CACHE_DIR", None)
env["PYTHONPATH"] = str(site)
command = [
sys.executable,
"-m",
"mypy",
"-v",
f"--cache-dir={tmp_path / 'cache'}",
"a.py",
"e.py",
]

def run() -> subprocess.CompletedProcess[str]:
return subprocess.run(
command, cwd=tmp_path, env=env, capture_output=True, text=True, check=False
)

first_run = run()
second_run = run()

stale_log = "Scheduling SCC singleton (a) as inherently stale"
first_output = first_run.stdout + first_run.stderr
second_output = second_run.stdout + second_run.stderr
assert first_run.returncode == second_run.returncode == 1
assert stale_log in first_output
assert stale_log not in second_output
Loading