I am not sure what I am doing wrong. How to prevent the Test class to accept & throw error, when input of different types are passed. I am using Python 3.9.2
from dataclasses import dataclass, fields
@dataclass
class Test:
a: str = 'a'
b: int = 1
t = Test(2, 'b')
print(fields(t))
print(type(t.a))
print(type(t.b))
# output
# (venv) D:\Playground>python dataClassesTest.py
# (Field(name='a',type=<class 'str'>,default='a',default_factory=<dataclasses._MISSING_TYPE object at 0x00000232952D5880>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), Field(name='b',type=<class 'int'>,default=1,default_factory=<dataclasses._MISSING_TYPE object at 0x00000232952D5880>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD))
# <class 'int'>
# <class 'str'>