-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix some crashes in dataclasses #8271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Store the type of an attribute in `DataclassAttribute` so we don't need to pull it out of `TypeInfo` in a fragile way (since the child might try to override it in a way that breaks things). This also allows us to get rid of some pretty dodgy code having to do with InitVars (that could cause an incremental mode crash.) Fixes #6809 and an unreported incremental bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few questions. I like how the the new code looks much cleaner.
assert attr.is_init_var and not attr.is_in_init | ||
continue | ||
if node.type is None: | ||
if attr.type is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the some attribute has no type? We seem to handle this case during deserialization, so maybe it can happen here as well. Could this result in always deferring for some attribute? If not, maybe we should require that the serialized type is not None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only consider something as being an attribute if it has a type annotation, so the type missing is (should be) always due to resolution issues that can be fixed by deferring.
I think we can only serialize things with non-None types, yeah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! Looks good now.
Store the type of an attribute in
DataclassAttribute
so we don'tneed to pull it out of
TypeInfo
in a fragile way (since the childmight try to override it in a way that breaks things). This also
allows us to get rid of some pretty dodgy code having to do with
InitVars (that could cause an incremental mode crash.)
Fixes #6809 and an unreported incremental bug