# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/91_tgrd.ipynb.

# %% auto 0
__all__ = ['T', 'P', 'TypeLike', 'GuardFunc', 'istypeq', 'isinst', 'isinstq', 'isof']

# %% ../nbs/91_tgrd.ipynb 4
from types import NoneType
from typing import Type, Tuple, Union, Callable, TypeAlias, TypeGuard, TypeVar, ParamSpec
T = TypeVar('T')
P = ParamSpec('P')

# %% ../nbs/91_tgrd.ipynb 6
TypeLike:  TypeAlias = Union[Type, TypeAlias, Type[T]]
GuardFunc: TypeAlias = Callable[P, TypeGuard[TypeLike]]

# %% ../nbs/91_tgrd.ipynb 7
def istypeq(x: T, t: TypeLike) -> TypeGuard[Union[T, NoneType]]:
    '''Check if `x` is of type `t` or `NoneType`'''
    return isinstance(x, (t, NoneType))

def isinst(x: T, t: TypeLike) -> TypeGuard[T]:
    '''Alias for `isinstance`'''
    return isinstance(x, t)

def isinstq(x: T, t: TypeLike) -> TypeGuard[Union[T, NoneType]]:
    '''Alias for `isinstance`'''
    return isinstance(x, (t, NoneType))

def isof(x: T, t: Tuple[TypeLike, ...]) -> TypeGuard[TypeLike]:
    '''Alias for `isinstance`'''
    return isinst(x, t)
