Repository navigation
Compare dependency lists as sets in State.is_fresh() - #22403
Closed
Shanmukh-l33t wants to merge 1 commit into
Closed
Shanmukh-l33t wants to merge 1 commit into
Shanmukh-l33t wants to merge 1 commit into
Conversation
load_graph() may suppress a dependency (State.new_state() raising ModuleNotFound, e.g. for the parent of a missing submodule of a namespace package) and the up-suppress pass later re-adds it with add_dependency(), which appends it at the end of the list. That reorders the list without changing its membership, and on a warm run the indirect dependencies from CacheMetaEx are already merged in, so the order-sensitive comparison reported the module stale on every run and re-checked it forever (python#22159). Both lists only ever contain unique elements (asserted in write_cache()), so comparing them as sets is equivalent for membership and insensitive to ordering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22159
What
A warm mypy run re-checked an unchanged module forever (every run logs
Scheduling SCC singleton (...) as inherently stalefor it) whenever the module's dependency list had been reordered by the suppress / up-suppress cycle:State.is_fresh()comparedself.dependencies == self.meta.dependenciesorder-sensitively.Why
load_graph()can suppress a dependency (State.new_state()raisingModuleNotFound, e.g. for the parent of a missing submodule of a namespace package onPYTHONPATH), and the up-suppress pass later re-adds it withadd_dependency(), which appends it at the end of the list. Membership is unchanged, order is not. On a warm run the indirect dependencies fromCacheMetaExare already merged intoself.dependencies, so the reordered list never matches the cached order: nothing ever changes, but nothing is ever fresh either — the module is re-analyzed on every run and the cache is effectively bypassed for it.Change
mypy/build.py: compare the two dependency lists as sets. Both sides only ever contain unique elements (asserted inState.write_cache(),mypy/build.py:3687—Duplicates in dependencies list), so set equality is exactly membership equality here, and the suppressed-then-re-added ordering no longer matters.mypy/test/testcache.py: regression test built from the issue's repro — a missing submodule of a namespace package reachable viaPYTHONPATH, plus theimport osfrom the report. It asserts the cold run does schedule the module as inherently stale (the bug's precondition), and that the warm run and a third run schedule nothing as stale and replay byte-identical output.Testing
5dc284074with the reported symptom (assert "as inherently stale" not in second.stderr— the warm run logsScheduling SCC singleton (a) as inherently stale;1 failed) and passes with the fix (1 passed). The stash used for the RED run was popped and the working tree re-verified before committing.pytest mypy/test -q -n 2→ 12534 passed, 404 skipped, 10 xfailed, 1 failed. The single failure,test_find_sources_exclude(InvalidSourceList: There are no .py[i] files in directory '/'), reproduces identically with the fix stashed — a pre-existing environment failure in this sandbox, unrelated to this change. (Three other environment failures during the first full run — twoattrs-related stubgen/daemon cases andtestpep561'sfilelockImportError — disappeared after installing the pinnedattrs==26.1.0/filelock==3.32.3fromtest-requirements.txt; they too failed with the fix stashed.)black --check mypy/build.py mypy/test/testcache.py,ruff checkon the same files, andmypy --config-file mypy_self_check.ini mypy/build.py mypy/test/testcache.pyall clean.Checklist per the template: a test covers the changed behaviour; local checks above are green — CI to confirm.