project/alcatraz/alcatraz/clusters/_serialization.py [19:39]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class SerializableBaseModel(BaseModel):
    """
    A model which, when serialized, saves the class and module name of the
    current instance to secret fields. This allows the instance to be
    deserialized later without knowing the class in advance.

    Copied from nanoeval as there's no good place to put it without duplication.
    """

    @model_serializer(when_used="always", mode="wrap")
    def _save_class_and_module_fields(
        self, serializer: SerializerFunctionWrapHandler, info: SerializationInfo
    ) -> dict[str, Any]:
        del info
        data: dict[str, Any] = serializer(self)
        data["__class_name__"] = self.__class__.__name__
        data["__module_name__"] = self.__module__
        return data

    @classmethod
    def deserialize(cls, data: dict[str, Any]) -> Self:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



project/nanoeval/nanoeval/solvers/computer_tasks/_serializable_base_model.py [10:34]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class SerializableBaseModel(BaseModel):
    """
    A model which, when serialized, saves the class and module name of the
    current instance to secret fields. This allows the instance to be
    deserialized later without knowing the class in advance.

    This should only be used with TRUSTED DATA, as the deserializer can
    import any class.

    Serialize: `d.model_dump`
    Deserialize: Class.deserialize(dict)`
    """

    @model_serializer(when_used="always", mode="wrap")
    def _save_class_and_module_fields(
        self, serializer: SerializerFunctionWrapHandler, info: SerializationInfo
    ) -> dict[str, Any]:
        del info
        data: dict[str, Any] = serializer(self)
        data["__class_name__"] = self.__class__.__name__
        data["__module_name__"] = self.__module__
        return data

    @classmethod
    def deserialize(cls, data: dict[str, Any]) -> Self:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



