def coerce_enum(value, cls):
    """Attempt to coerce a given string or int value into an Enum instance."""

    if isinstance(value, int):
        value = cls(value)

    elif isinstance(value, str):
        value = cls[value]

    return value