I am using the new dataclass
feature of Python3
that allows specifying the type of the class fields. In this examples field2 should be of type List[int], and I passed a List[str] to it. This code runs without failure, I am wondering if there is an (automatic) way to have the code fail (i.e. using asserts, etc.) if the wrong type is passed to the class.
from dataclasses import *
import typing
@dataclass
class C:
field1: str
field2: typing.List[int]
if __name__ == '__main__':
x = C('a',['a','b'])
print(repr(x))