o
    z¨Êhr   ã                   @  s²  U d dl mZ d dlZd dl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Zd dlmZ dejv Zer@edvr@d	Zejje d
d�Zzd dlmZ W n ey\   d	ZY nw dZergd dlmZ ej ej e¡d¡Zej ed¡Z ej ed¡Z!ej ed¡Z"ej ed¡Z#ej ed¡Z$ej ed¡Z%ee&ƒZ'de(d< dRdd„Z)dSdd „Z*dTd#d$„Z+ej,d%d	d&�dUd(d)„ƒZ-dVd,d-„Z.ejj/ejjed.d�ej 0d/e.e ƒ¡dUd0d1„ƒƒƒZ1ejj/ejjed.d�ej 0d/e.e!ƒ¡dWd2d3„ƒƒƒZ2d4Z3d5Z4dXd<d=„Z5d>Z6ejj/ejjed.d�ej 0d/e.e"ƒ¡dWd?d@„ƒƒƒZ7ejj/ejjed.d�ej 0d/e.e ƒ¡dWdAdB„ƒƒƒZ8dCdDdEdFdGdHdIdJdKdLdMdNdOœZ9ejj/ejjed.d�dUdPdQ„ƒƒZ:dS )Yé    )ÚannotationsN)Údefaultdict)ÚIterator)ÚTYPE_CHECKING)Ú_EXTENDED_PRECISION_LISTÚNPY_RUN_MYPY_IN_TESTSUITE)Ú0Ú ÚfalseTz#`NPY_RUN_MYPY_IN_TESTSUITE` not set)Úreason)ÚapiF)ÚParameterSetÚdataÚpassÚfailÚrevealÚmisczmypy.iniz.mypy_cachezdefaultdict[str, list[str]]ÚOUTPUT_MYPYÚkeyÚstrÚreturnc                 C  s*   t j | ¡\}}t j || dd¡d ¡S )zySplit at the first occurrence of the ``:`` character.

    Windows drive-letters (*e.g.* ``C:``) are ignored herein.
    ú:é   r   )ÚosÚpathÚ
splitdriveÚjoinÚsplit)r   ÚdriveÚtail© r    úP/var/www/html/env/lib/python3.10/site-packages/numpy/typing/tests/test_typing.pyÚ	_key_func6   s   r"   Úmsgútuple[int, str]c                 C  s2   t j | ¡\}}| dd¡\}}} t|ƒ|  ¡ fS )z7Strip the filename and line number from a mypy message.r   é   )r   r   r   r   ÚintÚstrip)r#   Ú_r   Úlinenor    r    r!   Ú_strip_filename?   s   r*   Úmatchúre.Match[str]c                 C  s   |   ¡ d S )z4`re.sub` helper function for stripping module names.r   )Úgroups)r+   r    r    r!   Ú
strip_funcF   s   r.   Úmodule)ÚscopeÚautouseÚNonec                  C  sú   t j t¡rtt j dd¡ƒrt t¡ t	 
d¡} ttttfD ][}t dtdt|g¡\}}}|r9t d|› �¡ n|dvrHt d|› d	|› �¡ d
}d}| d¡D ](}d|v rXqQ|du r`t|ƒ}||› d�7 }|  |¡duryt|  |¡ d
}d}qQqdS )zøClears the cache and run mypy before running any of the typing tests.

    The mypy results are cached in `OUTPUT_MYPY` for further use.

    The cache refresh can be skipped using

    NUMPY_TYPING_TEST_CLEAR_CACHE=0 pytest numpy/typing/tests
    ÚNUMPY_TYPING_TEST_CLEAR_CACHETz(\s+)?\^(\~+)?z--config-filez--cache-dirz Unexpected mypy standard error

>   r   r   zUnexpected mypy exit code: ú

r	   NÚ
znote:)r   r   ÚisdirÚ	CACHE_DIRÚboolÚenvironÚgetÚshutilÚrmtreeÚreÚcompileÚPASS_DIRÚ
REVEAL_DIRÚFAIL_DIRÚMISC_DIRr   ÚrunÚMYPY_INIÚpytestr   r   r"   r+   r   Úappend)Úsplit_patternÚ	directoryÚstdoutÚstderrÚ	exit_codeÚ
str_concatÚfilenameÚir    r    r!   Úrun_mypyK   sB   
ÿþ

û€öðrO   rH   úIterator[ParameterSet]c                 c  s\   � t  | ¡D ]%\}}}|D ]}t j |¡\}}|dv r*t j ||¡}tj||d�V  qqd S )N)z.pyiz.py)Úid)r   Úwalkr   Úsplitextr   rE   Úparam)rH   Úrootr(   ÚfilesÚfnameÚshort_fnameÚextÚfullpathr    r    r!   Úget_test_casesy   s   €€üÿr[   zMypy is not installedr   c                 C  s8   t }| |v rd}|d dd„ ||  D ƒ¡7 }t|ƒ‚d S )NzUnexpected mypy output

r5   c                 s  s   � | ]	}t |ƒd  V  qdS )r   N)r*   )Ú.0Úvr    r    r!   Ú	<genexpr>Š   s   € ztest_success.<locals>.<genexpr>)r   r   ÚAssertionError)r   Úoutput_mypyr#   r    r    r!   Útest_success‚   s   ýra   c                 C  s  d}t | ƒ�}| ¡ }W d   ƒ n1 sw   Y  tdd„ ƒ}t}| |v s(J ‚||  D ]}t|ƒ\}}||  |› d�7  < q,t|ƒD ]H\}}	|d }|	 d¡sYd|	vrZ||vrZqD||d  }
d|
v r|
 d	¡\}}}||  ¡ }| ¡ }t	| ||||ƒ qDt
 d
|› d|| › �¡ qDd S )NTc                   S  s   dS )Nr	   r    r    r    r    r!   Ú<lambda>—   s    ztest_fail.<locals>.<lambda>r5   r   ú#z E:z# E:z  # E: zUnexpected mypy output at line r4   )ÚopenÚ	readlinesr   r   r*   Ú	enumerateÚ
startswithÚ	partitionr'   Ú
_test_failrE   r   )r   Ú__tracebackhide__ÚfinÚlinesÚerrorsr`   Ú
error_liner)   rN   ÚlineÚtarget_lineÚ
expressionr(   ÚmarkerÚexpected_errorr    r    r!   Ú	test_failŽ   s4   

ÿÿÿñrt   z9Extra error at line {}

Expression: {}
Extra error: {!r}
zRError mismatch at line {}

Expression: {}
Expected error: {}
Observed error: {!r}
rq   Úerrorrs   ú
None | strr)   r&   c                 C  s:   |d u rt t |||¡ƒ‚||vrt t ||||¡ƒ‚d S )N)r_   Ú
_FAIL_MSG1ÚformatÚ
_FAIL_MSG2)r   rq   ru   rs   r)   r    r    r!   ri   Â   s   ÿÿri   zReveal mismatch at line {}

{}
c                 C  s@   d}t }| |vr
dS ||  D ]}t|ƒ\}}tt ||¡ƒ‚dS )z[Validate that mypy correctly infers the return-types of
    the expressions in `path`.
    TN)r   r*   r_   Ú_REVEAL_MSGrx   )r   rj   r`   rn   r)   r    r    r!   Útest_reveal×   s   þr{   c                 C  sv   t j | ¡\}}|  t j¡dd… \}}tj |› d|› �| ¡}|dus&J ‚|jdus-J ‚tj 	|¡}|j 
|¡ dS )z9Validate that the code in `path` properly during runtime.éþÿÿÿNÚ.)r   r   rS   r   ÚsepÚ	importlibÚutilÚspec_from_file_locationÚloaderÚmodule_from_specÚexec_module)r   Úpath_without_extensionr(   ÚdirnamerM   ÚspecÚtest_moduler    r    r!   Útest_code_runsé   s   ÿr‰   Úuint128Úuint256Úint128Úint256Úfloat80Úfloat96Úfloat128Úfloat256Ú
complex160Ú
complex192Ú
complex256Ú
complex512)é   é   é   é   é   é   é   é   é   é   é   é   c                  C  s²   t j td¡} t}| |v sJ ‚t| ƒ�}| ¡ }W d   ƒ n1 s"w   Y  ||  D ]+}t|ƒ\}}||d   d¡}t	| t
v rJtt ||¡ƒ‚d|vrVt| ||d|ƒ q+d S )Nzextended_precision.pyir   r5   ru   zExpression is of type "Any")r   r   r   rB   r   rd   re   r*   ÚrstripÚLINENO_MAPPINGr   r_   rz   rx   ri   )r   r`   ÚfÚexpression_listÚ_msgr)   r#   rq   r    r    r!   Útest_extended_precision  s"   

ÿ
ÿ€ùr§   )r   r   r   r   )r#   r   r   r$   )r+   r,   r   r   )r   r2   )rH   r   r   rP   )r   r   r   r2   )r   r   rq   r   ru   r   rs   rv   r)   r&   r   r2   );Ú
__future__r   Úimportlib.utilr   r   r=   r;   Úcollectionsr   Úcollections.abcr   Útypingr   rE   Únumpy.typing.mypy_pluginr   r9   ÚRUN_MYPYÚmarkÚskipifÚ
pytestmarkÚmypyr   ÚImportErrorÚNO_MYPYÚ_pytest.mark.structuresr   r   r   r†   Ú__file__ÚDATA_DIRr?   rA   r@   rB   rD   r7   Úlistr   Ú__annotations__r"   r*   r.   ÚfixturerO   r[   ÚslowÚparametrizera   rt   rw   ry   ri   rz   r{   r‰   r£   r§   r    r    r    r!   Ú<module>   s–    
þÿ

	

-		#
ô