def str_to_iterable(func, iterable_str):
    """Converts a string representation of an iterable to an iterable."""
    if not isinstance(iterable_str, str):
        return func()

    iterable_str = iterable_str.strip(" ")
    if not iterable_str:
        return func()

    is_in_iterable = True
    if iterable_str[0] == "(":
        if not iterable_str.endswith(")"):
            return func()
    elif iterable_str[0] == "{":
        if not iterable_str.endswith("}"):
            return func()
    elif iterable_str[0] == "[":
        if not iterable_str.endswith("]"):
            return func()
    else:
        is_in_iterable = False

    # We may have a nested object, so try to use eval first
    try:
        eval_ = ast.literal_eval(iterable_str)
        if eval_ is None:
            return ""
        if isinstance(eval_, (int, float)):
            eval_ = [
                eval_,
            ]
        return func(eval_)
    except (SyntaxError, ValueError):
        if is_in_iterable:
            iterable_str = iterable_str[1:-1]
        items = [item.strip() for item in iterable_str.split(",")]
        return func(items)
Converts a string representation of an iterable to an iterable.
vlmeval/dataset/utils/megabench/scoring/common/conversions.py