Fix crash with # type: ignore in incremental mode #1906
Closed
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 commit fixes the bug described in #1904.
More precisely, the bug manifests when...
# type: ignore
comment#type: ignore
comment after the regular import.The bug appears to stem from how the semantic analyzer seemed to always mark import symbols as being of kind
MODULE_REF
and did not preserve whether the module was previously marked with the# type: ignore
comment or not.This caused a contradiction since how mypy decides to order dependencies differs whether you're starting with a cold cache or a warm cache.
When you start with a cold cache, mypy determines what each module's dependencies are based roughly on the order mypy encounters each file while parsing and whether the import is marked as ignorable or not.
However, when you start with a warm cache, mypy will use the previously computed list of dependencies, but will also attempt to typecheck each symbol marked as being of kind
MODULE_REF
. This presents a problem, since if the module was marked as being ignorable, it wouldn't be in the list of dependencies, but since it was marked asMODULE_REF
, mypy assumes it is...This pull request fixes this problem by modifying the semantic analyzer so that it determines whether it needs to mark import symbols of being kind
MODULE_REF
orUNBOUND_IMPORTED
to keep the behavior consistent during both runs.