0

我不熟悉使用名为 pydantic 的库。他们使用对我来说陌生的语法,以前从未见过。这是显示“:”的片段,很像赋值语句中的字典。有关几个实例,请参见类 FooBar 和类 MainModel。有人请赐教吗?谢谢。

class FooBar(BaseModel):
    count: int
    size: float = None

class Gender(str, Enum):
    male = 'male'
    female = 'female'
    other = 'other'
    not_given = 'not_given'

class MainModel(BaseModel):
    """
    This is the description of the main model
    """
    foo_bar: FooBar = Field(...)
    gender: Gender = Field(None)
    snap: int = Field(
        42,
        title='The Snap',
        description='this is the value of snap',
        gt=30,
        lt=50,
    )
4

0 回答 0