a
    ;ev"                     @  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redvrd	Zejje d
dZdejv Zeredvrd	Zejje d
dZzd dlmZ W n ey   d	ZY n0 dZerd 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< dddddZ)dddddZ*d dd!d"d#Z+ejj,ejjed$dej-d%d	d&d'd(d)d*Z.dd+d,d-d.Z/ejj,ejjed$dej0d/e/e d'd(d0d1Z1ejj,ejjed$dej0d/e/e!dd'd2d3d4Z2d5Z3d6Z4dddd7d8d'd9d:d;Z5d<Z6ejj,ejjed$dej0d/e/e"dd'd2d=d>Z7ejj,ejjed$dej0d/e/e dd'd2d?d@Z8dAdBdCdDdEdFdGdHdIdJdKdLdMZ9ejj,ejjed$dd'd(dNdOZ:dS )P    )annotationsN)defaultdict)Iterator)TYPE_CHECKING)_EXTENDED_PRECISION_LISTZNPY_RUN_MYPY_IN_TESTSUITE)0 falseTz#`NPY_RUN_MYPY_IN_TESTSUITE` not set)reason)apiF)ParameterSetdatapassfailZrevealmisczmypy.iniz.mypy_cachezdefaultdict[str, list[str]]OUTPUT_MYPYstr)key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   R/var/www/sunrise/env/lib/python3.9/site-packages/numpy/typing/tests/test_typing.py	_key_funcD   s    r    ztuple[int, str])msgr   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_filenameM   s    r'   zre.Match[str])matchr   c                 C  s   |   d S )z4`re.sub` helper function for stripping module names.r   )groups)r(   r   r   r   
strip_funcT   s    r*   zMypy is not installedmodule)ZscopeZautouseNone)r   c                  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\}}}|rrtd|  n|dvrtd| d	|  d
}d}|dD ]P}d|v rq|du rt|}|| d7 }| |durt| | d
}d}qq>dS )zClears 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
    Z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)Zsplit_pattern	directorystdoutstderrZ	exit_codeZ
str_concatfilenameir   r   r   run_mypyY   s<    


rE   zIterator[ParameterSet])r@   r   c                 c  sZ   t | D ]J\}}}|D ]:}t j|\}}|dv rt j||}tj||dV  qq
d S )N)z.pyiz.py)id)r   walkr   splitextr   r>   param)r@   rootr%   filesfnameZshort_fnameextfullpathr   r   r   get_test_cases   s    rO   r   c                 C  s8   t }| |v r4d}|ddd ||  D 7 }t|d S )NzUnexpected mypy output

r.   c                 s  s   | ]}t |d  V  qdS )r   N)r'   ).0vr   r   r   	<genexpr>       ztest_success.<locals>.<genexpr>)r   r   AssertionError)r   output_mypyr!   r   r   r   test_success   s
    rV   )r   r   c                 C  s  d}t | }| }W d    n1 s*0    Y  tdd }t}| |v sPJ ||  D ]&}t|\}}||  | d7  < qXt|D ]\}}	|d }|	dsd|	vr||vrq||d  }
d|
v r|
d	\}}}||  }| }t	| |||| qt
d
| d||   qd S )NTc                   S  s   dS )Nr   r   r   r   r   r   <lambda>   rS   ztest_fail.<locals>.<lambda>r.   r   #z E:z# E:z  # E: zUnexpected mypy output at line r-   )open	readlinesr   r   r'   	enumerate
startswith	partitionr$   
_test_failr>   r   )r   __tracebackhide__ZfinlineserrorsrU   
error_liner&   rD   lineZtarget_line
expressionr%   markerexpected_errorr   r   r   	test_fail   s6    
&rg   z9Extra error at line {}

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

Expression: {}
Expected error: {}
Observed error: {!r}
z
None | strr#   )r   rd   errorrf   r&   r   c                 C  s<   |d u rt t|||n||vr8t t||||d S )N)rT   
_FAIL_MSG1format
_FAIL_MSG2)r   rd   rh   rf   r&   r   r   r   r^      s    r^   zReveal mismatch at line {}

{}
c                 C  sB   d}t }| |vrdS ||  D ] }t|\}}tt||qdS )z[Validate that mypy correctly infers the return-types of
    the expressions in `path`.
    TN)r   r'   rT   _REVEAL_MSGrj   )r   r_   rU   rb   r&   r   r   r   test_reveal   s    rm   c                 C  sv   t j| \}}| t jdd \}}tj| d| | }|dusLJ |jdusZJ tj	|}|j
| dS )z9Validate that the code in `path` properly during runtime.N.)r   r   rH   r   sep	importlibutilspec_from_file_locationloadermodule_from_specexec_module)r   Zpath_without_extensionr%   dirnamerC   specZtest_moduler   r   r   test_code_runs   s    ry   Zuint128Zuint256Zint128Zint256Zfloat80Zfloat96Zfloat128Zfloat256Z
complex160Z
complex192Z
complex256Z
complex512)                                    c                  C  s   t jtd} t}| |v sJ t| }| }W d    n1 sD0    Y  ||  D ]X}t|\}}||d  d}t	| t
v rtt||qVd|vrVt| ||d| qVd S )Nzextended_precision.pyir   r.   rh   zExpression is of type "Any")r   r   r   r;   r   rY   rZ   r'   rstripLINENO_MAPPINGr   rT   rl   rj   r^   )r   rU   fZexpression_list_msgr&   r!   rd   r   r   r   test_extended_precision  s    
&
r   );
__future__r   importlib.utilrq   r   r6   r4   collectionsr   collections.abcr   typingr   r>   Znumpy.typing.mypy_pluginr   r2   ZRUN_MYPYmarkZskipifZ
pytestmarkZmypyr   ImportErrorZNO_MYPYZ_pytest.mark.structuresr   r   r   rw   __file__ZDATA_DIRr8   r:   r9   r;   r=   r0   listr   __annotations__r    r'   r*   ZslowZfixturerE   rO   ZparametrizerV   rg   ri   rk   r^   rl   rm   ry   r   r   r   r   r   r   <module>   s   
	

	-		#