from dataclasses import dataclass, field from typing import List, Dict @dataclass class Upload: img_quality: float = 1.0 # 默认值为 1.0f @dataclass class Config: url: str = "http://www.linxyun.com" # 默认值 entCode: str = field(default=None, metadata={"required": True, "message": "The 'entCode' property is mandatory"}) project: str = field(default=None, metadata={"required": True, "message": "The 'project' property is mandatory"}) role: Dict[str, List[str]] = field(default_factory=dict) white_list: List[str] = field(default_factory=list) upload: Upload = field(default_factory=Upload) def __post_init__(self): # 进行字段校验,例如检查必填字段 if self.entCode is None: raise ValueError("The 'entCode' property is mandatory") if self.project is None: raise ValueError("The 'project' property is mandatory")