def freeze(obj):
    """Returns the immutable version of the object."""

    if hasattr(type(obj), "__freeze__"):
        return obj.__freeze__()
    try:
        handler = _freeze_registry[type(obj)]
    except KeyError:
        pass
    else:
        return handler(obj)
    #if hasattr(type(obj), "__unfreeze__"):
    #    return obj

    msg = "Don't know how to freeze a {} object"
    raise TypeError(msg.format(type(obj)))
Returns the immutable version of the object.
recipes/Python/577895_Protocol_Making_Objects/recipe-577895.py