
    KiK                        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# 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/ ej6                  dk\  rd dlmZ ndZerd dl0m1Z1  ed      Z2 ede      Z3 ede      Z4e5e5e6   e7e7e6   e8e8e6   e9e9e6df   e:e:e6e6f   iZ;e:e<e<f   e=d<   e	e7ej                  e7e
e7ej|                  j~                  e8ej|                  j                  e8ej|                  j                  e7ej|                  j                  e:ej|                  j                  e:iZDe:e<e<f   e=d<   e:e6ee
e6   df   f   ZEde6deFfdZGde6deHfdZIde6deJfdZKde6deLfdZMde6defdZNde6defdZOde6defdZPde<e3   d ed!e6f   d"ee6ge6f   de3fd#ZQd$e<e4   d%e	e6   e	d!   z  d"ee6ge6f   de4fd&ZReFeGeHeIeJeKeLeMeeNeeOeePiZSe:eef   e=d'<   de<e   d%d!d(ee<e6gef   dz  d"ee6ge6f   de9f
d)ZT	 d9d*e:de<d d+ddfd,ZUded*e:d-e:d(edz  d"ee6ge6f   f
d.ZVd d!ded/ej                  de6fd0ZXde<e2   d*e:e6ef   de2fd1ZYde<e2   d e
d!   d-e:e6d2f   d3ede2f
d4ZZd ed!e
d!   f   d(eee6gef   dz  d"ee6ge6f   fd5Z[	 	 d:ded%e
e6   e
d!   z  eEz  d(ee<e6gef   dz  d"ee6ge6f   dz  fd6Z\d;ded7eFde9eHeFf   fd8Z]y)<    N)CallableIterableSequence)datedatetime	timedelta)EnumFlag)partialreduce)TYPE_CHECKINGAnyLiteralTypeVarUnionget_args
get_origin)      )TypeAliasType)ITERABLE_TYPESis_annotatedis_enum_flagis_nonetypeis_unionresolve)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r/   s    ]/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/cyclopts/_convert.py_boolrA   G   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floatr?   s    r@   _intrO   R   sz    		A||D1bz	
d	1ay	
d	1ay	 5q?##1vrB   c                     t        | d      S )Nutf8)encoding)bytesr?   s    r@   _bytesrT   c   s    V$$rB   c                 *    t        t        |             S N)	bytearrayrT   r?   s    r@   
_bytearrayrX   g   s    VAYrB   c                 ,    t        j                  |       S )zDParse a date string.

    Returns
    -------
    datetime.date
    )r   fromisoformatr?   s    r@   _dater[   k   s     a  rB   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   rZ   
ValueErrorstripreplacer?   s    r@   	_datetimerb   u   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   r/   m<   hi  diQ wi:	 Mi ' r9   i3)seconds)rK   refindallr_   rN   r   )r/   negativematchesrk   _valueunits          r@   
_timedeltars      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%%rB   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ru   r<   )cyclopts.argumentr'   
isinstancerq   __members__itemsr   )	rt   ru   rv   r'   is_tokenrq   value_transformednamemembers	            r@   get_enum_memberr      s     (%'H#EKKE&u-))//1 f$#44M e %) rB   	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rV   )r   ).0ru   r   rv   s     r@   	<genexpr>z$convert_enum_flag.<locals>.<genexpr>   s     OuE>	:Os   r   )r   operatoror_)r   r   rv   s   ` `r@   convert_enum_flagr      s(    4 OO! rB   _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   rv   c              3   *   K   | ]  }|d us|  yw).N r   xs     r@   r   z!_convert_tuple.<locals>.<genexpr>   s     CaaslCs   	r^   z4Incorrect number of arguments: expected multiple of z	 but got rJ   )msgr   z%A tuple must have 0 or 1 inner-types.c              3   D   K   | ]  } d k(  r|d   n|        yw)r^   r   Nr   )r   chunkconvertinner_token_count
inner_types     r@   r   z!_convert_tuple.<locals>.<genexpr>  s.      
 J,=,BaN
s    z(Incorrect number of arguments: expected c              3   6   K   | ]  \  }} ||        y wrV   r   )r   r   argr   s      r@   r   z!_convert_tuple.<locals>.<genexpr>  s     lSGJ,l   F)strict)r   _converttupler   token_countmaxlenr   strr_   r#   iterrangenextzip)rt   r   rv   r   inner_typesconsume_all	remainderr   args_per_convertitsizerp   batchedelemoutr   r   r   s                  @@@r@   _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C&\?OPteDk2DH2PPCJK4c$i1n47$6K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<   ru   N)r    setr|   addupdatenameskeyssortedjoinr   __name__)
r   rt   ru   field_infosvalid_names
field_name
field_info
extra_keys	extra_keyvalid_fieldss
             r@   _validate_json_extra_keysr     s    * "%(KEK"-"3"3"5 -
J
#:++,- TYY[!K/J:&q)	yy(8(8(:!;<!)N5>>:JJZ[gZhi
 	
 rB   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&   rq   r   )cyclopts.tokenr'   r   r|   r%   hintr   rz   dictlistjsondumpsr   )rt   r   r   r   rv   r'   converted_datar   r   rq   ru   converted_values               r@   _convert_jsonr   ?  s    4 % dE*N"-"3"3"5 9
J$E )>zPS)TE4RV;9WDJJu$5]`af]gh")*//E7I~"^"')8N:&9 ">""rB   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^ )rq   r`   hasattrr   r   r   minr   rl   searchr   r   )
ru   rt   r   	value_str	error_possnippet_startsnippet_endsnippet
marker_posr   s
             r@   !_create_json_decode_error_messager   p  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jrB   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    r@   <lambda>z'instantiate_from_dict.<locals>.<lambda>  s     1 7 7! = rB   )keyc              3   &   K   | ]	  \  }}|  y wrV   r   )r   rp   vs      r@   r   z(instantiate_from_dict.<locals>.<genexpr>  s     *A1*s   r   )
r    r|   getkindr   POSITIONAL_ONLYappendr   r   sort)	rt   r   r   pos_argskwargsr   rq   r   r   s	           @r@   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5rB   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   rq   r   r   r   )rt   ru   r   r   ir   r   r   r   rq   should_breaktokens_per_elementr   s                r@   _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4 E
?? --rB   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        | ||      }	r	 jr                  D ]  } || |	        	 |	S |	S # t.        $ r Y Cw 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 w xY w# tt        t2        th        f$ r.}tw        |jx                  r|jx                  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 rV   )r   rz   r   getattrinspectismethod)t_rq   resolved_convertercparams      r@   converter_with_tokenz&_convert.<locals>.converter_with_token.  sh    '''' &,%5%5"0#6)05G)H& ##$67-uh77 .b5(;;rB   Nr   rx   )r   r   r^   c              3      K   | ];  }t        |      xr) |j                  j                         j                  d        = yw){N)rz   rq   r`   rK   )r   r8   r'   s     r@   r   z_convert.<locals>.<genexpr>  s6     \QRJq%(LQWW]]_-G-G-LL\s   AAr   c              3   6   K   | ]  } d    |        yw)r   Nr   )r   er   r   s     r@   r   z_convert.<locals>.<genexpr>  s     B'+a.!4Br   r   )r   ru   r<   r   )exception_messagerq   )=ry   r'   cyclopts.parameterr   r   from_annotationr   rv   r   r   r   r   r-   r   r   r   r,   r   r   rz   	__value__r   r   	Exceptionr   r_   r   r   typer<   r   r   r   anyr   r   r%   r
   r   r	   r   rq   r    r$   implicit_valuer!   r   ru   r`   rK   r   loads	TypeErrorr   JSONDecodeErrorr   r   	validatorAssertionErrorr   args)rt   ru   r   rv   r   converter_needs_tokenr   convert_tupleorigin_typer   concrete_typedefault_paramr8   last_coercion_errorchoiceresr  countrp   r   genr   r   r   r  r'   r   r   r   s                            @@@@r@   r   r     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??		"uo 	qFd6lE2 f}	q #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#-- &	%%&
 J3Jw   ! &'#D ! ==($)AM77?#AG N#%UCMN ++ X;E5!LC'Cu%PVWW  W%eX6!&25%gVC	W& 
I6 	c!AFF1IRWZ[abb	csz   +	R4R"%A&R; 
AT	 3U+ 	RR"	R8+R33R8;	T'S++T	U(T88-U('U(+V-?)V((V-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   )r   r   r'   s     r@   r   zconvert.<locals>.<genexpr>"  s     ;qu3q6**;s   r   r^   z*Dictionary of tokens provided for unknown rJ   zUnreachable?r   )ry   r'   r_   rz   r   r   r   r"   r   r   r   r   r   r,   r   r-   r   r   r   
IndexErrorr|   r   r   r   r   r   r   NotImplementedError)rt   r   r   rv   convert_privr  r  r  maybe_origin_type
value_typekr   dict_convertedr   r   itemr'   s                   @r@   r   r     se   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
^b^_abAwz1	.YY
 
 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                    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\  }}|j-                         D ]L  }|j.                  |j0                  u rd}n|j2                  s+t        |j4                        \  }}||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.
    r   )get_parameters)r$  N)r^   TTFc              3   B   K   | ]  }|d ust        |      d     yw).r   N)r   r   s     r@   r   ztoken_count.<locals>.<genexpr>  s     GQ!3,{1~a(Gs   	.)r   Fr^   z=Cannot Union types that consume different numbers of tokens: r]   )r^   F)r  r&  n_tokensr   r   r-   r,   r   r   r   sumr>   r   r   r   r   rz   r  r   r_   r$   r    valuesr   VAR_POSITIONALrequiredr   )rt   r$  r&  resolved_type
parametersparamrp   consume_all_from_typer  r  r  sub_argstoken_count_target	sub_type_thisr   r  r   rq   
elem_countelem_consume_alls                        r@   r   r   _  s   * 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!!rB   rV   )NN)F)^collections.abccollectionsr   r   r   rl   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   cyclopts.exceptionsr   r   cyclopts.field_infor   r    cyclopts.utilsr!   r"   r#   r$   r%   ry   r'   r(   r)   r+   	frozensetr   r   r   r   r   r,   r  __annotations__abcSet
MutableSetMutableSequenceMappingMutableMappingr-   r.   r>   rA   rL   rO   rS   rT   rW   rX   r[   rb   rs   r   r   r   r   r   r   r  r   r   r   r   r   r   r   rB   r@   <module>rK     s(       	 
  8 8 . .  %   w$M k k > : 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7# cUCZ( 	.AwSMHW-- cUCZ( 	F 	%	6z%iz$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;&'=. 	=.
 =.@J(7++,J c
C(4/	J
 cUCZ(J` 4826	z6z6SMHW--=z6 sS()D0z6 cUCZ(4/	z6zd"s d"4 d"E#t)DT d"rB   