qilisdk.utils.serialization

Attributes

T

Exceptions

SerializationError

Custom exception for serialization errors.

DeserializationError

Custom exception for deserialization errors.

Functions

serialize(→ str)

Serialize an object to a YAML string.

serialize_to(→ None)

Serialize an object to a YAML file.

deserialize(…)

Deserialize a YAML string to an object.

deserialize_from(…)

Deserialize a YAML file to an object.

Module Contents

T[font]
exception SerializationError[font]

Bases: Exception

Custom exception for serialization errors.

Initialize self. See help(type(self)) for accurate signature.

exception DeserializationError[font]

Bases: Exception

Custom 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