from typing import Union


def format_indexing_element(indexing_element: Union[int, slice]) -> str:
    """Format an indexing element.

    This is required mainly for slices. The reason is that string representation of slices
    are very long and verbose. To give an example, `x[:, 2:]` will have the following index
    `[slice(None, None, None), slice(2, None, None)]` if printed naively. With this helper,
    it will be formatted as `[:, 2:]`.

    Args:
        indexing_element (Union[int, slice]): indexing element to be formatted

    Returns:
        str: formatted element
    """

    result = ""
    if isinstance(indexing_element, slice):
        if indexing_element.start is not None:
            result += str(indexing_element.start)
        result += ":"
        if indexing_element.stop is not None:
            result += str(indexing_element.stop)
        if indexing_element.step is not None:
            result += ":"
            result += str(indexing_element.step)
    else:
        result += str(indexing_element)
    return result.replace("\n", " ")