# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/50_chic.ipynb.

# %% auto 0
__all__ = ['boolfunc', 'flagfunc', 'numeric', 'numbers', 'emptystring', 'notemptystring', 'pttn', 'dirpath', 'dirnames',
           'filenames', 'enummember', 'layer', 'boundingbox', 'coordinate', 'coord', 'point', 'xypos', 'width',
           'height', 'rect', 'clsint', 'clsset', 'clsstr', 'clsobj', 'clsbool', 'clsbool01', 'clscall', 'clstype',
           'clslist', 'clsfloat', 'clsnum', 'clscomplex', 'slc', 'slcs', 'path', 'boolidx', 'bidx', 'catidx', 'cidx',
           'anndata', 'anndatas', 'series', 'index', 'lit', 'boolcall', 'boolcallq', 'boolcalls', 'docgenfn',
           'axesidxs', 'axesidxsq', 'argstype', 'sysexcinfotype', 'sysformatstyle', 'bbox', 'rgb', 'rgba', 'color',
           'imagesize', 'videosize', 'imagesizeq', 'videosizeq', 'mixin']

# %% ../nbs/50_chic.ipynb 6
from enum import member, _EnumDict

# %% ../nbs/50_chic.ipynb 8
from types import ModuleType, TracebackType

from typing import (
    Any, Dict, List, Set, Self, Type, Union, Tuple, Generic, Callable, Literal, 
    TypeVar, ClassVar, TypeAlias, ParamSpec, Optional,
    Iterable, ForwardRef, Mapping, TypeGuard
)

# %% ../nbs/50_chic.ipynb 10
#| export

# %% ../nbs/50_chic.ipynb 12
#| export

# %% ../nbs/50_chic.ipynb 14
from .cons import RETURN
from .type import P, T, Ts, O
from .enum import Species
from .misc import getretann
from .base import Duck

from . import grds, duck

# %% ../nbs/50_chic.ipynb 17
# bool01 = TypeVar('bool01', bound=duck.bool01)

# %% ../nbs/50_chic.ipynb 19
class boolcall(duck.annreturn[P, duck.bool01]):
    '''A type alias for a boolean or a callable that returns a boolean.'''
    __ducktype__ = (duck.bool01, Callable)
    @classmethod
    def __guard__(cls, obj: Any) -> bool:
        return super().__instancecheck__(obj) and getretann(obj) in (bool, duck.bool01)
  
class boolcallq(boolcall): 
    '''A type alias for a boolean or a callable that returns a boolean.'''
    __species__ = Species.OPT
      
class boolcalls(duck.bools, Duck[List[Callable[P, duck.bool01]]]): 
    '''A type alias for a list of booleans or callables that each returns a boolean.''';
    __expected__ = dict(dtype=boolcall)
    
boolfunc: TypeAlias = boolcall
'''A type alias for a function that returns a boolean.''';

flagfunc: TypeAlias = boolfunc
'''A type alias for a "flag" function i.e. a function that returns a boolean.''';

# %% ../nbs/50_chic.ipynb 20
numeric: TypeAlias = duck.num
'''A type alias for a "numeric" value i.e. `int`, `float`, `complex`, or `Number`''';

numbers: TypeAlias = duck.nums
'''A type alias for a list of "numeric" values i.e. `int`, `float`, `complex`, or `Number`''';

# %% ../nbs/50_chic.ipynb 22
emptystring = duck.nilstr
'''A type alias for the empty string `''` (aka the nil string)''';

notemptystring = duck.notnilstr
'''A type alias for not emptystring (not `''`, the empty string)''';

pttn: TypeAlias = duck.pattern
'''A type alias for `re.Pattern`''';

# %% ../nbs/50_chic.ipynb 23
class docgenfn(duck.annreturn[P, str]): 
    '''A type alias for a callable that returns as string, which should be a valid docstring.''';
    __ducktype__ = (Callable, )
    __retannot__ = str

# %% ../nbs/50_chic.ipynb 25
dirpath: TypeAlias = duck.pathlike
'''A type alias for a path to a directory.''';

dirnames: TypeAlias = duck.paths
'''A type alias for a list of paths to directories.''';

filenames: TypeAlias = duck.paths
'''A type alias for a list of paths to filenames.''';

# %% ../nbs/50_chic.ipynb 27
enummember: TypeAlias = duck.enumauto
'''A type alias for an `auto()` generated enum `member`.''';

# %% ../nbs/50_chic.ipynb 29
class axesidxs(duck.ints, Generic[*Ts]): 
    '''A type alias for an integer or a tuple of integers representing 
    the index / indicies of the axes of a tensor.'''
    __ducktype__ = (int, duck.ints, )
    
class axesidxsq(duck.ints, Generic[*Ts]): 
    '''A type alias for an integer or a tuple of integers representing 
    the index / indicies of the axes of a tensor.'''
    __species__ = Species.OPT
    

layer: TypeAlias = duck.ptmodule
'''A type alias for a PyTorch layer.''';

# %% ../nbs/50_chic.ipynb 31
class argstype(Duck[type[tuple[object, ...]] | type[Mapping[str, object]]]):
    '''A type alias for argument types.''';
    __ducktype__ = (tuple, Mapping[str, object], Mapping, )
    __expected__ = dict(dtype=object)
    
    
class sysexcinfotype(Duck[
    type[tuple[type[BaseException], BaseException, TracebackType | None]] | \
    type[tuple[None, None, None]]
]):
    '''A type alias for `SysExcInfoType` types i.e.
    `(type[BaseException], BaseException, TracebackType | None)` or `(None, None, None)`''';
    __ducktype__ = (type(BaseException), BaseException, Optional[TracebackType], )
    __expected__ = dict(dtype=object)
    
    
class sysformatstyle(Duck[Literal['%', '{', '$']]):
    __ducktype__ = ('%', '{', '$', )

# %% ../nbs/50_chic.ipynb 33
class bbox(duck.itertype[T: duck.int2, T: duck.int2], Generic[T, O]):
    '''A type alias representing a BoundingBox i.e. a tuple of 
    `(upper_left: int, upper_right: int), (lower_left: int, lower_right: int)`.'''; 
    __expected__ = dict(dtype=duck.int2)
   
    
boundingbox: TypeAlias = bbox[duck.int2, duck.int2]
 
coordinate: TypeAlias = duck.nums
'''A type alias for a coordinate i.e. a tuple of numbers representing a point in space.''';

coord: TypeAlias = coordinate
'''A type alias for a coordinate (`coord`) i.e. a tuple of numbers representing a point in space.''';

point: TypeAlias = coordinate
'''A type alias for a point i.e. $(x_1, x_2, ..., x_n)$.''';

xypos: TypeAlias = duck.int2
'''A type alias for an 2D-point in space i.e. `(x, y)`.'''; 

width: TypeAlias = int
'''the width of an object''';

height: TypeAlias = int
'''the height of an object''';

rect: TypeAlias = duck.int2
'''A type alias an 2D tuple representing the `width` and `height` of rectangle.'''; 

# %% ../nbs/50_chic.ipynb 35
class rgb(duck.int3, Generic[*Ts]):
    '''A type alias for an RGB color tuple `(r: int, g: int, b: int)` 
    where, `r`, `g`, & `b` are each integers between 0 and 255.'''
    @classmethod
    def __guard__(cls, obj: Any) -> bool:
        return super().__guard__(obj) and all(0 <= obj[i] <= 255 for i in range(3))
        
class rgba(duck.len4, duck.size[int, int, int, float], Generic[*Ts]):
    '''A type alias for a RGBA color tuple `(r: int, g: int, b: int, a: float)` 
    where, `r`, `g`, & `b` are each integers between 0 and 255 and `a` is a float between 0 and 1.0.'''
    @classmethod
    def __guard__(cls, obj: Any) -> bool:
        return duck.size(obj) and len(obj) == 4, rgb(obj[:-1]) and 0 <= obj[-1] <= 1
    
class color(Duck[rgb | rgba], Generic[*Ts]):
    '''A type alias for either a RGB or a RGBA color tuple `(r: int, g: int, b: int, a: float)` 
    where, `r`, `g`, & `b` are each integers between 0 and 255 and `a`
    is a float between 0 and 1.0.'''
    __ducktype__ = (rgb, rgba,)

# %% ../nbs/50_chic.ipynb 37
class imagesize(Duck[duck.int2, duck.int3]):
    '''A type alias for an image size i.e. a tuple of `(width: int, height: int)` or
    `(width: int, height: int, channels: int)`.'''
    __ducktype__ = (duck.int2, duck.int3, )

class videosize(Duck[duck.int3, duck.int4]):
    '''A type alias for a video size i.e. a tuple of `(width: int, height: int, channels: int)` or
    `(width: int, height: int, channels: int, frames: int)`.'''
    __ducktype__ = (duck.int3, duck.int4, )

class imagesizeq(imagesize):
    '''A type alias for an optional image size i.e. a tuple of `(width: int, height: int)` or
    `(width: int, height: int, channels: int)`.'''
    __species__ = Species.OPT
    
class videosizeq(videosize):
    '''A type alias for an optional video size i.e. a tuple of `(width: int, height: int, channels: int)` or
    `(width: int, height: int, channels: int, frames: int)`.'''
    __species__ = Species.OPT

# %% ../nbs/50_chic.ipynb 39
class mixin(Duck[Union[Tuple[Type, Callable], 'MixinType']]):
    __ducktype__ = (tuple, 'MixinType', )
    @classmethod
    def __guard__(cls, obj: Any) -> bool:
        if super().__instancecheck__(obj): return True
        return grds.istuple(obj) and len(obj) == 2 and isinstance(obj[0], type) and callable(obj[1])

# %% ../nbs/50_chic.ipynb 41
clsint = ClassVar[int]
'''A type alias for a class variable of type `int`.''';

clsset = ClassVar[set]
'''A type alias for a class variable of type `set`.''';

clsstr = ClassVar[str]
'''A type alias for a class variable of type `str`.''';

clsobj = ClassVar[object]
'''A type alias for a class variable of type `object`.''';

clsbool = ClassVar[bool]
'''A type alias for a class variable of type `bool`.''';

clsbool01 = ClassVar[duck.bool01]
'''A type alias for a class variable of type `bool01`.''';

clscall = ClassVar[Callable]
'''A type alias for a class variable of type `Callable`.''';

clstype = ClassVar[type]
'''A type alias for a class variable of type `type`.''';

clslist = ClassVar[list]
'''A type alias for a class variable of type `list`.''';

clsfloat = ClassVar[float]
'''A type alias for a class variable of type `float`.''';

clsnum = ClassVar[duck.num]
'''A type alias for a class variable of type `num`.''';

clscomplex = ClassVar[complex]
'''A type alias for a class variable of type `complex`.''';


# %% ../nbs/50_chic.ipynb 43
slc: TypeAlias = duck.slicespec
'''A type alias for a slice or the integers corresponding to the
`(start, stop, step)` of a slice.'''
    
slcs: TypeAlias = duck.slicespecs
'''A type alias for a list of slices or the integers corresponding to the
`(start, stop, step)` of a slice.''';

# %% ../nbs/50_chic.ipynb 45
path: TypeAlias = duck.pathlike
'''A type alias for `os.PathLike`, `pathlib.Path`, `pathlib.PosixPath`''';

# %% ../nbs/50_chic.ipynb 47
boolidx: TypeAlias = duck.boolindex
'''A type alias for a boolean index.''';
bidx: TypeAlias = duck.boolindex
'''A type alias for a boolean index.''';
catidx: TypeAlias = duck.catindex
'''A type alias for a categorical index.''';
cidx: TypeAlias = duck.catindex
'''A type alias for a categorical index.''';


# %% ../nbs/50_chic.ipynb 49
anndata: TypeAlias = duck.adata
'''A type alias for an `AnnData` object.''';

anndatas: TypeAlias = duck.adatas
'''A type alias for a list of  `AnnData` object.''';

series: TypeAlias = duck.pdseries
'''A type alias for a `pandas.Series` object.''';

index: TypeAlias = duck.pdindex
'''A type alias for a `pandas.Index` object.''';

# %% ../nbs/50_chic.ipynb 51
lit: TypeAlias = duck.literal
'''A type alias for a `Literal` type.''';
