twpasolver.basemodel module#

Custom overload of pydantic BaseModel.

pydantic model twpasolver.basemodel.BaseModel[source]#

Bases: BaseModel

Overridden pydantic BaseModel.

This class extends the pydantic BaseModel to exclude serializing optional arguments by default and adds functionality for dumping and loading from files.

Show JSON schema
{
   "title": "BaseModel",
   "description": "Overridden pydantic BaseModel.\n\nThis class extends the pydantic BaseModel to exclude serializing optional arguments by default\nand adds functionality for dumping and loading from files.",
   "type": "object",
   "properties": {}
}

model_dump(exclude_none: bool = True, mode: str = 'json', **kwargs) dict[source]#

Override the model_dump method to customize serialization.

Parameters:
  • exclude_none (bool) – Whether to exclude fields that are None. Defaults to True.

  • mode (str) – The serialization mode. Defaults to “json”.

  • **kwargs – Additional keyword arguments for customization.

Returns:

The serialized representation of the model.

Return type:

dict

classmethod from_file(filename: str)[source]#

Load a model instance from a file.

Parameters:

filename (str) – The path to the file from which to load the model.

Returns:

An instance of the model loaded from the file.

Return type:

BaseModel

dump_to_file(filename: str) None[source]#

Dump the model instance to a file.

Parameters:

filename (str) – The path to the file where the model will be saved.