
    &e                     n   d dl Z d dlmZmZ d dlmZ d dlmZmZm	Z	 d dl
mZmZ dZdedefd	Zd
edefdZ G d de          Z G d de          Z G d de          Z G d de          Z G d de	          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )    N)AnyOptional)	type_util)MarkdownFormattedExceptionStreamlitAPIExceptionStreamlitAPIWarning)	CacheTypeget_decorator_api_namez;https://docs.streamlit.io/library/advanced-features/cachingfuncreturnc                     t          | d          r
d| j        z  S t          t          |           d          rdt          |           j         dS dt          |            dS )1Get markdown representation of the function name.__name__`%s()``)hasattrr   typer   s    Flib/python3.11/site-packages/streamlit/runtime/caching/cache_errors.pyget_cached_func_name_mdr      sj    tZ   *$-''	dZ	(	( *)4::&))))tDzz    return_valuec                     t          | d          r=t          t          |           d          r d| j         dt          |           j         dS t	          |           S )N
__module__r   r   .)r   r   r   r   r   )r   s    r   get_return_value_typer   &   sd    |\** LwtL7I7I:/V/V LK<*KKT,-?-?-HKKKK"<000r   c                       e Zd ZdS )UnhashableTypeErrorNr   r   __qualname__ r   r   r   r   ,           Dr   r   c                        e Zd Zdedej        dee         dede	f
 fdZ
ededej        dee         dedef
d            Z xZS )	UnhashableParamError
cache_typer   arg_name	arg_valueorig_excc                     |                      ||||          }t                                          |           |                     |j                   d S )N)_create_messagesuper__init__with_traceback__traceback__)selfr%   r   r&   r'   r(   msg	__class__s          r   r,   zUnhashableParamError.__init__1   sS     "":tXyIIH233333r   r   c                     ||nd}t          j        |          }|j        }|d| nd}d| d| d| dt          |            d| d	| d
                    d          S )Nz	(unnamed)__argz
Cannot hash argument 'z' (of type `z`) in 'z'.

To address this, you can tell Streamlit not to hash this argument by adding a
leading underscore to the argument's name in the function signature:

```
@st.z
def (z , ...):
    ...
```
            
)r   get_fqn_typer   r
   strip)r%   r   r&   r'   arg_name_strarg_type	func_namearg_replacement_names           r   r*   z$UnhashableParamError._create_message=   s     $,#7xx[))44M	191E~8~~~6# 19 BK  J''    &   %++	r   )r   r   r    r	   typesFunctionTyper   strr   BaseExceptionr,   staticmethodr*   __classcell__r1   s   @r   r$   r$   0   s        
4
4  
4 3-	
4
 
4  
4 
4 
4 
4 
4 
4   3- 	
 
   \    r   r$   c                       e Zd ZdS )CacheKeyNotFoundErrorNr   r!   r   r   rE   rE   Y   r"   r   rE   c                       e Zd ZdS )
CacheErrorNr   r!   r   r   rG   rG   ]   r"   r   rG   c                   `     e Zd Zdededej        f fdZedej        defd            Z	 xZ
S )CachedStFunctionWarningr%   st_func_namecached_funcc                     d| d|                      |          t          |          d}d|z                      d          }t                                          |           d S )Nz`st.z()`)rJ   r;   decorator_namea  
Your script uses %(st_func_name)s to write to your Streamlit app from within
some cached code at %(func_name)s. This code will only be called when we detect
a cache "miss", which can lead to unexpected results.

How to fix this:
* Move the %(st_func_name)s call outside %(func_name)s.
* Or, if you know what you're doing, use `@st.%(decorator_name)s(experimental_allow_widgets=True)`
to enable widget replay and suppress this warning.
            r6   )_get_cached_func_name_mdr
   r8   r+   r,   )r/   r%   rJ   rK   argsr0   r1   s         r   r,   z CachedStFunctionWarning.__init__b   s|     5<44466{CC4Z@@
 
	 
 %++ 	 	r   r   r   c                 :    t          | d          r
d| j        z  S dS )r   r   r   za cached function)r   r   r   s    r   rN   z0CachedStFunctionWarning._get_cached_func_name_md~   s)     4$$ 	'dm++&&r   )r   r   r    r	   r?   r=   r>   r,   rA   rN   rB   rC   s   @r   rI   rI   a   s          '	     8 'u'9 'c ' ' ' \' ' ' ' 'r   rI   c                   2     e Zd Zdedej        f fdZ xZS )CacheReplayClosureErrorr%   rK   c                     t          |          }t          |          }d| d| d| d| d| d                    d          }t                                          |           d S )Nz
While running a  , a streamlit element is called on some layout block created outside the function.
This is incompatible with replaying the cached effect of that element, because the
the referenced block might not exist when the replay happens.

How to fix this:
* Move the creation of $THING inside z6.
* Move the call to the streamlit element outside of z.
* Remove the `@st.z` decorator from z.
            r6   )r   r
   r8   r+   r,   )r/   r%   rK   r;   rM   r0   r1   s         r   r,   z CacheReplayClosureError.__init__   s    
 ,K88	/
;;		 	 '0	 	 6?	 	 "	 	 5>	 	 	 %++ 	 	r   )r   r   r    r	   r=   r>   r,   rB   rC   s   @r   rR   rR      sR         '         r   rR   c                   2    e Zd Zdej        dej        fdZdS )UnserializableReturnValueErrorr   r   c           
          t          j        | dt          |           dt          |           dt           d           d S )Nz8
            Cannot serialize the return value (of type z) in u  .
            `st.cache_data` uses [pickle](https://docs.python.org/3/library/pickle.html) to
            serialize the function’s return value and safely store it in the cache without mutating the original object. Please convert the return value to a pickle-serializable type.
            If you want to cache unserializable objects such as database connections or Tensorflow
            sessions, use `st.cache_resource` instead (see [our docs](z) for differences).)r   r,   r   r   CACHE_DOCS_URL)r/   r   r   s      r   r,   z'UnserializableReturnValueError.__init__   sr    "+m8Ml8[8[m mbyz~bbm m
 HVm m m	
 	
 	
 	
 	
r   N)r   r   r    r=   r>   r,   r!   r   r   rU   rU      s<        	
U/ 	
u?Q 	
 	
 	
 	
 	
 	
r   rU   c                       e Zd ZdZdS )UnevaluatedDataFrameErrorz@Used to display a message about uncollected dataframe being usedN)r   r   r    __doc__r!   r   r   rY   rY      s        JJDr   rY   c                       e Zd ZdZdefdZdS )BadTTLStringErrorz1Raised when a bad ttl= argument string is passed.ttlc                 6    t          j        | d|            d S )NzcTTL string doesn't look right. It should be formatted as`'1d2h34m'` or `2 days`, for example. Got: )r   r,   )r/   r]   s     r   r,   zBadTTLStringError.__init__   s9    "+@:=@ @	
 	
 	
 	
 	
r   N)r   r   r    rZ   r?   r,   r!   r   r   r\   r\      s5        ;;
C 
 
 
 
 
 
r   r\   )r=   typingr   r   	streamlitr   streamlit.errorsr   r   r   $streamlit.runtime.caching.cache_typer	   r
   rW   r?   r   r   	Exceptionr   r$   rE   rG   rI   rR   rU   rY   r\   r!   r   r   <module>rd      s\                                  
 S R R R R R R RN# #    1 1 1 1 1 1	 	 	 	 	) 	 	 	& & & & &0 & & &R	 	 	 	 	I 	 	 		 	 	 	 	 	 	 	#' #' #' #' #'1 #' #' #'L    3   2

 

 

 

 

%? 

 

 

	 	 	 	 	 5 	 	 	
 
 
 
 
- 
 
 
 
 
r   