dataclasses: Fix deeply nested InitVar definitions with init=False #8208
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 #8207
In #8159, I fixed InitVar handling so that it looked up the superclass
__init__
and used that to determine the definition of InitVars.That fix doesn't work in the presence of
init=False
subclasses of the initialinit=False
class. In that case, the lookup fails because the first attribute reached in MRO order on the subclass is the intermediate class, which also doesn't have the variable in its__init__
. Then mypy didn't know about the InitVar but still tried to process it as if it did, resulting in an assertion error.This PR fixes that issue by not adding the field to the set of known attrs until an actual definition is found.