我正在创建一个带有字段的数据类,我希望只有几个可能的值。我在想这样的事情:
@dataclass class Person: name: str = field(default='Eric', choices=['Eric', 'John', 'Graham', 'Terry'])
我知道一种解决方案是验证__post_init__方法中的参数,但是否有使用类似上述语法的更简洁的方法?
__post_init__
python field python-3.x python-3.7 python-dataclasses
field ×1
python ×1
python-3.7 ×1
python-3.x ×1
python-dataclasses ×1