from typing import Union
from pathlib import Path
from typing import Any
from typing import TextIO


def fopen(filepath: Union[str, Path], *args: Any, **kwargs: Any) -> TextIO:
    """Open file.

    Args:
        filepath (Union[str, Path]): filepath

    Returns:
        TextIOWrapper: buffer text stream.
    """
    if isinstance(filepath, str):
        return open(filepath, *args, **kwargs)
    elif isinstance(filepath, Path):
        return filepath.open(*args, **kwargs)