from typing import Optional
from typing import List


def _convert_names(
    names, max_levels: Optional[int] = None, err_msg: Optional[str] = None
) -> List[str]:
    """Helper function that converts arguments of index, columns, values to list.

    Also performs check on number of levels. If it exceeds `max_levels`,
    raise ValueError with `err_msg`.
    """
    result = None
    if isinstance(names, str):
        result = [names]
    elif isinstance(names, list):
        result = names
    else:
        result = list(names)

    if max_levels and len(result) > max_levels:
        raise ValueError(err_msg)

    return result