Код: Выделить всё
from typing import Any
from datetime import datetime
from pydantic import BaseModel
class Model(BaseModel):
timestamp: datetime
number: int
name: str
def construct(dictionary: Any) -> Model:
return Model(**dictionary)
construct({"timestamp": "2024-03-14T10:00:00Z", "number": 7, "name":"Model"})
Если, например, я поставлю dict[str, str] как тип, по которому я получаю ошибки
Код: Выделить всё
Argument 1 to "Model" has incompatible type "**dict[str, str]"; expected "datetime"
Argument 1 to "Model" has incompatible type "**dict[str, str]"; expected "number"
Argument 1 to "Model" has incompatible type "**dict[str, str]"; expected "name"
Источник: https://stackoverflow.com/questions/781 ... tic-kwargs