gemseo.utils.pydantic module#

Tools for Pydantic.

copy_field(name, model, **kwargs)[source]#

Copy a Pydantic model Field, eventually overriden.

Parameters:
  • name (str) -- The name of the field.

  • model (type[BaseModel]) -- The model to copy the field from.

  • **kwargs (Any) -- The arguments of the field to be overriden.

Returns:

The copied field.

Return type:

FieldInfo

create_model(Model, settings_model=None, **settings)[source]#

Create a Pydantic model.

Parameters:
  • Model (type[T]) -- The class of the Pydantic model.

  • settings_model (T | None) -- The settings as a Pydantic model. If None, use **settings.

  • **settings (Any) -- The settings. These arguments are ignored when settings_model is not None.

Returns:

A Pydantic model

Raises:

ValueError -- When the class of the "settings" argument is not Model.

Return type:

T

get_algo_name(settings_model, settings, *, class_name_arg='algo_name')#

Return the name of the class using settings defined as a Pydantic model.

Parameters:
  • settings_model (BaseModel | None) -- The class settings as a Pydantic model. If None, use **settings.

  • settings (dict[str, Any]) -- The settings, including the class name (use the keyword class_name_arg). The function will remove the class_name_arg entry. These settings are ignored when settings_model is not None.

  • class_name_arg (str) --

    The name of the argument to set the class name.

    By default it is set to "algo_name".

Returns:

The class name.

Return type:

str

get_class_name(settings_model, settings, class_name_arg='algo_name')[source]#

Return the name of the class using settings defined as a Pydantic model.

Parameters:
  • settings_model (BaseModel | None) -- The class settings as a Pydantic model. If None, use **settings.

  • settings (dict[str, Any]) -- The settings, including the class name (use the keyword class_name_arg). The function will remove the class_name_arg entry. These settings are ignored when settings_model is not None.

  • class_name_arg (str) --

    The name of the argument to set the class name.

    By default it is set to "algo_name".

Returns:

The class name.

Return type:

str

update_field(model, field_name, **kwargs)[source]#

Update a Field of a Pydantic model.

Parameters:
  • model (type[BaseModel]) -- The model.

  • field_name (str) -- The name of the field.

  • **kwargs (Any) -- The arguments of the field to be overridden. See Field() for the description of the arguments.

Return type:

None