In this code:
import dataclasses
@dataclasses.dataclass
class MyClass:
value: str
obj = MyClass(value=1)
the dataclass MyClass
is instantiated with a value that does not obey the value
type.
Is there a simple way (using a decorator, an argument in the dataclass
decorator or library) of enforcing the fields' types so that the last line in my example raises a ValueError
or something like that? Is there a major downside of enforcing types in this way?