
    k7i                         S SK r S SKrS SKJr  S SKJr  S SKJrJrJ	r	J
r
Jr  S SKrS SKJr  \R                  S:  a	  S SKJrJr  OS SKJrJr  \R                  S:  a  S S	KJr  OSr\" S5      r\" \\S 4   5      rS
 rS\S-  S\4S jrS\4S jrS\4S jrS\4S jrS\4S jrS\4S jrS\4S jr S\4S jr!S\4S jr"S\4S jr#S\S\4S jr$S\S\4S jr%S\S\4S jr&S\S\4S jr'S\S\4S jr(S\S\4S jr)S\*4S jr+g)    N)Flag)	UnionType)	AnnotatedAnyUnionget_args
get_origin)is_class_and_subclass)      )NotRequiredRequired)r      )TypeAliasTypec                     U [         L $ N)NoneTypehints    N/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/annotations.pyis_nonetyper      s    8    type_returnc                     U [         L d	  U [        L a  gU [        L d+  U [        L d"  U [        L d  U [
        L d  [        U 5      (       a  g[        U 5      nU[         L =(       d    U[        L $ )zChecks if a type is a union.TF)r   r   strintfloatboolis_annotatedr	   )r   origins     r   is_unionr"      s\     ~)+ |u|u~$,W\J]J]FU?1f	11r   c                     [        U S5      $ )N__pydantic_core_schema__hasattrr   s    r   is_pydanticr'   ,   s    4344r   c                     [        U S5      =(       a?    U R                  S:H  =(       a)    [        U S5      =(       a    [        [        U SS5      5      $ )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_secretr-   0   sN     	l# 	>OO//	>D,-	> WT#5t<=	r   c                     [        U S5      $ )N__dataclass_fields__r%   r   s    r   is_dataclassr0   :   s    4/00r   c                 H    [        U [        5      =(       a    [        U S5      $ )N_fields)r
   tupler&   r   s    r   is_namedtupler4   >   s     u-J'$	2JJr   c                 .    [         R                  " U 5      $ r   )attrshasr   s    r   is_attrsr8   B   s    99T?r   c                 "    [        U [        5      $ )z.Check if a type hint is an enum.Flag subclass.)r
   r   r   s    r   is_enum_flagr:   F   s     t,,r   c                 $    [        U 5      [        L $ r   )typeAnnotatedTyper   s    r   r    r    K   s    :&&r   c                    ^ [        U 5      n [        U 5      (       a  [        U4S j[        U 5       5       5      $ [	        U T5      $ )zIndicates if ``target_type`` is in a possibly annotated/unioned ``hint``.

E.g. ``contains_hint(Union[int, str], str) == True``
c              3   <   >#    U  H  n[        UT5      v   M     g 7fr   )contains_hint).0xtarget_types     r   	<genexpr> contains_hint.<locals>.<genexpr>V   s     I.Q=K00.s   )resolver"   anyr   r
   )r   rC   s    `r   r@   r@   O   s9    
 4=D~~I(4.III$T;77r   c                 $   [        U 5      n [        U 5      (       a  [        S [        U 5       5       5      $ [	        U [
        5      (       d  g[        U S5      =(       a2    [        U S5      =(       a    [        U S5      =(       a    [        U S5      $ )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   8   #    U  H  n[        U5      v   M     g 7fr   )is_typeddictrA   rB   s     r   rD   is_typeddict.<locals>.<genexpr>d   s     ;Nq<??N   F__annotations__	__total____required_keys____optional_keys__)rF   r"   rG   r   r
   dictr&   r   s    r   rJ   rJ   [   s~     4=D~~;HTN;;; t,, 	'( 	/D+&	/D-.	/ D-.	r   c                     U [         R                  R                  L a  [        $ SnX:w  a@  U n[	        U 5      n [        U 5      n [        U 5      n [        U 5      n [        U 5      n X:w  a  M@  U $ )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   rF   rF   q   sn     !!'''
I

	"5)!%( ' ' ' 
 Lr   c                 <   [        U 5      n [        U 5      (       d  U $ [        U 5       Vs/ s H  o[        Ld  M  UPM     nnU(       d  [	        S5      e[        U5      S:X  a  US   n U $ [        U5      S:  a  [        [        S U 5       5         $ [        es  snf )z?Only resolves Union's of None + one other type (i.e. Optional).z!Union type cannot be all NoneType   r   c              3   8   #    U  H  n[        U5      v   M     g 7fr   )rY   rK   s     r   rD   #resolve_optional.<locals>.<genexpr>   s     G1+A..rM   )	rW   r"   r   r   
ValueErrorlenr   r3   NotImplementedError)r   tnon_none_typess      r   rY   rY      s    u%E E??!)%FAX4EaNF <==	^		!q! L 
^	q	 UGGGHH!! Gs
   BBc                 \    [        U 5      n [        U 5      [        L a  [        U 5      S   n U $ Nr   )rW   r<   r=   r   r   s    r   rX   rX      s+    u%EE{m#"Lr   c                 T    [        U 5      [        [        4;   a  [        U 5      S   n U $ rg   )r	   r   r   r   rh   s    r   rZ   rZ      s'    %X{33"Lr   c                 R     [        U R                  5      $ ! [         a    U s $ f = fr   )r[   __supertype__AttributeErrorrh   s    r   r[   r[      s,     3 344 s    &&c                 V    [         b!  [        U [         5      (       a  U R                  $ U $ )zMResolve TypeAliasType (Python 3.12+ 'type' statement) to its underlying type.)r   
isinstance	__value__rh   s    r   rW   rW      s#     Z}%E%ELr   c                    [        U [        5      (       a  U $ [        U 5      (       a  gU [        L a  g[	        U 5      (       a!  SR                  S [        U 5       5       5      $ [        U 5      =n(       a@  [        U5      n[        U 5      =n(       a!  USSR                  S U 5       5      -   S-   -  nU$ [        U S	5      (       a  U R                  $ [        U S
S 5      b  U R                  $ [        U 5      $ )NNoner   |c              3   8   #    U  H  n[        U5      v   M     g 7fr   get_hint_namerA   args     r   rD    get_hint_name.<locals>.<genexpr>   s     Ensc**nrM   [z, c              3   8   #    U  H  n[        U5      v   M     g 7fr   rt   rv   s     r   rD   rx      s     "F#=#5#5rM   ]__name___name)rn   r   r   r   r"   joinr   r	   ru   r&   r|   r,   r}   )r   r!   outargss       r   ru   ru      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   ),rT   sysenumr   typesr   typingr   r   r   r   r	   r6   cyclopts.utilsr
   version_infotyping_extensionsr   r   r   r<   r   r   r=   r   r   r"   r'   r-   r0   r4   r8   r:   r    r@   rJ   rF   rY   rX   rZ   r[   rW   r   ru    r   r   <module>r      sr    
   > >  0g77,w$M :YsAv&'2D4K 2D 25 5 1$ 1K4 Kd -$ -
'$ '	8 	8$ ,	$C C .S T C D C D c c 3 r   