
    g#                       U d dl mZ d dlmZmZ d dl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 d dlmZ d dlmZmZ erd d	lmZmZ  ej6                  e      Zd
ed<   dZded<    e	d      Z d!dZ!	 	 	 	 	 	 d"dZ"d#dZ#	 d$	 	 	 	 	 d%dZ$ e	de      Z% e	de      Z&dZ'd&dZ(d'dZ)e
	 	 	 	 	 	 	 	 d(d       Z*e
	 	 	 	 	 	 	 	 d)d       Z*d Z*e
	 	 	 	 	 	 	 	 d*d       Z+e
	 	 	 	 	 	 	 	 d+d       Z+d  Z+y),    )annotations)EnumEnumMeta)TYPE_CHECKINGAnyFinalTypeVaroverload)configlogger)OptionSequenceconvert_anything_to_list)StreamlitAPIException)RegisterWidgetResult)Tcheck_python_comparable)IterableSequencer   _LOGGERgdy=zFinal[float]_FLOAT_EQUALITY_EPSILON_Valuec                    t        |       D ]I  \  }}||k(  r|c S t        |t              s t        |t              s1t        ||z
        t        k  sG|c S  t        t        |       d      )a  Return zero-based index of the first item whose value is equal to x.
    Raises a ValueError if there is no such item.

    We need a custom implementation instead of the built-in list .index() to
    be compatible with NumPy array and Pandas Series.

    Parameters
    ----------
    iterable : list, tuple, numpy.ndarray, pandas.Series
    x : Any

    Returns
    -------
    int
    z is not in iterable)	enumerate
isinstancefloatabsr   
ValueErrorstr)iterablexivalues       b/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/lib/options_selector_utils.pyindex_r$   &   se      h'5:Hu%*Q*>1u9~ 77 ( Ax23
44    c                    |yt        |      }|D ]  }|| vst        d| d       |D cg c]  }| j                  |       c}S c c}w )zIPerform validation checks and return indices based on the default values.NzThe default value 'zd' is not part of the options. Please make sure that every default values also exists in the options.)r   r   index)optdefault_valuesr"   s      r#   check_and_convert_to_indicesr*   ?   sl     -n=N'%eW -Y Y    +99.CIIe.999s   Ac                2    t        |       }t        |       |S N)r   r   )optionsindexable_optionss     r#   (convert_to_sequence_and_check_comparabler/   R   s    09-.r%   Nc                .    t        | |      }||}|S g }|S r,   )r*   )r.   defaultdefault_indicess      r#   get_default_indicesr3   X   s0     33DgNO)8)DoO KMOr%   E1)boundE2)offnameOnlynameAndValuec                   t        | t              st        dt        |              t        |t              st        dt        |             t        | |      r| S t        j                  d      }|t        vrt        dt         d| d      |dk(  r| S | j                  }|j                  |j                  k7  s`|dk(  r+t        |j                        t        |j                        k7  s0|d	k(  rDt        |j                        t        |j                        k7  rt        j                  d
| |       | S t        j                  d| |       || j                      S )a  Attempt to coerce an Enum value to another EnumMeta.

    An Enum value of EnumMeta E1 is considered coercable to EnumType E2
    if the EnumMeta __qualname__ match and the names of their members
    match as well. (This is configurable in streamlist configs)
    z,Expected an Enum in the first argument. Got z6Expected an EnumMeta/Type in the second argument. Got zrunner.enumCoercionzEInvalid value for config option runner.enumCoercion. Expected one of z, but got 'z'.r7   r8   r9   zFailed to coerce %s to class %szCoerced %s to class %s)r   r   r   typer   r   
get_option&_ALLOWED_ENUM_COERCION_CONFIG_SETTINGSr   	__class____qualname__set_member_names__value2member_map_r   debug_name_)from_enum_valueto_enum_classcoercion_typefrom_enum_classs       r#   _coerce_enumrI   f   si    ot,:4;P:QR
 	
 mX.DT-EXDYZ
 	
 /=1%%&;<MBB#EF G%b*
 	

 
 &//O$$(B(BBZ'M001S9W9W5XX ^+M445?5567 	7-X
 MM*O]K//00r%   c                    	 t        |       }t        t        |            t	        fd|D              rS y# t        $ r Y yw xY w)zdReturn the common class of all elements in a iterable if they share one.
    Otherwise, return None.Nc              3  8   K   | ]  }t        |      u   y wr,   )r;   ).0itemfirst_classs     r#   	<genexpr>z2_extract_common_class_from_iter.<locals>.<genexpr>   s     
<4:$s   )iterr;   nextStopIterationall)r   
inner_iterrN   s     @r#   _extract_common_class_from_iterrU      sM    (^
4
+, 
<
<<	  s   9 	AAc                     y r,    register_widget_resultr-   opt_sequences      r#   maybe_coerce_enumr[      s    
 "%r%   c                     y r,   rW   rX   s      r#   r[   r[      s    
 "r%   c                    t        | j                  t              s| S t        |t              r|}nt	        |      }|| S t        t        | j                  |      | j                        S )zMaybe Coerce a RegisterWidgetResult with an Enum member value to
    RegisterWidgetResult[option] if option is an EnumType, otherwise just return
    the original RegisterWidgetResult.)r   r"   r   r   rU   r   rI   value_changedrY   r-   rZ   coerce_classs       r#   r[   r[      si     ,22D9%% '8$6|D))+11<@,, r%   c                     y r,   rW   rX   s      r#   maybe_coerce_enum_sequencerb      s    
 %(r%   c                     y r,   rW   rX   s      r#   rb   rb      s    
 ),r%   c                   t        d | j                  D              s| S t        |t              r|nt	        |      | S t         t        | j                        fd| j                  D              | j                        S )zMaybe Coerce a RegisterWidgetResult with a sequence of Enum members as value
    to RegisterWidgetResult[Sequence[option]] if option is an EnumType, otherwise just return
    the original RegisterWidgetResult.c              3  <   K   | ]  }t        |t                y wr,   )r   r   )rL   vals     r#   rO   z-maybe_coerce_enum_sequence.<locals>.<genexpr>   s     M0Lz#t$0Ls   c              3  6   K   | ]  }t        |        y wr,   )rI   )rL   rf   r`   s     r#   rO   z-maybe_coerce_enum_sequence.<locals>.<genexpr>   s      +
7SLl+7Ss   )rS   r"   r   r   rU   r   r;   r^   r_   s      @r#   rb   rb      s     M0F0L0LMM%% '8$6|D))  *#))* +
7M7S7S+
 	
 	,,	 r%   )r   zIterable[_Value]r    r   returnint)r(   Sequence[Any]r)   Sequence[Any] | Any | Nonerh   zlist[int] | None)r-   OptionSequence[T]rh   Sequence[T]r,   )r.   rm   r1   rk   rh   z	list[int])rE   r4   rF   ztype[E2]rh   zE1 | E2)r   zIterable[Any]rh   r   )rY   RegisterWidgetResult[Enum]r-   z
type[Enum]rZ   rj   rh   rn   )rY   RegisterWidgetResult[T]r-   rl   rZ   rm   rh   ro   )rY   RegisterWidgetResult[list[T]]r-   rl   rZ   rm   rh   rp   )rY   !RegisterWidgetResult[tuple[T, T]]r-   rl   rZ   rm   rh   rq   ),
__future__r   enumr   r   typingr   r   r   r	   r
   	streamlitr   r   streamlit.dataframe_utilr   r   streamlit.errorsr   streamlit.runtime.state.commonr   streamlit.type_utilr   r   collections.abcr   r   
get_logger__name__r   __annotations__r   r   r$   r*   r/   r3   r4   r6   r=   rI   rU   r[   rb   rW   r%   r#   <module>r~      s   #  ? ? $ M 2 ?
 2"""8, ,(6  6		52:	:(B::& KO"-G TT)L &31l
 
%6%%  %  	% 
% 
"3"" " 	" 
"2 
(9(( ( #	( 
( 
,=,, , '	, 
,r%   