a
    (ñ»jä   ã                   @  s8  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ddd	œd
d„ƒZddœdd„Zdddœdd„Zdddœdd„Zdddœdd„Zddœdd„Zddœdd„Zdddœdd„Ze	dded �d!dœd"d#„ƒZdddœd$d%„ZG d&d'„ d'ƒZdddœd(d)„Ze	d*d+ddd,�d!dœd-d.„ƒZdddœd/d0„Zd1dœd2d3„Ze
d4ed5dd6�Zdddœd7d8„ZG d9d:„ d:ƒZ dddœd;d<„Z!e	d=dd>d �ddœd?d@„ƒZ"e	d=dd>d �ddœdAdB„ƒZ#e	d=ddd �ddœdCdD„ƒZ$e	d=ddd �ddœdEdF„ƒZ%ddœdGdH„Z&dddœdIdJ„Z'ddœdKdL„Z(dS )Mé    )ÚannotationsN)Ú
ModuleTypeé   )ÚTrioDeprecationWarningÚ
deprecatedÚdeprecated_aliasÚwarn_deprecatedé   )Úmodule_with_deprecationszpytest.WarningsRecorder)ÚrecwarnÚreturnc                 C  s   t  d¡ t  dt¡ | S )NÚalwaysÚignore)ÚwarningsÚsimplefilterÚResourceWarning)r   © r   ú@E:\soccer\ml_env\Lib\site-packages\trio/_tests/test_deprecate.pyÚrecwarn_always   s    
r   ztuple[str, int]©r   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   ÚNone)r   r   c                 C  s¼   ddœdd„}|ƒ  t ƒ \}}t| ƒdks.J ‚|  t¡}t|jtƒsHJ ‚d|jjd v s\J ‚d|jjd v spJ ‚d	|jjd v s„J ‚d
|jjd v s˜J ‚|j|ks¦J ‚|j	|d ks¸J ‚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   ÚlenÚpopÚDeprecationWarningÚ
isinstanceÚmessageÚWarningÚargsr   r   )r   r(   r   r   Úgotr   r   r   Útest_warn_deprecated#   s    

r2   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 sNJ ‚d|jjd v sbJ ‚d|jjd v svJ ‚d S )	Nr#   ú1.3r$   r	   zwater is deprecatedr   zno replacementzTrio 1.3)r   r*   r+   r,   r-   r.   r/   r0   ©r   r1   r   r   r   Ú(test_warn_deprecated_no_instead_or_issue4   s    
r5   c                   s^   ddœ‡ fdd„}ddœdd„‰ t ƒ \}}|ƒ  |  t¡}|j|ksHJ ‚|j|d ksZJ ‚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Úxr3   é   Úyé   )r%   r&   Ú
stacklevelr'   r   r   r   r   r7   E   s    z0test_warn_deprecated_stacklevel.<locals>.nested2r	   )r   r+   r,   r   r   )r   r8   r   r   r1   r   r6   r   Útest_warn_deprecated_stacklevelA   s    

r>   c                   C  s   d S r   r   r   r   r   r   ÚoldO   s    r?   c                   C  s   d S r   r   r   r   r   r   ÚnewS   s    r@   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 sRJ ‚d S )Nú1.0r	   r$   z test_deprecate.old is deprecatedr   ztest_deprecate.new instead)	r   r?   r@   r+   r,   r-   r.   r/   r0   r4   r   r   r   Útest_warn_deprecated_formattingW   s
    
rB   ú1.5é{   r$   Úintc                   C  s   dS )Nr<   r   r   r   r   r   Údeprecated_old_   s    rF   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 sPJ ‚d|jjd v sdJ ‚d|jjd v sxJ ‚d S )Nr<   z+test_deprecate.deprecated_old is deprecatedr   rC   ztest_deprecate.newz
issues/123)rF   r+   r,   r-   r.   r/   r0   r4   r   r   r   Útest_deprecated_decoratord   s    
rG   c                   @  s(   e Zd Zedddd�ddœdd„ƒZd	S )
ÚFoorA   rD   Zcryingr$   rE   r   c                 C  s   dS )Nr:   r   ©Úselfr   r   r   Úmethodo   s    z
Foo.methodN)Ú__name__Ú
__module__Ú__qualname__r   rK   r   r   r   r   rH   n   s   rH   c                 C  sH   t ƒ }| ¡ dksJ ‚|  t¡}t|jtƒs0J ‚d|jjd v sDJ ‚d S )Nr:   z'test_deprecate.Foo.method is deprecatedr   )rH   rK   r+   r,   r-   r.   r/   r0   )r   Úfr1   r   r   r   Ú test_deprecated_decorator_methodt   s
    
rP   r"   z	the thing)Úthingr%   r&   c                   C  s   dS )NéH   r   r   r   r   r   Údeprecated_with_thing|   s    rS   c                 C  s@   t ƒ dksJ ‚|  t¡}t|jtƒs(J ‚d|jjd v s<J ‚d S )NrR   zthe thing is deprecatedr   )rS   r+   r,   r-   r.   r/   r0   r4   r   r   r   Ú-test_deprecated_decorator_with_explicit_thing�   s    
rT   Ústrc                   C  s   dS )Núnew hotnessr   r   r   r   r   Únew_hotnessŠ   s    rW   Ú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 sPJ ‚d|jjd v sdJ ‚d|jjd v sxJ ‚tt jtƒsˆJ ‚dt jv s–J ‚dt jv s¤J ‚dt jv s²J ‚d S )	NrV   z(test_deprecate.old_hotness is deprecatedr   rY   z"test_deprecate.new_hotness insteadzissues/1z.. deprecated:: 1.23zissues/1>`__)	rX   r+   r,   r-   r.   r/   r0   Ú__doc__rU   r4   r   r   r   Útest_deprecated_alias‘   s    
r\   c                   @  s*   e Zd Zddœdd„Zededdd�Zd	S )
ÚAliasrU   r   c                 C  s   dS )Núnew hotness methodr   rI   r   r   r   Únew_hotness_method¡   s    zAlias.new_hotness_methodzAlias.old_hotness_methodz3.21r	   rZ   N)rL   rM   rN   r_   r   Úold_hotness_methodr   r   r   r   r]       s   ür]   c                 C  sX   t ƒ }| ¡ dksJ ‚|  t¡}t|jtƒs0J ‚|jjd }d|v sHJ ‚d|v sTJ ‚d S )Nr^   r   z5test_deprecate.Alias.old_hotness_method is deprecatedz/test_deprecate.Alias.new_hotness_method instead)r]   r`   r+   r,   r-   r.   r/   r0   )r   Úobjr1   Úmsgr   r   r   Útest_deprecated_alias_method¬   s    
rc   z2.1Úhic                   C  s   dS ©zHello!Nr   r   r   r   r   Údocstring_test1¶   s    rf   c                   C  s   dS re   r   r   r   r   r   Údocstring_test2»   s    rg   c                   C  s   dS re   r   r   r   r   r   Údocstring_test3À   s    rh   c                   C  s   dS re   r   r   r   r   r   Údocstring_test4Å   s    ri   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s8J ‚d S )Nz�Hello!

.. 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

)rf   r[   rg   rh   ri   r   r   r   r   Ú!test_deprecated_docstring_mungingÊ   s     ÿÿÿÿÿÿÿÿrj   c                 C  sD  t jdksJ ‚t| ƒdksJ ‚tt ƒtu s.J ‚tƒ \}}t jdksFJ ‚|  t¡}t	|j
tƒs`J ‚|j|ksnJ ‚|j|d ks€J ‚d|j
jd v s”J ‚d|j
jd v s¨J ‚d|j
jd v s¼J ‚d|j
jd v sÐJ ‚t jd	ksÞJ ‚|  t¡}t	|j
tƒsøJ ‚d
|j
jd v �sJ ‚t t¡� t j W d   ƒ n1 �s60    Y  d S )Nrd   r   Zvalue1r	   zmodule_with_deprecations.dep1zTrio 1.1r)   zvalue1 insteadZvalue2zinstead-string instead)r
   Zregularr*   Útyper   r   Zdep1r+   r,   r-   r.   r/   r   r   r0   Zdep2ÚpytestZraisesÚAttributeErrorZasdf)r   r   r   r1   r   r   r   Útest_module_with_deprecationsô   s&    


rn   c                   C  s¶   t  ¡ �  tddd d d� W d   ƒ n1 s.0    Y  t jtdd��  tddd d d� W d   ƒ n1 sl0    Y  t  t¡�" tddd d dd� W d   ƒ n1 s¨0    Y  d S )NZfooÚbarr$   z6^foo is deprecated since Trio bar with no replacement$)ÚmatchT)r%   r&   Zuse_triodeprecationwarning)rl   Zdeprecated_callr   Zwarnsr,   r   r   r   r   r   Útest_warning_class  s    
.þ.ûrq   ))Ú
__future__r   r   r   Útypesr   rl   Z
_deprecater   r   r   r   Ú r
   Zfixturer   r   r2   r5   r>   r?   r@   rB   rF   rG   rH   rP   rS   rT   rW   rX   r\   r]   rc   rf   rg   rh   ri   rj   rn   rq   r   r   r   r   Ú<module>   sN   
	
*