
    lKj:                     0   U d dl Zd dlZd dlZd dlZd dlZd dlZd dlZd dl mZm	Z	m
Z
 d dlmZmZmZ d dlmZmZ d dlmZmZ d dlmZmZmZmZmZmZmZ ej6                  dk\  rd dlmZ ndZd d	lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% d d
l&m'Z'm(Z( d dl)m*Z*m+Z+ d dl,m-Z-m.Z.m/Z/m0Z0m1Z1 ej6                  dk\  rd dlmZ ndZerd dl2m3Z3  ed      Z4 ede      Z5 ede      Z6e7e7e8   e9e9e8   e:e:e8   e;e;e8df   e<e<e8e8f   iZ=e<e>e>f   e?d<   e	e9ej                  e9e
e9ej                  j                  e:ej                  j                  e:ej                  j                  e9ej                  j                  e<ej                  j                  e<iZFe<e>e>f   e?d<   e<e8ee
e8   df   f   ZGde8deHfdZIde8deJfdZKde8deLfdZMde8deNfdZOde8defdZPde8defdZQde8defdZRde8deSfdZTd e>e5   d!ed"e8f   d#ee8ge8f   de5fd$ZUd%e>e6   d&e	e8   e	d"   z  d#ee8ge8f   de6fd'ZVeHeIeJeKeLeMeNeOeePeeQeeReSeTiZWe<eef   e?d(<   d e>e   d&d"d)ee>e8gef   dz  d#ee8ge8f   de;f
d*ZX	 d:d+e<d e>d!d,ddfd-ZYd ed+e<d.e<d)edz  d#ee8ge8f   f
d/ZZd!d"d ed0ej                  de8fd1Z\d e>e4   d+e<e8ef   de4fd2Z]d e>e4   d!e
d"   d.e<e8d3f   d4ede4f
d5Z^d!ed"e
d"   f   d)eee8gef   dz  d#ee8ge8f   fd6Z_	 	 d;d ed&e
e8   e
d"   z  eGz  d)ee>e8gef   dz  d#ee8ge8f   dz  fd7Z`d<d ed8eHde;eJeHf   fd9Zay)=    N)CallableIterableSequence)datedatetime	timedelta)EnumFlag)partialreduce)TYPE_CHECKINGAnyLiteralTypeVarUnionget_args
get_origin)      )TypeAliasType)ITERABLE_TYPESget_annotated_discriminatoris_annotatedis_enum_flagis_nonetypeis_unionresolveresolve_optional)CoercionErrorValidationError)	FieldInfoget_field_infos)UNSETdefault_name_transformgrouper
is_builtinis_class_and_subclassTokenTE)boundF._implicit_iterable_type_mapping"_abstract_to_concrete_type_mappingNestedCliArgssreturnc                 V    | j                         } | dv ry| dv ryt        t              )N>   0fnnofalseF>   1tyyestrueT)target_type)lowerr   boolr1   s    b/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/cyclopts/_convert.py_boolrC   P   s2    		A**	
,	, --    c                 (   | j                         } | j                  d      rt        | d      S | j                  d      rt        | d      S | j                  d      rt        | d      S d| v rt        t        t	        |                   S t        |       S )N0x   0o   0b   .)r?   
startswithintroundfloatrA   s    rB   _intrQ   [   sz    		A||D1bz	
d	1ay	
d	1ay	 5q?##1vrD   c                     t        | d      S )Nutf8)encoding)bytesrA   s    rB   _bytesrV   l   s    V$$rD   c                 *    t        t        |             S N)	bytearrayrV   rA   s    rB   
_bytearrayrZ   p   s    VAYrD   c                 ,    t        j                  |       S )zDParse a date string.

    Returns
    -------
    datetime.date
    )r   fromisoformatrA   s    rB   _dater]   t   s     a  rD   c                     	 t        j                  |       S # t        $ r7 t        j                  | j                         j	                  ddd            cY S w xY w)zLParse a datetime string.

    Returns
    -------
    datetime.datetime
     r*      )r   r\   
ValueErrorstripreplacerA   s    rB   	_datetimerd   ~   sR    F%%a(( F %%aggi&7&7S!&DEE	Fs    =AAc                    d}| j                  d      rd}| dd } t        j                  d|       }|st        d|        d}|D ]p  \  }}}t	        |      }|d	k(  r||z  }|d
k(  r	||dz  z  }+|dk(  r	||dz  z  }9|dk(  r	||dz  z  }G|dk(  r	||dz  z  }U|dk(  r	||dz  z  }c|dk(  si||dz  z  }r |r| }t        |      S )zParse a timedelta string.F-Tr`   Nz((\d+\.\d+|\d+)([smhdwMy]))z!Could not parse duration string: r   r1   m<   hi  diQ wi:	 Mi ' r;   i3)seconds)rM   refindallra   rP   r   )r1   negativematchesrm   _valueunits          rB   
_timedeltaru      s   H||CabEjj7;G<QC@AAG!5$e3;uGS[urz!GS[ut|#GS[uu}$GS[uv~%GS[uw&GS[ux''G# "& (W%%rD   c                     | j                  d      }dt        |      cxk  rdk  rn n	 t        d |D         S t	        t        d|  d      # t        $ r Y  w xY w)zParse a string in slice notation.

    Examples: ``0:3``, ``:10``, ``0:100:5``, ``-10:``. Empty fields map to :obj:`None`.

    Returns
    -------
    slice
    :rK   r   c              3   V   K   | ]!  }|j                         rt        |      nd  # y wrX   )rb   rN   ).0parts     rB   	<genexpr>z_slice.<locals>.<genexpr>   s"     Q54

3t9$>5s   ')zUnable to interpret "zu" as a slice; expected "start:stop" or "start:stop:step" with integer or empty fields (e.g. "0:3", ":10", "0:100:5").)r>   msg)splitlenslicera   r   )r1   partss     rB   _slicer      sq     GGCLECJ!	Q5QRR #A3  '\  ]   		s   A 	AAtype_tokenr)   name_transformc                     ddl m} t        ||      }|r|j                  n|} ||      }| j                  j                         D ]  \  }} ||      |k(  s|c S  t        |r||       d|       )zqMatch a token's value to an enum's member.

    Applies ``name_transform`` to both the value and the member.
    r   r(   Nr   r>   )cyclopts.argumentr)   
isinstancers   __members__itemsr   )	r   r   r   r)   is_tokenrs   value_transformednamemembers	            rB   get_enum_memberr      s     (%'H#EKKE&u-))//1f$#44M 2 e %) rD   	enum_typetokensc                 \     t        t        j                   fd|D          d            S )a  Convert tokens to a Flag enum value.

    Parameters
    ----------
    enum_type : type[F]
        The Flag enum type to convert to.
    tokens : Iterable[str] | Iterable[Token]
        The tokens to convert. Can be member names or :class:`Token` objects.
    name_transform : Callable[[str], str] | None
        Function to transform names for comparison.

    Returns
    -------
    F
        The combined flag value.

    Raises
    ------
    CoercionError
        If a token is not a valid flag member.
    c              3   8   K   | ]  }t        |        y wrX   )r   )ry   r   r   r   s     rB   r{   z$convert_enum_flag.<locals>.<genexpr>   s     OuE>	:s   r   )r   operatoror_)r   r   r   s   ` `rB   convert_enum_flagr      s(    4 OO! rD   _converters	converterc          
      N   t        t        ||      t        d t        |       D              }t	        |       \  }t        d      |rt        |      z  }|rt        d dt        |       d      t        |      dk(  r|d   n t        |      dk(  rt        nt        d	      t        fd
t        |      D              S t        |      k7  rt        d dt        |       d      |D cg c]  }t	        |      d    }}t        |      }	|D 
cg c]$  }
t        |
      D cg c]  }t        |	       c}& }}
}|D cg c]  }t        |      dk(  r|d   n| }}t        fdt        ||d      D              }|S c c}w c c}w c c}}
w c c}w )Nr   r   c              3   *   K   | ]  }|d us|  yw).N ry   xs     rB   r{   z!_convert_tuple.<locals>.<genexpr>  s     C?aasl?s   	r`   z4Incorrect number of arguments: expected multiple of z	 but got rL   )r|   r   z%A tuple must have 0 or 1 inner-types.c              3   D   K   | ]  } d k(  r|d   n|        yw)r`   r   Nr   )ry   chunkconvertinner_token_count
inner_types     rB   r{   z!_convert_tuple.<locals>.<genexpr>&  s.      
; J,=,BaN;s    z(Incorrect number of arguments: expected c              3   6   K   | ]  \  }} ||        y wrX   r   )ry   r   argr   s      rB   r{   z!_convert_tuple.<locals>.<genexpr>4  s     lDkSGJ,Dk   F)strict)r   _converttupler   token_countmaxr~   r   strra   r%   iterrangenextzip)r   r   r   r   inner_typesconsume_all	remainderr   args_per_convertitsizerr   batchedelemoutr   r   r   s                  @@@rB   _convert_tupler     s    h)NSGC8E?CCK%0%7"{-q1K"33	JK\J]]fgjkqgrfsstu  {q $QJ"JDEE 
 ):;
 
 	
 F+>?P>QQZ[^_e[fZgghi  8CC{!KN1-{C&\?OP?OteDk2kDHk2?OPCJK74c$i1n47$67KlCU\ejDkllJ D2PKs$   ;F"F4FFF"FdatazToken | Nonec                    t        |      }t               }|j                         D ]1  \  }}|j                  |       |j	                  |j
                         3 t        | j                               |z
  }|rWt        |      d   }dj                  t        |j                                     }	t        d| d|j                   d|	 ||      y)a  Validate that JSON data doesn't contain extra keys not in the type's fields.

    Parameters
    ----------
    data : dict
        The JSON dictionary to validate.
    type_ : type
        The target type (dataclass, etc.) to validate against.
    token : Token | None
        Optional token for error context.

    Raises
    ------
    CoercionError
        If the data contains keys not present in the type's fields.
    r   z, zUnknown field "z" in JSON for z. Valid fields: )r|   r>   r   N)r"   setr   addupdatenameskeyssortedjoinr   __name__)
r   r   r   field_infosvalid_names
field_name
field_info
extra_keys	extra_keyvalid_fieldss
             rB   _validate_json_extra_keysr   8  s    * "%(KEK"-"3"3"5
J
#:++, #6 TYY[!K/J:&q)	yy(8(8(:!;<!)N5>>:JJZ[gZhi
 	
 rD   r   c                 t   ddl m} t        ||        i }|j                         D ]  \  }}||v s||   }	|	rt	        |j
                  t              sX |t        |	t        t        z        rt        j                  |	      n
t        |	            }
t        |j
                  |
g||      }n|	}|||<     | di |S )a  Convert JSON dict to dataclass with proper type conversion for fields.

    Parameters
    ----------
    type_ : Type
        The dataclass type to create.
    data : dict
        The JSON dictionary containing field values.
    field_infos : dict
        Field information from the dataclass.
    converter : Callable | None
        Optional converter function.
    name_transform : Callable[[str], str]
        Function to transform field names.

    Returns
    -------
    Instance of type_ with properly converted field values.
    r   r(   rs   r   )cyclopts.tokenr)   r   r   r'   hintr   r   dictlistjsondumpsr   )r   r   r   r   r   r)   converted_datar   r   rs   r   converted_values               rB   _convert_jsonr   ^  s    4 % dE*N"-"3"3"5
J$E )>zPS)TE4RV;9WDJJu$5]`af]gh")*//E7I~"^"')8N:& #6 ">""rD   errorc           	      D   | j                   j                         }t        |d      r|j                  nt        |d      r|j                  dz
  nd}t        d|dz
        }t        t        |      |dz         }||| }|dkD  rd|z   }|t        |      k  r|dz   }||z
  }|dkD  r|dz  }d}	t        j                  d	|      rd
}	n8t        j                  d|      rd}	nt        j                  d|      rd}	nd|v rd}	d|j                   d| dd|z   d|j                   |	 	S )a  Create a helpful error message for JSON decode errors.

    Parameters
    ----------
    token : Token
        The token containing the invalid JSON.
    type_ : Type
        The target type we were trying to convert to.
    error : json.JSONDecodeError
        The JSON decode error that occurred.

    Returns
    -------
    str
        A formatted error message with context and hints.
    poscolnor`   r      z...r    z\bTrue\bz8
    Hint: Use lowercase 'true' instead of Python's Truez	\bFalse\bz:
    Hint: Use lowercase 'false' instead of Python's Falsez\bNone\bz.
    Hint: Use 'null' instead of Python's None'z9
    Hint: JSON requires double quotes, not single quoteszInvalid JSON for z:
    z
    r_   z^ )rs   rb   hasattrr   r   r   minr~   rn   searchr   r|   )
r   r   r   	value_str	error_possnippet_startsnippet_endsnippet
marker_posr   s
             rB   !_create_json_decode_error_messager     s?   * !!#I %UE2		7SXZaKbahiI 9r>*Mc)ni"n5Kk2G q'/S^#E/ ]*Jqa
 D	yyi(J	<	+L	;		*@			Ku~~.ggYfS:EUDVVXY^YbYbXcdhcijjrD   c                 r   t        |       }|s | di |S g }i }|j                         D ]N  \  }}|j                  |      }|r1|j                  t        j
                  k(  r|j                  ||f       J|||<   P t        |j                               |j                  fd        | d |D        i |S )a%  Instantiate a type with proper handling of parameter kinds.

    Respects POSITIONAL_ONLY, KEYWORD_ONLY, and POSITIONAL_OR_KEYWORD parameter kinds
    when constructing the object.

    This function is necessary because `inspect.signature().bind(**data)` has the same
    limitation we're solving: it cannot accept positional-only parameters as keyword
    arguments. For example, `def __init__(self, a, /, b)` requires `a` to be passed
    positionally, but when we have a dict `{"a": 1, "b": 2}`, we need to transform
    this into the call `type_(1, b=2)`.

    Parameters
    ----------
    type_ : type[T]
        The type to instantiate.
    data : dict[str, Any]
        Dictionary mapping field names to values.

    Returns
    -------
    T
        Instance of type_ constructed from data.
    c                 ,    j                  | d         S )Nr   )index)r   field_names_orders    rB   <lambda>z'instantiate_from_dict.<locals>.<lambda>  s     1 7 7! =rD   )keyc              3   &   K   | ]	  \  }}|  y wrX   r   )ry   rr   vs      rB   r{   z(instantiate_from_dict.<locals>.<genexpr>  s     *A1s   r   )
r"   r   getkindr!   POSITIONAL_ONLYappendr   r   sort)	r   r   r   pos_argskwargsr   rs   r   r   s	           @rB   instantiate_from_dictr     s    0 "%(K}t}HF!ZZ\
E __Z0
*//Y-F-FFOOZ/0!&F: * [--/0MM=M>**5f55rD   r!   r   c                    d}i }| }|j                         D ]  \  }}|j                  }t        |t              r||   j                  }	|dz  }d}
n;t        |      \  }}|dk(  r ||||         }	|dz  }n ||||||z          }	||z  }|}
|	||<   |
r n|t        |      k(  s n |t        |      k(  sJ t        | |      S )a  Convert tokens to a structured type with proper positional/keyword argument handling.

    Respects the parameter kind of each field:
    - POSITIONAL_ONLY: passed as positional argument
    - KEYWORD_ONLY or POSITIONAL_OR_KEYWORD: passed as keyword argument

    This correctly handles types with keyword-only fields (e.g., dataclasses with kw_only=True).

    Parameters
    ----------
    type_ : type[T]
        The target structured type to instantiate.
    token : Sequence[Token]
        The tokens to convert.
    field_infos : dict[str, FieldInfo]
        Field information for the structured type.
    convert : Callable
        Conversion function for nested types.

    Returns
    -------
    T
        Instance of type_ constructed from the tokens.
    r   r`   F)r   r   r'   r   rs   r   r~   r   )r   r   r   r   ir   r   r   r   rs   should_breaktokens_per_elementr   s                rB   _convert_structured_typer     s    < 	
ADD"-"3"3"5
J !s+!HNNEFA L.9$.?+!Q&eAh/QeA4F0F&GH''&L Z E
?1 #64 E
?? --rD   c                   ddl m ddlm} d}t	        |       rHddlm} |j                  |       \  } j                  r	d}fd}|}j                  rj                  }ndt        t        ||      t        t        ||      }t        |       }|t        v r	t        |   }t        |       | t        u r t        t        t        f   |      }	n| t         v r t         |    |      }	n| t        v r*t        |    }
t         j#                  |
|
      } ||      }	nMt$        %t'        | t$              r | j(                  |      }	n"t+        |      rBD ]  }t-        |      r	  ||      }	 n t'        |t0              rt2        t5        || 	      |t6        u rbd}t        |       D ]  }	  t9        |      |      }||k(  s|}	 n |r	| |_        |t5        t'        |t0              r|d   | 	      || 	      |t<        u r't'        |      r || ||
      }	nJ || g|d|i}	n<|t>        v rtA        d         \  }}t'        |t0              st2        d   }|dkD  rtC        fd|D              r|t        ur|}n |dkD  rtE        tG        |      g|z  ddi}n|} |fd|D              }	ntI        | tJ              r"tM        | t'        |t0              r|n|g|      }	n~tI        | tN              r<t'        |t0              rt2        |tQ        | ||      }	nG || |jR                        }	n2tU        |       }tW        |       s|svt'        |      sJ 	 |jX                  tZ        ur|jX                  }	nG|&t]        j#                  | |       |jR                        }	n|r
 || |      }	n || |jR                        }	nt'        |      rw|jR                  ja                         jc                  d      rN| t        urF	 te        jf                  |jR                        }t'        |t              sth        tk        | ||||      }	n!t'        |t0              s|g}tq        | ||      }	rX	 jr                  D ]E  }t'        |t              rtu        | |      }tw        jx                  |      r	 ||	       = || |	       G 	 |	S |	S # t.        $ r Y }w xY w# t4        $ r}|}Y d}~=d}~ww xY w# t4        $ r,}|j:                  | |_        |j^                  ||_/         d}~wt2        $ r t5        || 	      dw xY w# td        jl                  $ r!}to        || |      }t5        |||       |d}~wth        $ r% t'        |t0              s|g}tq        | ||      }	Y 2w xY w# tz        t2        th        f$ r.}t}        |j~                  r|j~                  d   nd|	      |d}~ww xY w)zInner recursive conversion function for public ``convert``.

    Parameters
    ----------
    converter: Callable
    name_transform: Callable
    r   r(   )	ParameterFTc                     j                   sJ j                   }t        |t              rt        | |      }t	        j
                  |      r	 ||f      S  || |f      S rX   )r   r   r   getattrinspectismethod)t_rs   resolved_convertercparams      rB   converter_with_tokenz&_convert.<locals>.converter_with_tokenM  sh    '''' &,%5%5"0#6)05G)H& ##$67-uh77 .b5(;;rD   Nr   r   )r   r   r`   c              3      K   | ];  }t        |      xr) |j                  j                         j                  d        = yw){N)r   rs   rb   rM   )ry   r:   r)   s     rB   r{   z_convert.<locals>.<genexpr>  s9     \V[QRJq%(LQWW]]_-G-G-LLV[s   AAr   c              3   6   K   | ]  } d    |        yw)r   Nr   )ry   er   r   s     rB   r{   z_convert.<locals>.<genexpr>  s     Bc'+a.!4cr   r	  )r|   r   r>   r   )exception_messagers   )@r   r)   cyclopts.parameterr   r   from_annotationr   r   r   r   r   r   r/   r   r   r   r.   r   r   r   	__value__r   r   	Exceptionr   ra   r   r   typer>   r   r   r   anyr   r   r'   r
   r   r	   r   rs   r"   r&   implicit_valuer#   r   r   rb   rM   r   loads	TypeErrorr   JSONDecodeErrorr   r   	validatorr  r  r  AssertionErrorr    args)r   r   r   r   r   converter_needs_tokenr  convert_tupleorigin_typer   concrete_typedefault_paramr:   last_coercion_errorchoiceresr  countrr   r   genr   r   r|   r  r)   r   r  r   s                            @@@@rB   r   r   4  s    (,!E0!11%8v$(!<" -I  #22Nh)NSGNiP^_MU#K 888E5/K}d38ne,	1	15e<eD	4	4 ;5A7;;M=YmU+		"z%'Geoou-	+	A1~a'  %*  e??		"uoFd6lE2 f} & #27#/))#j6Q%(joppW\jopp		eU#u	BCCCCC		& {1~.q%* !^
AI\V[\\#% CQYU}u,;U;CCBcBB	ud	+
5(0KuRWQXZhi	ud	+eX&!%?CE5;;/C%e, eKeU+++N''u4..C&%//%7DC*#E51C#E5;;7C %'EKK,=,=,?,J,J3,OTYadTdW::ekk2D%dD1''t[)^\C "%2"GE.ue['R
		c#--	i- 'y 9I##I.cNeS) . J3JA   ! &'#D ! ==($)AM77?#AG N#%UCMN ++ X;E5!LC'Cu%PVWW  W%eX6!&25%gVC	W0 
I6 	c!AFF1IRWZ[abb	cs{   +	S4S%A&S5 
AU 3AV& 	SS	S2%S--S25	U >'T%%U V#U22-V#"V#&W(:)W##W(c                    ddl m |st        t        |t              s't        |d   t
              rt        fd|D              }|t        }t        t        ||      }t        t        ||      }t        |       } | t        u rt
        } t        j                  | |       } | t        v rt        |    }t        j                  ||      } t!        |       }|t        v r	t        |   }|xs | }|t        u r	 || g| S |t"        v r	 || |      S |t        u rpt        |t              st        	 t%        |       d   }	|j)                         D 
ci c]  \  }
}|
t+        |	|||       }}
}t-        j                  ||      d	i |S t        |t              rt        d| d      t/        |      rt1        |||      S t3        |       \  }}|r	 || |      S t5        |      dk(  r || |d         S |dk(  r|D cg c]  } || |       c}S t5        |      |k(  r	 || |      S t7        d      # t&        $ r
 t
        }	Y w xY wc c}}
w c c}w )
a  Coerce variables into a specified type.

    Internally used to coercing string CLI tokens into python builtin types.
    Externally, may be useful in a custom converter.
    See Cyclopt's automatic coercion rules :doc:`/rules`.

    If ``type_`` **is not** iterable, then each element of ``tokens`` will be converted independently.
    If there is more than one element, then the return type will be a ``Tuple[type_, ...]``.
    If there is a single element, then the return type will be ``type_``.

    If ``type_`` **is** iterable, then all elements of ``tokens`` will be collated.

    Parameters
    ----------
    type_: Type
        A type hint/annotation to coerce ``*args`` into.
    tokens: Union[Sequence[str], NestedCliArgs]
        String tokens to coerce.
        Generally, either a list of strings, or a dictionary of list of strings (recursive).
        Each leaf in the dictionary tree should be a list of strings.
    converter: Optional[Callable[[Type, str], Any]]
        An optional function to convert tokens to the inner-most types.
        The converter should have signature:

        .. code-block:: python

            def converter(type_: type, value: str) -> Any:
                "Perform conversion of string token."

        This allows to use the :func:`convert` function to handle the the difficult task
        of traversing lists/tuples/unions/etc, while leaving the final conversion logic to
        the caller.
    name_transform: Optional[Callable[[str], str]]
        Currently only used for ``Enum`` type hints.
        A function that transforms enum names and CLI values into a normalized format.

        The function should have signature:

        .. code-block:: python

            def name_transform(s: str) -> str:
                "Perform name transform."

        where the returned value is the name to be used on the CLI.

        If ``None``, defaults to ``cyclopts.default_name_transform``.

    Returns
    -------
    Any
        Coerced version of input ``*args``.
    r   r(   c              3   B   K   | ]  } t        |               yw)r   N)r   )ry   r   r)   s     rB   r{   zconvert.<locals>.<genexpr>F  s     ;Fqu3q6**Fs   r   r`   z*Dictionary of tokens provided for unknown rL   zUnreachable?r   )r   r)   ra   r   r   r   r   r$   r   r   r   r   r   r.   r   r/   r   r   r   
IndexErrorr   r   r   r   r   r   r~   NotImplementedError)r   r   r   r   convert_privr  r  r  maybe_origin_type
value_typekr   dict_convertedr   r   itemr)   s                   @rB   r   r     sm   t (fd#
6!9c(B;F;;/8yXLNiP^_MENE|+//u=E 22:5A/33M=QU#K888E#,ueU,V,,	n	,E6**	d	"&$'	!%+J gmfrfrft
ft^b^_abAwz1	.YYft 	 
 02CDV~VV	FD	!EeYaPQQ	'	( !!2FNKK*5e*<'Kv..[Avay111$:@A&$L-&AA[..v..%n55/  	J	
" Bs   ,H- I8I	-I ?I skip_converter_paramsc                    t        t        |             yddlm}  || |      \  }}|D ]F  }|j                  |j                  dk(  r y|| urt        |d      \  }}nd	}|j                  |fc S  |} t        |       }|t        v r	t        |   }| t        v r*t        |    }	t        j                  |	|	      } t        |       }|xs | t        u r$t        |       }
|
rt        d
 |
D              d|
v fS y|xs | t        u ry| t        v s|t        v rt        t        |             dk(  ryt!        |       ry|t        v r0t        t        |             rt        t        |       d         d   dfS t"        %t%        | t"              rt        | j&                        S t)        |       rIt        |       }t        |d         }|dd D ]&  }t        |      }||k7  st+        d|d    d|        |S t-        |       ryt/        |       }d\  }}|j1                         D ]L  }|j2                  |j4                  u rd}n|j6                  s+t        |j8                        \  }}||z  }||z  }N |sy||fS )a  The number of tokens after a keyword the parameter should consume.

    Parameters
    ----------
    type_: Type
        A type hint/annotation to infer token_count from if not explicitly specified.
    skip_converter_params: bool
        If True, don't extract converter parameters from __cyclopts__.
        Used to prevent infinite recursion when determining consume_all behavior.

    Returns
    -------
    int
        Number of tokens to consume.
    bool
        If this is ``True`` and positional, consume all remaining tokens.
        The returned number of tokens constitutes a single element of the iterable-to-be-parsed.
    N)r`   Fr   )get_parameters)r.  )r`   TTFc              3   B   K   | ]  }|d ust        |      d     yw).r   N)r   r   s     rB   r{   ztoken_count.<locals>.<genexpr>  s      G$Q!3,{1~a($s   	.)r   Fr`   z=Cannot Union types that consume different numbers of tokens: r_   )r   r   r  r0  n_tokensr   r   r/   r.   r   r   r   sumr@   r   r~   r   r   r   r  r   ra   r&   r"   valuesr   VAR_POSITIONALrequiredr   )r   r.  r0  resolved_type
parametersparamrr   consume_all_from_typer  r  r  sub_argstoken_count_target	sub_type_thisr   r"  r   rs   
elem_countelem_consume_alls                        rB   r   r     s   , ##3E#:;G 2 .uLa bM:>>%~~#
 !- 0;=`d/e,A, -2)~~'<<<! $ EU#K888E 22:5A/33M=Q 'u&G$GGPTTT

4	'	.	 [N%Bs8TY?G[_`G`	e			&3x+?8E?1-.q1477		"z%'G5??++	%E?(!5!!"Iy)D)) ST\]^T_S``abkalm  & "!	E	 &e,%{ '')EzzU111"^^+6uzz+B(J(ZE++K * k!!rD   rX   )NN)F)bcollections.abccollectionsr  r   r   rn   systypingr   r   r   r   r   r   enumr	   r
   	functoolsr   r   r   r   r   r   r   r   r   version_infor   cyclopts.annotationsr   r   r   r   r   r   r   r   cyclopts.exceptionsr   r    cyclopts.field_infor!   r"   cyclopts.utilsr#   r$   r%   r&   r'   r   r)   r*   r+   r-   	frozensetr   r   r   r   r   r.   r  __annotations__abcSet
MutableSetMutableSequenceMappingMutableMappingr/   r0   r@   rC   rN   rQ   rU   rV   rY   rZ   r]   rd   ru   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   rD   rB   <module>rU     sK       	 
  8 8 . .  %   w$M	 	 	 ? : d dw$M' CLCtCt
 y~$s)S	5c?$sCx.5 dDj!1  d
OOTdOOOOOO##TOOTOO""D	8 "Dt$4 	 S% >??@.S .T .C C "%c %e % #  )  !S !T !F F F "&# "&) "&Jc e *7# cUCZ( 	.AwSMHW-- cUCZ( 	F 	%	6z%iz	6	$T#x-  	(9(( sS()D0( cUCZ(	(
 (\ !#

#
#
 #
 
	#
L.#.#
.# .# $	.#
 cUCZ(.#b5k5k5k 5k 		5kp*6a *6S#X *61 *6Z=.7=.G=. c;&'=. 	=.
 =.@O(7++,O c
C(4/	O
 cUCZ(Oj 4826	z6z6SMHW--=z6 sS()D0z6 cUCZ(4/	z6zj"s j"4 j"E#t)DT j"rD   