其他分享
首页 > 其他分享> > pydantic错误处理

pydantic错误处理

作者:互联网

错误处理

from typing import List
from pydantic import BaseModel, ValidationError, conint


class Location(BaseModel):
    lat = 0.1
    lng = 10.1


class Model(BaseModel):
    is_required: float
    gt_int: conint(gt=42)
    list_of_ints: List[int] = None
    a_float: float = None
    recursive_model: Location = None


data = dict(
    list_of_ints=['1', 2, 'bad'],
    a_float='not a float',
    recursive_model={'lat': 4.2, 'lng': 'New York'},
    gt_int=21,
)

标签:loc,float,value,error,msg,错误处理,type,pydantic
来源: https://www.cnblogs.com/puffer/p/16377537.html