from typing import Type
from typing import Union
from typing import Tuple


def _cached_issubclass(
        cls: Type,
        class_or_tuple: Union[Type, Tuple[Union[Type, Tuple[Type]]]]) -> bool:
    """
    Emulate issubclass builtin to take advantage of functools caching.

    Parameters
    ----------
    obj: object

    class_or_tuple: Union[Type, Tuple[Union[Type, Tuple[Type]]]]
        A single type, a tuple of types (potentially nested)

    Returns
    -------
    bool
        Whether 'cls' is a derived from another class or is the same class.

    """
    return issubclass(cls, class_or_tuple)