def METHOD_NAME(
    cls, exception: Union[BaseException, Type[BaseException]]
) -> List[str]:
    """For an Exception, return a list of all its base classes that inherit from
    Exception.
    Parameters
    ----------
    exception:
        The exception or exception class whose ancestors should be retrieved
    Returns
    -------
    A list of all base classes (and their base classes, etc.) that inherit
    from Exception. They will be in no particular order.
    """
    if isinstance(exception, BaseException):
        exception_type = type(exception)
    else:
        exception_type = exception
    ancestors = []
    to_traverse = [exception_type]
    self_classpath = f"{exception_type.__module__}.{exception_type.__name__}"
    while len(to_traverse) > 0:
        class_ = to_traverse.pop()
        for base in class_.__bases__:
            if not issubclass(base, Exception):
                # only interested in exception classes
                continue
            classpath = f"{base.__module__}.{base.__name__}"
            if classpath not in ancestors and self_classpath != classpath:
                ancestors.append(classpath)
                to_traverse.append(base)
    return ancestors