Skip to content

types

The Types module defines several basic data types for the framework.

Serializable

Bases: Protocol

Serializable is a protocol that defines the interfaces that customizes serialization.

Source code in bridgic/core/types/_serialization.py
@runtime_checkable
class Serializable(Protocol):
    """
    Serializable is a protocol that defines the interfaces that customizes serialization.
    """
    @abstractmethod
    def dump_to_dict(self) -> Dict[str, Any]:
        """
        Dump the object to a dictionary, which will finally be serialized to bytes.
        """
        ...

    @abstractmethod
    def load_from_dict(self, state_dict: Dict[str, Any]) -> None:
        """
        Load the object state from a dictionary previously obtained by deserializing from bytes.
        """
        ...

dump_to_dict

abstractmethod
dump_to_dict() -> Dict[str, Any]

Dump the object to a dictionary, which will finally be serialized to bytes.

Source code in bridgic/core/types/_serialization.py
@abstractmethod
def dump_to_dict(self) -> Dict[str, Any]:
    """
    Dump the object to a dictionary, which will finally be serialized to bytes.
    """
    ...

load_from_dict

abstractmethod
load_from_dict(state_dict: Dict[str, Any]) -> None

Load the object state from a dictionary previously obtained by deserializing from bytes.

Source code in bridgic/core/types/_serialization.py
@abstractmethod
def load_from_dict(self, state_dict: Dict[str, Any]) -> None:
    """
    Load the object state from a dictionary previously obtained by deserializing from bytes.
    """
    ...

Picklable

Bases: Protocol

Picklable is a protocol that defines the interfaces that customizes serialization using pickle.

Notes

If a class implements both Serializable and Picklable, the object of the class will be serialized using the implementation provided by Serializable instead of using pickle.

Source code in bridgic/core/types/_serialization.py
@runtime_checkable
class Picklable(Protocol):
    """
    Picklable is a protocol that defines the interfaces that customizes serialization using pickle.

    Notes
    -----
    If a class implements both Serializable and Picklable, the object of the class will be 
    serialized using the implementation provided by Serializable instead of using pickle.
    """

    def __picklable_marker__(self) -> None:
        """
        This is just a marker method to distinguish Picklable objects from other objects.
        Since it is not necessary to implement this method in the subclass, thus no 
        @abstractmethod is used here.
        """
        ...