from typing import Optional
from typing import Union
import pathlib


def cast_as_path(data: Optional[Union[pathlib.Path, str]]) -> Optional[pathlib.Path]:
    """Ensure the the input is a path.

    Parameters
    ----------
    data: str or pathlib.Path

    Returns
    -------
    pathlib.Path
    """
    if data is None:
        return None

    return pathlib.Path(data)