from enum import Enum


def encode_enums(obj):
    """
    Encode enums in yaml parser friendly data type
    :param obj:     object to encode
    :return:        encoded object
    """
    if isinstance(obj, dict):
        new_obj = {}
        for key, value in obj.items():
            value = encode_enums(value)
            new_obj[key] = value
        return new_obj
    elif isinstance(obj, Enum):
        return ['enum', type(obj).__name__, obj.name]
    else:
        return obj