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鈥檒l 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

commented Jul 8, 2019

Closes #6399. Pretty simple fix but I ran into it so figured might as well fix it. 馃し鈥嶁檪

mypy/plugins/dataclasses.py Outdated Show resolved Hide resolved

@refi64 refi64 force-pushed the refi64:dataclass-init branch from c5288f9 to a5e5eda Jul 8, 2019

@refi64

This comment has been minimized.

Copy link
Contributor Author

commented Jul 8, 2019

Welp I broke the new semantic analyzer, everything is complicated 馃ぃ

@refi64 refi64 force-pushed the refi64:dataclass-init branch from a5e5eda to 6f22bee Jul 8, 2019

@refi64

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 8, 2019

Okay it's all green now!

@ilevkivskyi
Copy link
Collaborator

left a comment

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

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can鈥檛 perform that action at this time.