def convert_to_hashable()

in evalbench/scorers/comparator.py [0:0]


def convert_to_hashable(obj: Any) -> Any | None:
    """convert_to_hashable.

    Args:
      obj:

    Returns:
    """
    if isinstance(obj, dict):
        # Sort the dictionary by keys to ensure consistent string representation
        sorted_dict = {
            key: convert_to_hashable(value) for key, value in sorted(obj.items())
        }
        return json.dumps(sorted_dict, sort_keys=True)
    elif isinstance(obj, (list, tuple)):
        return tuple(convert_to_hashable(item) for item in obj)
    elif isinstance(obj, datetime.datetime):
        return obj.isoformat()
    elif isinstance(obj, decimal.Decimal):
        return float(obj)
    else:
        return obj