Deserializer#

class pymc_extras.deserialize.Deserializer(is_type: Callable[[Any], bool], deserialize: Callable[[Any], Any])[source]#

Object to store information required for deserialization.

All deserializers should be stored via the register_deserialization() function instead of creating this object directly.

is_type#

Function to determine if the data is of the correct type.

Type:

IsType

deserialize#

Function to deserialize the data.

Type:

Deserialize

Examples

from typing import Any

class MyClass:
    def __init__(self, value: int):
        self.value = value


from pymc_extras.deserialize import Deserializer


def is_type(data: Any) -> bool:
    return data.keys() == {"value"} and isinstance(data["value"], int)


def deserialize(data: dict) -> MyClass:
    return MyClass(value=data["value"])


deserialize_logic = Deserializer(is_type=is_type, deserialize=deserialize)
__init__(is_type: Callable[[Any], bool], deserialize: Callable[[Any], Any]) None#

Methods

__init__(is_type, deserialize)

Attributes