Fix imports being unsilenced when checking stale SCCs #2037
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.
This pull request fixes an edge case where previously silenced imports were being un-silenced when using silent imports with incremental mode.
Unfortunately, I wasn't able to provide a test case because this problem seems to manifest mainly in larger code bases (with import cycles?) that are hard to simplify and after running incremental mode at least 3 times -- our test suite can currently handle only three. See #2036 for more details about the bug.
The problem ended up being with the order in which the
parse_file(...)
andload_graph(...)
functions are called -- the former function will mark imports with the# type: ignore
directives as suppressed and the latter function corrects the dependencies computed byparse_file
and will mark silenced modules as suppressed.The problem is that when running mypy with a cold cache, the
parse_file
function will be executed at the start of theload_graph
function, but when checking a stale SCC, the logic will end up makingparse_file
be executed after theload_graph
function.This is problematic since
parse_file
will potentially clobber over the (often correct) information regarding suppressed and unsuppressed dependencies that was loaded from the old cache files.This fix adds an extra pass over the dependencies after calling
parse_file
when checking stale SCCs to correct the clobbering.