from typing import Callable
from typing import Any
from typing import Union
from pathlib import Path
import errno


def _try_rm_wrapper(func: Callable[[Any], Any], fpath: Union[str, Path]) -> bool:
    """Takes a function (e.g. os.remove / os.rmdir), and attempts to remove a
    path; returns true if that path was succesfully remove, and false if it did
    not exist."""
    try:
        func(fpath)
        return True
    except OSError as error:
        if error.errno != errno.ENOENT:
            raise
        return False