Код: Выделить всё
class CustomSettingsSource(PydanticBaseSettingsSource):
# Must implement
def get_field_value(
self, field: FieldInfo, field_name: str
) -> Tuple[Any, str, bool]:
return ({}, "", False)
def __call__(self) -> Dict[str, Any]:
d: Dict[str, Any] = {}
for field_name, field in self.settings_cls.model_fields.items():
# If a field is of type MyModel I do custom processing/fetching
# This returns
print(field.annotation)
# This does not work
if isinstance(field.annotation, MyModel):
# do stuff...
return d
Код: Выделить всё
class Test(MyConfig):
test: MyModel = MyModel(blah="sdfsdf")
Подробнее здесь: https://stackoverflow.com/questions/784 ... ingssource