我正在尝试使用pydantic在Python中创建一个类型化列表。我的第一个想法是这样做: # some attributes and methods here items: List[TypedObject] # some other methods here
然而,TypedList实际上不是一个<em
我正在将项目中现有的dataclasses转换为pydantic-dataclasses,我正在使用这些dataclasses来表示我需要从json编码和解析的模型。请注意,我使用asdict函数将dataclass转换为dict,因为pydantic_encoder用于将dataclass转换为json,以及使用文档推荐的pydantic_encoder将pydantic-dataclass转换为json:
from dataclasses import asdict