o
    Yeg                     @  s  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	 d dl
mZmZmZ d dlZer:d dlmZ edZed	ZG d
d deZd1ddZd2ddZddd3ddZddd4d!d"Zd5d&d'Zejd(d)G d*d+ d+ZG d,d- d-e	Zd6d/d0ZdS )7    )annotationsN)Callable)wraps)
ModuleType)TYPE_CHECKINGClassVarTypeVar)	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   3usr/lib/python3.10/site-packages/trio/_deprecate.pyr      s    r   issueintreturnstrc                 C  s
   d|  S )Nz+https://github.com/python-trio/trio/issues/r   )r   r   r   r   _url_for_issue+   s   
r   thingobjectc                 C  s.   t | drt | dr| j d| j S t| S )Nr   r   .)hasattrr   r   r   r   r   r   r   
_stringify/   s   r      
stacklevelversion
int | Noneinsteadr    Nonec                C  sr   |d7 }t |  d| }|d u r|d7 }n
|dt | d7 }|d ur.|dt| d7 }tjt||d d S )	N   z is deprecated since Trio z with no replacementz; use z insteadz ()r   )r   r   warningswarnr   )r   r!   r   r#   r    msgr   r   r   warn_deprecated5   s   
r*   r   8Callable[[Callable[ArgsT, RetT]], Callable[ArgsT, RetT]]c                  s   d fdd}|S )NfnCallable[ArgsT, RetT]r   c                   s   t  d fdd}d u r||jd urP|j}| }|d	7 }|d
 d7 }d ur;|dt d7 }d urI|dt7 }|d7 }||_|S )Nargs
ArgsT.argskwargsArgsT.kwargsr   r   c                    s   t d  | i |S )N)r#   r   )r*   r.   r0   )r,   r#   r   r   r!   r   r   wrapperP   s   z,deprecated.<locals>.do_wrap.<locals>.wrapperz

z.. deprecated:: 
z   Use z
 instead.
z(   For details, see `issue #{} <{}>`__.
r.   r/   r0   r1   r   r   )r   r   rstripr   formatr   )r,   r3   docr#   r   r   r!   )r,   r   do_wrapM   s$   
zdeprecated.<locals>.do_wrap)r,   r-   r   r-   r   )r!   r   r   r#   r:   r   r9   r   
deprecatedJ   s   r;   old_qualnamenew_fnr-   c                  sB   t || dt ddd fd
d}| |_| dd |_|S )Nr   r#   )r   __annotations__)assignedr.   r/   r0   r1   r   r   c                    s    | i |S )zDeprecated alias.r   r2   r=   r   r   r3   u   s   z!deprecated_alias.<locals>.wrapperr   r5   )r;   r   r   
rpartitionr   )r<   r=   r!   r   r3   r   rA   r   deprecated_aliasn   s   
rD   T)frozenc                   @  s`   e Zd ZU e Zded< e Zded< e Z	ded< e Z
ded< ejed	Zded
< dS )DeprecatedAttributezClassVar[object]_not_setr   valuer   r!   r"   r   )defaultr#   N)r   r   r   r   rG   r?   attrZibrH   r!   r   r#   r   r   r   r   rF      s   
 rF   c                   @  s    e Zd ZU ded< d
ddZd	S )_ModuleWithDeprecationszdict[str, DeprecatedAttribute]__deprecated_attributes__namer   r   r   c                 C  sj   || j v r*| j | }|j}|tju r|j}| j d| }t||j|j|d |jS d}t	|
| j|)Nr   r>   z!module '{}' has no attribute '{}')rL   r#   rF   rG   rH   r   r*   r!   r   AttributeErrorr7   )selfrM   infor#   r   r)   r   r   r   __getattr__   s   


z#_ModuleWithDeprecations.__getattr__N)rM   r   r   r   )r   r   r   r?   rQ   r   r   r   r   rK      s   
 rK   module_namec                 C  s(   t j|  }t|_t|tsJ i |_d S )N)sysmodulesrK   	__class__
isinstancerL   )rR   moduler   r   r   enable_attribute_deprecations   s   

rX   )r   r   r   r   )r   r   r   r   )r   r   r!   r   r   r"   r#   r   r    r   r   r$   )
r!   r   r   r   r   r"   r#   r   r   r+   )
r<   r   r=   r-   r!   r   r   r"   r   r-   )rR   r   r   r$   )
__future__r   rS   r'   collections.abcr   	functoolsr   typesr   typingr   r   r   rJ   typing_extensionsr	   r
   r   FutureWarningr   r   r   r*   r;   rD   srF   rK   rX   r   r   r   r   <module>   s0    


$
	