数据类的严格伙伴
strictclasses的Python项目详细描述
严格分类
免责声明:这是测试版软件,API不稳定。
这是dataclasses
的验证伙伴。
它将strict
方法添加到数据类中,以验证类型是否正确。
用法:
fromdataclassesimportdataclassfromstrictclassesimportstrict@strict@dataclassclassFoo:bar:intf=Foo('3')f.strict()# -> AssertionError: bar is not an instance of <class 'int'>