
    Ki                     4   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 nd dl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Z/dedefdZ0dedefdZ1dedefdZ2de3fdZ4y)     N)IterableSequence)Flag)	UnionType)	AnnotatedAnyUnionget_args
get_origin)is_class_and_subclass)      )NotRequiredRequired)r      )TypeAliasTypec                     | t         u S N)NoneTypehints    `/home/jay/workspace/scripts/.codegraph-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_secretr/   <   sN     	l# 	>OO//	>D,-	> WT#5t<=	r   c                     t        | d      S )N__dataclass_fields__r'   r   s    r   is_dataclassr2   F   s    4/00r   c                 >    t        | t              xr t        | d      S )N_fields)r   tupler(   r   s    r   is_namedtupler6   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   r5   ITERABLE_TYPES)r   r#   s     r   is_iterable_typerC   [   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     IQ=K0Is   )rA   r$   anyr
   r   )r   rI   s    `r   rF   rF   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rG   rH   s     r   rJ   zis_typeddict.<locals>.<genexpr>z   s     ;q<?;   F__annotations__	__total____required_keys____optional_keys__)rA   r$   rK   r
   r   dictr(   r   s    r   rN   rN   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   rA   rA      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\   rO   s     r   rJ   z#resolve_optional.<locals>.<genexpr>   s     G1+A.GrP   )	rZ   r$   r
   r   
ValueErrorlenr	   r5   NotImplementedError)r   tnon_none_typess      r   r\   r\      s    u%E E?!)%FAAX4EaFNF <==	^		!q! L 
^	q	 UGGGHH!! Gs
   B	B	c                 Z    t        |       } t        |       t        u rt        |       d   } | S Nr   )rZ   r>   r?   r
   r   s    r   r[   r[      s+    u%EE{m#"Lr   c                 P    t        |       t        t        fv rt        |       d   } | S ri   )r   r   r   r
   rj   s    r   r]   r]      s'    %X{33"Lr   c                 P    	 t        | j                        S # t        $ r | cY S w xY wr   )r^   __supertype__AttributeErrorrj   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__rj   s    r   rZ   rZ      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rG   args     r   rJ   z get_hint_name.<locals>.<genexpr>   s     Esc*ErP   [z, c              3   2   K   | ]  }t        |        y wr   rv   rx   s     r   rJ   z get_hint_name.<locals>.<genexpr>   s     "F#=#5"FrP   ]__name___name)rp   r   r   r   r$   joinr
   r   rw   r(   r}   r.   r~   )r   r#   outargss       r   rw   rw      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   )5rW   systypingcollections.abcr   r   enumr   typesr   r   r   r	   r
   r   r8   cyclopts.utilsr   version_infotyping_extensionsr   r   r   r>   r   r   r?   	frozensetlistsetr5   rB   r   r!   r$   r)   r/   r2   r6   r:   r<   r"   rC   rF   rN   rA   r\   r[   r]   r^   rZ   r   rw    r   r   <module>r      s    
  .   > >  0g77,w$M :YsAv&' 
OO	2D4K 2D 25 5 1$ 1K4 Kd -$ -
'$ '@d @	8 	8$ ,	$C C .S T C D C D c c 3 r   