from pathlib import Path


def _is_relative_to(path: Path, base_path: Path) -> bool:
    """
    Check that a path can be written relative to a base path.

    This function is needed on Python versions < 3.9.

    Parameters
    ----------
    path: Path
        The path to compare against a base path.
    base_path: Path
        The path that acts as the base, to write `path` relative to.

    Returns
    -------
    True if `path` can be written as a relative path to `base_path`, False otherwise
    """
    try:
        _ = path.relative_to(base_path)
        return True
    except ValueError:
        return False