o
    h$#                     @  sd  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rKd d	lmZmZ eeZd
ed< dZded< e	dZ dFddZ!dGddZ"dHd!d"Z#	#dIdJd'd(Z$e	d)ed*Z%e	d+ed*Z&d,Z'dKd1d2Z(dLd5d6Z)e
dMd;d<Z*e
dNd>d<Z*d?d< Z*e
dOdAdBZ+e
dPdDdBZ+dEdB Z+d#S )Q    )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_ValueiterableIterable[_Value]xreturnintc                 C  s`   t | D ]"\}}||kr|  S t|tr&t|tr&t|| tk r&|  S q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)r   r   ivalue r$   a/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/lib/options_selector_utils.pyindex_&   s   r&   optSequence[Any]default_valuesSequence[Any] | Any | Nonelist[int] | Nonec                   sH   |du rdS t |}|D ]}| vrtd| dq fdd|D S )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.c                   s   g | ]}  |qS r$   )index).0r#   r'   r$   r%   
<listcomp>O   s    z0check_and_convert_to_indices.<locals>.<listcomp>)r   r   )r'   r)   r#   r$   r.   r%   check_and_convert_to_indices?   s   
r0   optionsOptionSequence[T]Sequence[T]c                 C  s   t | }t| |S N)r   r   )r1   indexable_optionsr$   r$   r%   (convert_to_sequence_and_check_comparableR   s   r6   Nr5   default	list[int]c                 C  s"   t | |}|d ur|}|S g }|S r4   )r0   )r5   r7   default_indicesr$   r$   r%   get_default_indicesX   s
   
r:   E1)boundE2)offnameOnlynameAndValuefrom_enum_valueto_enum_classtype[E2]E1 | E2c                 C  s   t | tstdt|  t |tstdt| t | |r#| S td}|tvr7tdt d| d|dkr=| S | j	}|j
|j
ksb|dkrTt|jt|jksb|d	krkt|jt|jkrktd
| | | S t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'.r>   r?   r@   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_)rA   rB   coercion_typefrom_enum_classr$   r$   r%   _coerce_enumf   sB   




rQ   Iterable[Any]r   c                   sL   zt | }tt| W n
 ty   Y dS w t fdd|D r$ S dS )ziReturn the common class of all elements in a iterable if they share one.
    Otherwise, return None.
    Nc                 3  s    | ]	}t | u V  qd S r4   )rE   )r-   itemfirst_classr$   r%   	<genexpr>   s    z2_extract_common_class_from_iter.<locals>.<genexpr>)iterrE   nextStopIterationall)r   
inner_iterr$   rT   r%   _extract_common_class_from_iter   s   r\   register_widget_resultRegisterWidgetResult[Enum]
type[Enum]opt_sequencec                 C     d S r4   r$   r]   r1   r`   r$   r$   r%   maybe_coerce_enum      rc   RegisterWidgetResult[T]c                 C  ra   r4   r$   rb   r$   r$   r%   rc      rd   c                 C  sH   t | jts| S t |tr|}n
t|}|du r| 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.
    N)r   r#   r   r   r\   r   rQ   value_changed)r]   r1   r`   coerce_classr$   r$   r%   rc      s   

RegisterWidgetResult[list[T]]c                 C  ra   r4   r$   rb   r$   r$   r%   maybe_coerce_enum_sequence   rd   ri   !RegisterWidgetResult[tuple[T, T]]c                 C  ra   r4   r$   rb   r$   r$   r%   ri      rd   c                   sb   t dd | jD s| S t|tr| n
t|  du r| S tt| j fd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                 s  s    | ]}t |tV  qd S r4   )r   r   r-   valr$   r$   r%   rV      s    z-maybe_coerce_enum_sequence.<locals>.<genexpr>Nc                 3  s    | ]}t | V  qd S r4   )rQ   rk   rg   r$   r%   rV      s    

)rZ   r#   r   r   r\   r   rE   rf   rb   r$   rm   r%   ri      s   
)r   r   r   r   r   r   )r'   r(   r)   r*   r   r+   )r1   r2   r   r3   r4   )r5   r3   r7   r*   r   r8   )rA   r;   rB   rC   r   rD   )r   rR   r   r   )r]   r^   r1   r_   r`   r(   r   r^   )r]   re   r1   r2   r`   r3   r   re   )r]   rh   r1   r2   r`   r3   r   rh   )r]   rj   r1   r2   r`   r3   r   rj   ),
__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&   r0   r6   r:   r;   r=   rG   rQ   r\   rc   ri   r$   r$   r$   r%   <module>   sB   




6