U
    ARd                     @   s   d dl Z d dlmZmZmZmZmZ d dlZd dlmZ d dl	m
Z
 e
eZededef dZededZed	d
dZeddddZeeeedddZeeeedddZeeeeedddZeeg ef edddZdS )    N)AnyCallableListTypeVarcast)config)
get_loggerTFunc.)boundTObjreturnc                   C   s   t tdS )z<True if we should print deprecation warnings to the browser.zclient.showErrorDetails)boolr   
get_option r   r   >/tmp/pip-unpacked-wheel-b9et7o5g/streamlit/deprecation_util.py+_should_show_deprecation_warning_in_browser   s    r   )messager   c                 C   s   t  rt|  t|  dS )z#Show a deprecation warning message.N)r   	streamlitwarning_LOGGER)r   r   r   r   show_deprecation_warning!   s    
r   )old_namenew_nameremoval_dater   c              	   C   s   d|  d| d|  d| d	S )NzPlease replace `st.z` with `st.z`.

`st.z` will be removed after .r   )r   r   r   r   r   r   make_deprecated_name_warning*   s    r   )funcr   r   r   c                    s2   t   fdd}|_ j|_tt|S )a6  Wrap an `st` function whose name has changed.

    Wrapped functions will run as normal, but will also show an st.warning
    saying that the old name will be removed after removal_date.

    (We generally set `removal_date` to 3 months from the deprecation date.)

    Parameters
    ----------
    func
        The `st.` function whose name has changed.

    old_name
        The function's deprecated name within __init__.py.

    removal_date
        A date like "2020-01-01", indicating the last day we'll guarantee
        support for the deprecated name.
    c                     s     | |}t t j |S N)r   r   __name__)argskwargsresultr   r   r   r   r   wrapped_funcH   s
    
z)deprecate_func_name.<locals>.wrapped_func)	functoolswrapsr   __doc__r   r	   )r   r   r   r$   r   r#   r   deprecate_func_name3   s
    r(   )objr   r   r   r   c                    s   t |  fddS )ar  Wrap an `st` object whose name has changed.

    Wrapped objects will behave as normal, but will also show an st.warning
    saying that the old name will be removed after `removal_date`.

    (We generally set `removal_date` to 3 months from the deprecation date.)

    Parameters
    ----------
    obj
        The `st.` object whose name has changed.

    old_name
        The object's deprecated name within __init__.py.

    new_name
        The object's new name within __init__.py.

    removal_date
        A date like "2020-01-01", indicating the last day we'll guarantee
        support for the deprecated name.
    c                      s   t t S r   )r   r   r   r   r   r   r   r   <lambda>r   s   
z$deprecate_obj_name.<locals>.<lambda>)_create_deprecated_obj_wrapper)r)   r   r   r   r   r*   r   deprecate_obj_nameV   s    r-   )r)   show_warningr   c                    s:   dddfddG  fddd t t  S )zCreate a wrapper for an object that has been deprecated. The first
    time one of the object's properties or functions is accessed, the
    given `show_warning` callback will be called.
    FNr   c                      s    sd   d S )NTr   r   )has_shown_warningr.   r   r   maybe_show_warning   s    z:_create_deprecated_obj_wrapper.<locals>.maybe_show_warningc                       sP   e Zd Z fddZfddZeee dddZefdd	Z	d
S )z/_create_deprecated_obj_wrapper.<locals>.Wrapperc                    s.     jD ]}t| j|t| | qd S r   )_get_magic_functions	__class__setattrproperty_make_magic_function_proxy)selfname)Wrapperr)   r   r   __init__   s    z8_create_deprecated_obj_wrapper.<locals>.Wrapper.__init__c                    s$   || j krt| |S    t|S r   )__dict__getattr)r6   attrr0   r)   r   r   __getattr__   s    

z;_create_deprecated_obj_wrapper.<locals>.Wrapper.__getattr__r   c                    s   d  fddt | D S )N)r2   r:   __getattribute__r>   c                    s"   g | ]}| kr| d r|qS )__)
startswith).0r7   ignorer   r   
<listcomp>   s    
zX_create_deprecated_obj_wrapper.<locals>.Wrapper._get_magic_functions.<locals>.<listcomp>)dir)clsr   rC   r   r1      s    
zD_create_deprecated_obj_wrapper.<locals>.Wrapper._get_magic_functionsc                    s    fdd}|S )Nc                    s      t S r   )r;   )r6   r    )r0   r7   r)   r   r   proxy   s    zY_create_deprecated_obj_wrapper.<locals>.Wrapper._make_magic_function_proxy.<locals>.proxyr   )r7   rH   r=   )r7   r   r5      s    zJ_create_deprecated_obj_wrapper.<locals>.Wrapper._make_magic_function_proxyN)
r   
__module____qualname__r9   r>   staticmethodr   strr1   r5   r   )r8   r0   r)   r   r   r8      s   	
r8   )r   r   )r)   r.   r   )r8   r/   r0   r)   r.   r   r,   x   s    (r,   )r%   typingr   r   r   r   r   r   r   Zstreamlit.loggerr   r   r   r	   objectr   r   r   rL   r   r   r(   r-   r,   r   r   r   r   <module>   s,   
  	$   "