我想在实例创建后验证类型是否正确,我尝试使用@dataclass装饰器,但不允许我使用该__init__方法,我还尝试使用自定义类类型
还按照类型的顺序进行了一些验证(例如,如果是 a int,则field>0或者 if 是str干净的空格),我可以使用字典来验证类型,但我想知道是否有办法在 pythonic 中做到这一点方式
class Car(object):
""" My class with many fields """
color: str
name: str
wheels: int
def __init__(self):
""" Get the type of fields and validate """
pass
Run Code Online (Sandbox Code Playgroud)