Skip to content
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

Don't define a duplicate __init__ for dataclasses #7168

Merged
merged 1 commit into from Jul 8, 2019

Conversation

refi64
Copy link
Contributor

@refi64 refi64 commented Jul 8, 2019

Closes #6399. Pretty simple fix but I ran into it so figured might as well fix it. 🤷‍♂️

@refi64
Copy link
Contributor Author

refi64 commented Jul 8, 2019

Welp I broke the new semantic analyzer, everything is complicated 🤣

@refi64
Copy link
Contributor Author

refi64 commented Jul 8, 2019

This is interesting, testTypeInDataclassDeferredStar is failing because under the new semantic analyzer, attributes is empty on the first round. Before this worked because __init__ was unconditionally overwritten every time, so the newer __init__ that actually contained attributes would override the empty one that was generated the first time. To work around this, I just skip generating __init__ if the attribute list is empty, since in that case the autogenerated __init__ would be identical to object's anyway.

@refi64
Copy link
Contributor Author

refi64 commented Jul 8, 2019

Okay it's all green now!

Copy link
Member

@ilevkivskyi ilevkivskyi 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 fix!

This is not super clean, but I can't propose anything better.

@ilevkivskyi ilevkivskyi merged commit 2f613b8 into python:master Jul 8, 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.

Wrong inference of dataclasses with custom __init__ and varargs.
2 participants