Fix crash in daemon mode on new import cycle #14508
Merged
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 #14329
This fixes the second crash reported in the issue (other one is already fixed). This one is tricky, it looks like it happens only when we bring in a new import cycle in an incremental update with
--follow-import=normal
. To explain the reason, a little reminder of how semantic analyzer passes work:force_progress
flag was added todefer()
.force_progress=True
(without checking if we actually resolved some placeholder types).becomes_typeinfo=True
, there is no way this symbol will later be unresolved (otherwise how would we know this is something that is a type).becomes_typeinfo=True
for symbols imported from modules that were not yet processed, thus causing a crash (see test cases).becomes_typeinfo=True
for unimported symbols in daemon mode, other one is to always carefully check if in-place update of a symbol actually resulted in progress.I didn't add test cases for each of the crash scenarios, since they are all very similar. I only added two that I encountered "in the wild", upper bound and tuple base caused actual crash in
trio
stubs, plus also randomly a test for a TypedDict crash.EDIT: and one more thing, the "cannot resolve name" error should never appear in normal mode, only in daemon update (see reasoning above), so I don't make those error messages detailed, just add some minimal info if we will need to debug them.