Код: Выделить всё
class Foo(BaseModel):
a: str = Field(
meta_field=("some extra data a"), # pyright: ignore
)
b: str = Field(
meta_field=("some extra data b"), # pyright: ignore
)
c: str = Field(
meta_field=("some extra data c"), # pyright: ignore
)
@classmethod
def summarize_meta_fields(cls, **kwargs) -> dict[str, str]:
schema = cls.model_json_schema()
return {
k: schema["properties"][k]["meta_field"] for k in schema["properties"].keys()
}
def configure_meta_data(**kwargs) -> None:
for k in kwargs:
if k not in Foo.model_fields:
raise ValueError(f"Field {k} not found in SummeryTube model")
Foo.model_fields[k].json_schema_extra["meta_field"] = kwargs[k]
[img]https: //i.sstatic.net/8MshlpvT.png[/img]
со следующим текстом:
Код: Выделить всё
Object of type "(JsonDict) -> None" is not subscriptablePylancereportIndexIssue
Object of type "None" is not subscriptablePylancereportOptionalSubscript
Подробнее здесь: https://stackoverflow.com/questions/791 ... ght-issues
Мобильная версия