from typing import Mapping
from typing import Sequence


def unfreeze(data):
    """
    Inverse of `freeze` defined above. In our usage, we don't actually care
    about whether the data is mutable; we just care that this can be serialized
    as JSON. (`frozendict` instances are not.)
    :param data:
    :return:
    """
    if isinstance(data, Mapping):
        return dict(
            (key, unfreeze(value))
            for key, value in data.items()
        )
    elif isinstance(data, Sequence) and not isinstance(data, str):
        return [unfreeze(value) for value in data]
    return data