-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
stubgen: Fix generated dataclass __init__
signature
#16906
Conversation
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
I believe it's valid to use |
You are right, that's why I changed stubgen to keep the |
I see -- that makes sense, thanks! |
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.
There is one aspect of the issue that isn't fixed by this PR: the __init__
parameters still don't have types. That can wait for another PR, though.
Including these types is a step into uncharted territory for stubgen as these types are inferred and stubgen doesn’t know how to handle them yet. I tried a little bit to include them before submitting the PR but they require some non trivial work (e.g. adding new imports for the inferred annotations and handling name collisions) so I left them out for now. |
Fixes #16811
stubgen was swallowing default values for
__init__
methods generated by the dataclass plugin making their signature incorrect. This is because the plugin does not include the argument's initializer in the generated signature. I changed it to include a dummy ellipsis so that stubgen can generate correct code.I also fixed arguments added by the dataclass plugin with the invalid names
*
and**
to have the valid and unique names*generated_args
and**generated_kwargs
(with extra underscores to make them unique if necessary). This removes the need for the hack to special case them in stubgen and is less confusing for someone looking at them in a stub file.