qilisdk.utils.serialization
Attributes
Exceptions
Custom exception for serialization errors. |
|
Custom exception for deserialization errors. |
Functions
|
Serialize an object to a YAML string. |
|
Serialize an object to a YAML file. |
|
Deserialize a YAML string to an object. |
Deserialize a YAML file to an object. |
Module Contents
- exception SerializationError[font]
Bases:
ExceptionCustom exception for serialization errors.
Initialize self. See help(type(self)) for accurate signature.
- exception DeserializationError[font]
Bases:
ExceptionCustom exception for deserialization errors.
Initialize self. See help(type(self)) for accurate signature.
- serialize(obj: Any) str[font]
Serialize an object to a YAML string.
- Paràmetres:
obj (
Any) – The object to serialize.- Llença:
SerializationError – If serialization fails.
- Retorna:
The serialized YAML string.
- Tipus de retorn:
str
- serialize_to(obj: Any, file: str) None[font]
Serialize an object to a YAML file.
- Paràmetres:
obj (
Any) – The object to serialize.file (
str) – The file path where the YAML data will be written.
- Llença:
SerializationError – If serialization to file fails.
- deserialize(string: str) Any[font]
- deserialize(string: str, cls: type[T]) T
Deserialize a YAML string to an object.
- Paràmetres:
string (
str) – The YAML string to deserialize.cls (
type[T], optional) – The class type to cast the deserialized object to. Defaults to None.
- Llença:
DeserializationError – If deserialization fails or the resulting object is not of the specified type.
- Retorna:
The deserialized object, optionally cast to the specified class type.
- Tipus de retorn:
Any | T
- deserialize_from(file: str) Any[font]
- deserialize_from(file: str, cls: type[T]) T
Deserialize a YAML file to an object.
- Paràmetres:
file (
str) – The file path of the YAML file to deserialize.cls (
type[T], optional) – The class type to cast the deserialized object to. Defaults to None.
- Llença:
DeserializationError – If deserialization fails or the resulting object is not of the specified type.
- Retorna:
The deserialized object, optionally cast to the specified class type.
- Tipus de retorn:
Any | T