from typing import Any
import io


def isio(obj: Any, *, read: bool = False, write: bool = False) -> bool:
    """Determine if object is IO like and is read and/or write.

    .. note::

        Falls back to :code:`isinstnace(obj, io.IOBase)` if neither `read` nor
        `write` is True.

    :param obj:
        Object to check if it is an IO like object.
    :param read:
        Require `obj` to be readable if True.
    :param write:
        Require `obj` to be writable if True.

    :return:
        True if the given `obj` is readable and/or writeable as defined by the
        `read` and `write` arguments.
    """
    if read or write:
        return (not read or hasattr(obj, "read")) and (
            not write or hasattr(obj, "write")
        )
    return isinstance(obj, io.IOBase)