Пример:
Код: Выделить всё
import pydantic
from typing import Any
class ExampleData(pydantic.BaseModel):
a: int
b: str = pydantic.Field(min_length=10, max_length=10)
@staticmethod
def example() -> dict[str, Any]:
# some logic
return {}
a.example()
"""Returns
{
"a": 1,
"b": "0123456789"
}
"""
Подробнее здесь: https://stackoverflow.com/questions/769 ... h-pydantic
Мобильная версия