from dataclasses import dataclass
@dataclassclass MyClass: id: int = 0 name: str = ''myclass = MyClass()myclass.__annotations__>> {'id': int, 'name': str}myclass.__dataclass_fields__>> {'id': Field(name='id',type=<class 'int'>,default=0,default_factory=<dataclasses._MISSING_TYPE object at 0x0000000004EED668>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'name': Field(name='name',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object at 0x0000000004EED668>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD)}
在旁注中还有:
myclass.__dataclass_params__>>_DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)