Skip to content

Fix false cache misses when dependency order changes - #22170

Closed
jstar0 wants to merge 1 commit into
python:masterfrom
jstar0:codex/issue-22159-cache-order
Closed

jstar0 wants to merge 1 commit into
python:masterfrom
jstar0:codex/issue-22159-cache-order

Conversation

@jstar0

@jstar0 jstar0 commented Oct 10, 2026

Copy link
Copy Markdown

Fixes #22159.

The cache freshness check compared dependency lists positionally. Graph loading can suppress and restore dependencies in a different order, marking an unchanged module stale. The comparison now checks dependency membership and list cardinality, preserving the unique-dependency invariant and the existing suppressed-import option validation.

The regression case uses the reported namespace-package layout and verifies that an unchanged second run does not recheck a.

LLM assistance was used during reproduction, source tracing, and implementation; the behavior was verified with the regression case and incremental suite.

Verification:

  • pytest -n0 mypy/test/testbuild.py::BuildSuite::test_reuses_cache_when_dependency_order_changes
  • pytest -n0 'mypy/test/testcheck.py::TypeCheckSuite::check-incremental.test' (358 passed, 4 skipped)
  • python runtests.py self
  • python runtests.py lint

Compare dependency membership and counts when validating cache freshness. Dependency order can change when graph loading suppresses and restores imports.

Add an integration regression for an unchanged second run using the namespace-package reproduction.

Fixes python#22159.
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

scipy-stubs (https://github.com/scipy/scipy-stubs)
+ tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache sometimes gets ignored for unchanged files

2 participants