Skip to content

Fix crash when a dataclass with a no init InitVar is inherited #7390

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

Merged
merged 3 commits into from
Aug 27, 2019

Conversation

onlined
Copy link
Contributor

@onlined onlined commented Aug 26, 2019

Fixes #7320.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the crash! Looks good (just a few nits) but it would be nice to have a test case. Test cases for dataclasses live in test-data/unit/check-dataclasses.test.

if info[attr.name].type is None:
try:
node = info[attr.name]
except KeyError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it would be slightly cleaner if you'd use a if info.get(attr.name) is None check instead of try/except here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

del info.names[attr.name]
try:
del info.names[attr.name]
except KeyError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, I'd slightly prefer an if statement instead of try/except here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@onlined
Copy link
Contributor Author

onlined commented Aug 27, 2019

Thanks for the review! I updated the code and added a test.

Copy link
Collaborator

@JukkaL JukkaL left a 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.

@JukkaL JukkaL merged commit ddec163 into python:master Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal error with dataclasses.InitVar and init=False
2 participants