o
    4@Hh                      @  s  d dl mZ d dlZd dlZd dlmZ d dlZddlmZm	Z	m
Z
mZ ddlmZ ejdLddZdMddZdNddZdNddZdNddZdOddZdOddZdNddZe	ddeddPd!d"ZdNd#d$ZG d%d& d&ZdNd'd(Ze	d)d*ddd+dPd,d-ZdNd.d/ZdQd1d2Ze
d3ed4dd5ZdNd6d7ZG d8d9 d9Z dNd:d;Z!e	d<dd=ddOd>d?Z"e	d<dd=ddOd@dAZ#e	d<ddddOdBdCZ$e	d<ddddOdDdEZ%dOdFdGZ&dNdHdIZ'dOdJdKZ(dS )R    )annotationsN)
ModuleType   )TrioDeprecationWarning
deprecateddeprecated_aliaswarn_deprecated   )module_with_deprecationsrecwarnpytest.WarningsRecorderreturnc                 C  s   t d t dt | S )Nalwaysignore)warningssimplefilterResourceWarning)r    r   Z/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/trio/_tests/test_deprecate.pyrecwarn_always   s   
r   tuple[str, int]c                  C  s:   t  } | d us
J | jd usJ t | j}|j|jfS N)inspectcurrentframef_backgetframeinfofilenamelineno)frameinfor   r   r   _here   s
   r    Nonec                 C  s   ddd}|  t  \}}t| dksJ | t}t|jts"J d|jjd v s,J d|jjd v s6J d	|jjd v s@J d
|jjd v sJJ |j|ksQJ |j	|d ksZJ d S )Nr   r!   c                   S  s   t ddddd d S )Nice1.2r	   waterissueinsteadr   r   r   r   r   deprecated_thing$   s   z.test_warn_deprecated.<locals>.deprecated_thingr	   zice is deprecatedr   zTrio 1.2zwater instead	/issues/1r   r!   )
r    lenpopDeprecationWarning
isinstancemessageWarningargsr   r   )r   r)   r   r   gotr   r   r   test_warn_deprecated#   s   


r4   c                 C  sz   t ddd d d t| dksJ | t}t|jtsJ d|jjd v s'J d|jjd v s1J d|jjd v s;J d S )	Nr$   1.3r%   r	   zwater is deprecatedr   zno replacementzTrio 1.3)r   r,   r-   r.   r/   r0   r1   r2   r   r3   r   r   r   (test_warn_deprecated_no_instead_or_issue4   s   
r7   c                   sV   d fdd}ddd t  \}}|  | t}|j|ks J |j|d ks)J d S )	Nr   r!   c                     s
      d S r   r   r   nested2r   r   nested1B   s   
z0test_warn_deprecated_stacklevel.<locals>.nested1c                   S  s   t dddddd d S )Nxr5      y   )r&   r'   
stacklevelr(   r   r   r   r   r9   E   s   z0test_warn_deprecated_stacklevel.<locals>.nested2r	   r+   )r    r-   r.   r   r   )r   r:   r   r   r3   r   r8   r   test_warn_deprecated_stacklevelA   s   


r@   c                   C     d S r   r   r   r   r   r   oldO      rB   c                   C  rA   r   r   r   r   r   r   newS   rC   rD   c                 C  sV   t tddtd | t}t|jtsJ d|jjd v sJ d|jjd v s)J d S )N1.0r	   r%   z test_deprecate.old is deprecatedr   ztest_deprecate.new instead)	r   rB   rD   r-   r.   r/   r0   r1   r2   r6   r   r   r   test_warn_deprecated_formattingW   s
   
rF   1.5{   r%   intc                   C     dS )Nr>   r   r   r   r   r   deprecated_old_      rK   c                 C  s|   t  dksJ | t}t|jtsJ d|jjd v sJ d|jjd v s(J d|jjd v s2J d|jjd v s<J d S )Nr>   z+test_deprecate.deprecated_old is deprecatedr   rG   ztest_deprecate.newz
issues/123)rK   r-   r.   r/   r0   r1   r2   r6   r   r   r   test_deprecated_decoratord   s   
rM   c                   @  s$   e Zd Zeddddd
ddZd	S )FoorE   rH   cryingr%   r   rI   c                 C  rJ   )Nr<   r   selfr   r   r   methodo   rL   z
Foo.methodNr   rI   )__name__
__module____qualname__r   rR   r   r   r   r   rN   n   s    rN   c                 C  sH   t  }| dksJ | t}t|jtsJ d|jjd v s"J d S )Nr<   z'test_deprecate.Foo.method is deprecatedr   )rN   rR   r-   r.   r/   r0   r1   r2   )r   fr3   r   r   r    test_deprecated_decorator_methodt   s
   
rX   r#   z	the thing)thingr&   r'   c                   C  rJ   )NH   r   r   r   r   r   deprecated_with_thing|   rL   r[   c                 C  s@   t  dksJ | t}t|jtsJ d|jjd v sJ d S )NrZ   zthe thing is deprecatedr   )r[   r-   r.   r/   r0   r1   r2   r6   r   r   r   -test_deprecated_decorator_with_explicit_thing   s   
r\   strc                   C  rJ   )Nnew hotnessr   r   r   r   r   new_hotness   rC   r_   old_hotness1.23r&   c                 C  s   t  dksJ | t}t|jtsJ d|jjd v sJ d|jjd v s(J d|jjd v s2J d|jjd v s<J tt jtsDJ dt jv sKJ dt jv sRJ dt jv sYJ d S )	Nr^   z(test_deprecate.old_hotness is deprecatedr   ra   z"test_deprecate.new_hotness insteadzissues/1z.. deprecated:: 1.23zissues/1>`__)	r`   r-   r.   r/   r0   r1   r2   __doc__r]   r6   r   r   r   test_deprecated_alias   s   
rd   c                   @  s&   e Zd Zd
ddZededddZd	S )Aliasr   r]   c                 C  rJ   )Nnew hotness methodr   rP   r   r   r   new_hotness_method   rC   zAlias.new_hotness_methodzAlias.old_hotness_methodz3.21r	   rb   Nr   r]   )rT   rU   rV   rg   r   old_hotness_methodr   r   r   r   re      s    

re   c                 C  sX   t  }| dksJ | t}t|jtsJ |jjd }d|v s$J d|v s*J d S )Nrf   r   z5test_deprecate.Alias.old_hotness_method is deprecatedz/test_deprecate.Alias.new_hotness_method instead)re   ri   r-   r.   r/   r0   r1   r2   )r   objr3   msgr   r   r   test_deprecated_alias_method   s   
rl   z2.1hic                   C  rJ   zHello!Nr   r   r   r   r   docstring_test1       ro   c                   C  rJ   rn   r   r   r   r   r   docstring_test2   rp   rq   c                   C  rJ   rn   r   r   r   r   r   docstring_test3   rp   rr   c                   C  rJ   rn   r   r   r   r   r   docstring_test4   rp   rs   c                   C  s<   t jdksJ tjdksJ tjdksJ tjdksJ d S )NzHello!

.. deprecated:: 2.1
   Use hi instead.
   For details, see `issue #1 <https://github.com/python-trio/trio/issues/1>`__.

z0Hello!

.. deprecated:: 2.1
   Use hi instead.

znHello!

.. deprecated:: 2.1
   For details, see `issue #1 <https://github.com/python-trio/trio/issues/1>`__.

zHello!

.. deprecated:: 2.1

)ro   rc   rq   rr   rs   r   r   r   r   !test_deprecated_docstring_munging   s   

rt   c                 C  sB  t jdksJ t| dksJ tt tu sJ t \}}t jdks#J | t}t	|j
ts0J |j|ks7J |j|d ks@J d|j
jd v sJJ d|j
jd v sTJ d|j
jd v s^J d|j
jd v shJ t jd	ksoJ | t}t	|j
ts|J d
|j
jd v sJ tt t j W d    d S 1 sw   Y  d S )Nrm   r   value1r	   zmodule_with_deprecations.dep1zTrio 1.1r*   zvalue1 insteadvalue2zinstead-string instead)r
   regularr,   typer   r    dep1r-   r.   r/   r0   r1   r   r   r2   dep2pytestraisesAttributeErrorasdf)r   r   r   r3   r   r   r   test_module_with_deprecations   s(   


"r   c                   C  s   t   tddd d d W d    n1 sw   Y  t jtdd tddd d d W d    n1 s6w   Y  t t tddd d dd W d    d S 1 sUw   Y  d S )Nfoobarr%   z6^foo is deprecated since Trio bar with no replacement$)matchT)r&   r'   use_triodeprecationwarning)r{   deprecated_callr   warnsr.   r   r   r   r   r   test_warning_class  s$   
"r   )r   r   r   r   )r   r   )r   r   r   r!   r+   rS   rh   ))
__future__r   r   r   typesr   r{   
_deprecater   r   r   r    r
   fixturer   r    r4   r7   r@   rB   rD   rF   rK   rM   rN   rX   r[   r\   r_   r`   rd   re   rl   ro   rq   rr   rs   rt   r   r   r   r   r   r   <module>   sP    











	




*