U
    g                  	   @  sB  d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlZe	rtd dlmZ d dlmZ edZed	ZG d
d deZdddddZdddddZdddddddddddddZdddddddddd d!d"Zdd#ddd#d$d%d&Zejdd'G d(d) d)ZG d*d+ d+eZddd,d-d.ZdS )/    )annotationsN)wraps)
ModuleType)TYPE_CHECKINGClassVarTypeVar)Callable)	ParamSpecArgsTRetTc                   @  s   e Zd ZdZdS )TrioDeprecationWarninga  Warning emitted if you use deprecated Trio functionality.

    As a young project, Trio is currently quite aggressive about deprecating
    and/or removing functionality that we realize was a bad idea. If you use
    Trio, you should subscribe to `issue #1
    <https://github.com/python-trio/trio/issues/1>`__ to get information about
    upcoming deprecations and other backwards compatibility breaking changes.

    Despite the name, this class currently inherits from
    :class:`FutureWarning`, not :class:`DeprecationWarning`, because while
    we're in young-and-aggressive mode we want these warnings to be visible by
    default. You can hide them by installing a filter or with the ``-W``
    switch: see the :mod:`warnings` documentation for details.

    N)__name__
__module____qualname____doc__ r   r   3/tmp/pip-unpacked-wheel-ks04xdmi/trio/_deprecate.pyr      s   r   intstr)issuereturnc                 C  s
   d|  S )Nz+https://github.com/python-trio/trio/issues/r   )r   r   r   r   _url_for_issue,   s    r   object)thingr   c                 C  s.   t | dr&t | dr&| j d| j S t| S )Nr   r   .)hasattrr   r   r   )r   r   r   r   
_stringify0   s    r      F)
stackleveluse_triodeprecationwarning
int | NoneboolNone)r   versionr   insteadr   r   r   c                C  s   |d7 }t |  d| }|d kr,|d7 }n|dt | d7 }|d k	r\|dt| d7 }|rft}nt}tj|||d d S )	N   z is deprecated since Trio z with no replacementz; use z insteadz ())r   )r   r   r   DeprecationWarningwarningswarn)r   r#   r   r$   r   r   msgZwarning_classr   r   r   warn_deprecated6   s    	
r+   )r   r   z8Callable[[Callable[ArgsT, RetT]], Callable[ArgsT, RetT]])r#   r   r   r$   r   r   c                  s    ddd fdd}|S )NCallable[ArgsT, RetT])fnr   c                   s   t  dddd fdd}d kr4||jd k	r|j}| }|d7 }|d d	7 }d k	r|d
t d7 }d k	r|d dt d7 }|d	7 }||_|S )N
ArgsT.argsArgsT.kwargsr   argskwargsr   c                    s   t d  | |S )N)r$   r   r   )r+   r1   r2   )r-   r$   r   r   r   r#   r   r   wrapper[   s    z,deprecated.<locals>.do_wrap.<locals>.wrapperz

z.. deprecated:: 
z   Use z
 instead.
z   For details, see `issue #z <z>`__.
)r   r   rstripr   r   )r-   r4   docr$   r   r   r   r#   )r-   r   do_wrapX   s     "
zdeprecated.<locals>.do_wrapr   )r#   r   r   r$   r   r9   r   r8   r   
deprecatedP   s    "r:   r,   )old_qualnamenew_fnr#   r   r   c                  sJ   t || dt dddddd fdd	}| |_| d
d |_|S )Nr   r$   )r   __annotations__)assignedr.   r/   r   r0   c                    s
    | |S )zDeprecated alias.r   r3   r<   r   r   r4      s    z!deprecated_alias.<locals>.wrapperr   )r:   r   r   
rpartitionr   )r;   r<   r#   r   r4   r   r@   r   deprecated_alias}   s    
rC   )slotsc                   @  s@   e Zd ZU e Zded< ded< ded< ded< eZded	< d
S )DeprecatedAttributezClassVar[object]_not_setr   valuer   r#   r    r   r$   N)r   r   r   r   rF   r>   r$   r   r   r   r   rE      s
   
rE   c                   @  s&   e Zd ZU ded< dddddZdS )	_ModuleWithDeprecationszdict[str, DeprecatedAttribute]__deprecated_attributes__r   r   )namer   c                 C  sn   || j krT| j | }|j}|tjkr*|j}| j d| }t||j|j|d |jS d}t	|
| j|d S )Nr   r=   z!module '{}' has no attribute '{}')rI   r$   rE   rF   rG   r   r+   r#   r   AttributeErrorformat)selfrJ   infor$   r   r*   r   r   r   __getattr__   s    


z#_ModuleWithDeprecations.__getattr__N)r   r   r   r>   rO   r   r   r   r   rH      s   
rH   )module_namer   c                 C  s(   t j|  }t|_t|tsti |_d S )N)sysmodulesrH   	__class__
isinstanceAssertionErrorrI   )rP   moduler   r   r   enable_attribute_deprecations   s    
rW   )
__future__r   rQ   r(   	functoolsr   typesr   typingr   r   r   attrscollections.abcr   Ztyping_extensionsr	   r
   r   FutureWarningr   r   r   r+   r:   rC   frozenrE   rH   rW   r   r   r   r   <module>   s2   -
	