You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you can see, the method method received the correct type hints. However, the __init__ method did not. It correctly removed the baz parameter, as this has the init=False flag, but no type hints are present. Also, it does not reflect the fact, that bar is only an optional parameter. This leads to incorrect type hints when using this dataclass.
To Reproduce
Run stubgen module.py.
Expected Behavior
The expected behavior could look something like this:
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.
Bug Report
Stubs for a dataclass are incomplete and depending on the use case also incorrect. Consider the following dataclass:
The resulting generated stubs are
As you can see, the method
method
received the correct type hints. However, the__init__
method did not. It correctly removed thebaz
parameter, as this has theinit=False
flag, but no type hints are present. Also, it does not reflect the fact, thatbar
is only an optional parameter. This leads to incorrect type hints when using this dataclass.To Reproduce
Run
stubgen module.py
.Expected Behavior
The expected behavior could look something like this:
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: