stubgen: Fix generated dataclass __init__ signature#16906
stubgen: Fix generated dataclass __init__ signature#16906JelleZijlstra merged 1 commit intopython:masterfrom
__init__ signature#16906Conversation
|
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! |
JelleZijlstra
left a comment
There was a problem hiding this comment.
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_argsand**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.