
    lKjc                     h   d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	 d dlm
Z
mZmZmZmZ d dlZd dlmZ ej$                  dk  rd dlmZmZmZ n
d dlmZmZmZ ej$                  d	k\  rd d
lmZ ndZ ed      Z ee
ed f         Zeej
                  eeeeehZ d Z!dedz  de"fdZ#de"fdZ$de"fdZ%de"fdZ&de"fdZ'de"fdZ(de"fdZ)de"fdZ*de"fdZ+de"fdZ,de"fdZ-dedefdZ.dedefdZ/dedefdZ0defdZ1dedefdZ2dede"fdZ3dedefdZ4dedefd Z5dedefd!Z6de7fd"Z8y)#    N)IterableSequence)Flag)	UnionType)	AnnotatedAnyUnionget_args
get_origin)is_class_and_subclass)      )NotRequiredRequiredUnpack)r      )TypeAliasTypec                     | t         u S N)NoneTypehints    e/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/cyclopts/annotations.pyis_nonetyper   &   s    8    type_returnc                     | t         u s| t        u ry| t        u s#| t        u s| t        u s| t
        u st        |       ryt        |       }|t         u xs |t        u S )zChecks if a type is a union.TF)r	   r   strintfloatboolis_annotatedr   )r   origins     r   is_unionr%   *   sY     ~)+ |u|u~$,W\J]FU?1f	11r   c                     t        | d      S )N__pydantic_core_schema__hasattrr   s    r   is_pydanticr*   8   s    4344r   c                     t        | d      xr5 | j                  dk(  xr$ t        | d      xr t        t        | dd            S )zQCheck if a type is a Pydantic secret type (SecretStr, SecretBytes, Secret, etc.).
__module__zpydantic.typesget_secret_valueN)r)   r,   callablegetattrr   s    r   is_pydantic_secretr0   <   sN     	l# 	>OO//	>D,-	> WT#5t<=	r   c                     t        | d      S )N__dataclass_fields__r(   r   s    r   is_dataclassr3   F   s    4/00r   c                 >    t        | t              xr t        | d      S )N_fields)r   tupler)   r   s    r   is_namedtupler7   J   s     u-J'$	2JJr   c                 ,    t        j                  |       S r   )attrshasr   s    r   is_attrsr;   N   s    99T?r   c                 "    t        | t              S )z.Check if a type hint is an enum.Flag subclass.)r   r   r   s    r   is_enum_flagr=   R   s     t,,r   c                 $    t        |       t        u S r   )typeAnnotatedTyper   s    r   r#   r#   W   s    :&&r   c                 `    t        |       } t        |       }t        |t        t                    S )zCheck if a type hint is a collection/iterable type (list, set, tuple, etc.).

    Handles Annotated, Optional, TypeAlias, and NewType wrappers.
    )resolver   r   r6   ITERABLE_TYPES)r   r$   s     r   is_iterable_typerD   [   s)    
 4=DF ~)>??r   c                     t        |       } t        |       rt        fdt        |       D              S t	        |       S )zIndicates if ``target_type`` is in a possibly annotated/unioned ``hint``.

    E.g. ``contains_hint(Union[int, str], str) == True``
    c              3   6   K   | ]  }t        |        y wr   )contains_hint).0xtarget_types     r   	<genexpr>z contains_hint.<locals>.<genexpr>l   s     I.Q=K0.s   )rB   r%   anyr
   r   )r   rJ   s    `r   rG   rG   e   s7    
 4=D~I(4.III$T;77r   c                     t        |       } t        |       rt        d t        |       D              S t	        | t
              syt        | d      xr( t        | d      xr t        | d      xr t        | d      S )zDetermine if a type annotation is a TypedDict.

    This is surprisingly hard! Modified from Beartype's implementation:

        https://github.com/beartype/beartype/blob/main/beartype/_util/hint/pep/proposal/utilpep589.py
    c              3   2   K   | ]  }t        |        y wr   )is_typeddictrH   rI   s     r   rK   zis_typeddict.<locals>.<genexpr>z   s     ;Nq<?N   F__annotations__	__total____required_keys____optional_keys__)rB   r%   rL   r
   r   dictr)   r   s    r   rO   rO   q   sy     4=D~;HTN;;; t, 	'( 	/D+&	/D-.	/ D-.	r   c                     | t         j                  j                  u rt        S d}| |k7  r?| }t	        |       } t        |       } t        |       } t        |       } t        |       } | |k7  r?| S )z$Perform all simplifying resolutions.N)	inspect	Parameteremptyr   resolve_type_aliasresolve_annotatedresolve_optionalresolve_requiredresolve_new_type)r   	type_prevs     r   rB   rB      sr     !!'''
I
9
	"5)!%( ' ' ' 9
 Lr   c                    t        |       } t        |       s| S t        |       D cg c]  }|t        us| }}|st	        d      t        |      dk(  r|d   } | S t        |      dkD  rt        t        d |D                 S t        c c}w )z?Only resolves Union's of None + one other type (i.e. Optional).z!Union type cannot be all NoneType   r   c              3   2   K   | ]  }t        |        y wr   )r]   rP   s     r   rK   z#resolve_optional.<locals>.<genexpr>   s     G1+A.rQ   )	r[   r%   r
   r   
ValueErrorlenr	   r6   NotImplementedError)r   tnon_none_typess      r   r]   r]      s    u%E E?!)%FAAX4EaNF <==	^		!q! L 
^	q	 UGGGHH!! Gs
   B	B	c                 N    t        |       } t        |       rt        |       d   } | S Nr   )r[   r#   r
   r   s    r   r\   r\      s'    u%EE"Lr   c                 |    t        |       syt        |       dd D ]  }	 |j                  c S  y# t        $ r Y w xY w)uE  Return the ``discriminator`` metadata from an ``Annotated[...]`` hint, else ``None``.

    Only inspects ``Annotated`` hints — for other parameterized types (``list[X]``,
    ``dict[K, V]``, etc.) this returns ``None`` so that an incidental
    ``.discriminator`` attribute on a type parameter cannot spuriously match.
    Nrb   )r#   r
   discriminatorAttributeError)
annotationmetas     r   get_annotated_discriminatorrq      sO     
#$QR(	%%% )
   		s   /	;;c                 P    t        |       t        t        fv rt        |       d   } | S rj   )r   r   r   r
   rk   s    r   r^   r^      s'    %X{33"Lr   c                 6    t        t        |             t        u S )zsCheck if a type is ``typing.Unpack[...]`` (PEP-646 / PEP-692).

    Looks through ``Annotated[...]`` wrappers.
    )r   r\   r   rk   s    r   	is_unpackrt      s    
 './699r   c                 Z    t        |       } t        |       t        u rt        |       d   S | S )zUnwrap ``Unpack[X]`` to ``X``. If not an ``Unpack``, returns ``type_`` unchanged.

    Looks through ``Annotated[...]`` wrappers.
    r   )r\   r   r   r
   rk   s    r   resolve_unpackrv      s/    
 e$E%F"q!!Lr   c                 P    	 t        | j                        S # t        $ r | cY S w xY wr   )r_   __supertype__rn   rk   s    r   r_   r_      s,     3 344 s    %%c                 J    t         t        | t               r| j                  S | S )zMResolve TypeAliasType (Python 3.12+ 'type' statement) to its underlying type.)r   
isinstance	__value__rk   s    r   r[   r[      s      Z}%ELr   c                    t        | t              r| S t        |       ry| t        u ryt	        |       r!dj                  d t        |       D              S t        |       x}r;t        |      }t        |       x}r!|ddj                  d |D              z   dz   z  }|S t        | d	      r| j                  S t        | d
d       | j                  S t        |       S )NNoner   |c              3   2   K   | ]  }t        |        y wr   get_hint_namerH   args     r   rK   z get_hint_name.<locals>.<genexpr>   s     Ensc*nrQ   [z, c              3   2   K   | ]  }t        |        y wr   r   r   s     r   rK   z get_hint_name.<locals>.<genexpr>   s     "F#=#5rQ   ]__name___name)rz   r   r   r   r%   joinr
   r   r   r)   r   r/   r   )r   r$   outargss       r   r   r      s    $4s{~xxEhtnEEED!!v!F#D>!4!3"F"FFFLLC
tZ }}tWd#/zzt9r   )9rX   systypingcollections.abcr   r   enumr   typesr   r   r   r	   r
   r   r9   cyclopts.utilsr   version_infotyping_extensionsr   r   r   r   r?   r   r    r@   	frozensetlistsetr6   rC   r   r"   r%   r*   r0   r3   r7   r;   r=   r#   rD   rG   rO   rB   r]   r\   rq   r^   rt   rv   r_   r[   r   r    r   r   <module>r      s    
  .   > >  0g??44w$M :YsAv&' 
OO	2D4K 2D 25 5 1$ 1K4 Kd -$ -
'$ '@d @	8 	8$ ,	$C C .S T s "C D :S :T :# # C D c c 3 r   