【发布时间】:2021-03-04 02:57:35
【问题描述】:
我想知道是否可以在自定义用户定义类型中参数化类型。
我的工作示例是:
from pydantic import BaseModel
from typing import TypeVar, Dict, Union, Optional
ListSchemaType = TypeVar("ListSchemaType", bound=BaseModel)
GenericPagination = Dict[str, Union[Optional[int], List[ListSchemaType]]]
我需要做的是使用参数调用 GenericPagination。
像这样:
pagination: GenericPagination(schemas.Posts)
我的数据结构如下:
"count": 2,
"limit": 10,
"page": 1,
"results": [{
"name": "Foo",
"url_base": "https://www.bar.cl",
"development_stage": "FOO",
"system_status": "BAR",
"id": 1
}]
}
【问题讨论】: