In Python 3.7.0 and mypy 0.630+dev-3fb16a2b8c5439074e39b75feebc109a439eede3, if I save the following code to mypy-test.py
fromdataclassesimportdataclassdataclass_alias=dataclassdataclass_alias2=dataclass(order=False)
defdataclass_wrapper(cls):
returndataclass(cls)
@dataclassclassA: arg1: int@dataclass_aliasclassB: arg1: int@dataclass_alias2classC: arg1: int@dataclass_wrapperclassD: arg1: inta=A(arg1=1)
b=B(arg1=1)
c=C(arg1=1)
d=D(arg1=1)
I get the following mypy output
$ mypy mypy-test.py mypy-test.py:22: error: Unexpected keyword argument "arg1" for "B"
mypy-test.py:23: error: Unexpected keyword argument "arg1" for "C"
mypy-test.py:24: error: Unexpected keyword argument "arg1" for "D"
Notice that mypy has no trouble recognizing the signature of A's constructor. I can understand how mypy would have a hard time with dataclass_wrapper, and dataclass_alias is probably not critical in terms of use case. However, dataclass_alias2 is important if you want (as I do) to define many data classes with the same options, especially if you want to make these options available as part of your module's public interface.
In Python 3.7.0 and mypy
0.630+dev-3fb16a2b8c5439074e39b75feebc109a439eede3, if I save the following code tomypy-test.pyI get the following mypy output
Notice that mypy has no trouble recognizing the signature of
A's constructor. I can understand how mypy would have a hard time withdataclass_wrapper, anddataclass_aliasis probably not critical in terms of use case. However,dataclass_alias2is important if you want (as I do) to define many data classes with the same options, especially if you want to make these options available as part of your module's public interface.