a
    Lfr                      @  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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,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   W/var/www/ai-form-bot/venv/lib/python3.9/site-packages/numpy/typing/tests/test_typing.py	_key_func6   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_filename?   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_funcF   s    r*   module)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stderr	exit_codeZ
str_concatfilenameir   r   r   run_mypyK   s<    


rG   zIterator[ParameterSet])rA   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)rA   rootr%   filesfnameZshort_fnameextfullpathr   r   r   get_test_casesy   s    rQ   zMypy is not installedr   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
    rX   )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>   rU   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errorsrW   
error_liner&   rF   lineZtarget_line
expressionr%   markerexpected_errorr   r   r   	test_fail   s6    
&ri   z9Extra error at line {}

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

Expression: {}
Expected error: {}
Observed error: {!r}
z
None | strr#   )r   rf   errorrh   r&   r   c                 C  s<   |d u rt t|||n||vr8t t||||d S )N)rV   
_FAIL_MSG1format
_FAIL_MSG2)r   rf   rj   rh   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'   rV   _REVEAL_MSGrl   )r   ra   rW   rd   r&   r   r   r   test_reveal   s    ro   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   rJ   r   sep	importlibutilspec_from_file_locationloadermodule_from_specexec_module)r   Zpath_without_extensionr%   dirnamerE   specZtest_moduler   r   r   test_code_runs   s    r{   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/   rj   zExpression is of type "Any")r   r   r   r<   r   r[   r\   r'   rstripLINENO_MAPPINGr   rV   rn   rl   r`   )r   rW   fZexpression_listZ_msgr&   r!   rf   r   r   r   test_extended_precision  s    
&
r   );
__future__r   importlib.utilrs   r   r7   r5   collectionsr   collections.abcr   typingr   r?   Znumpy.typing.mypy_pluginr   r3   ZRUN_MYPYmarkZskipifZ
pytestmarkZmypyr   ImportErrorZNO_MYPYZ_pytest.mark.structuresr   r   r   ry   __file__ZDATA_DIRr9   r;   r:   r<   r>   r1   listr   __annotations__r    r'   r*   ZfixturerG   rQ   ZslowZparametrizerX   ri   rk   rm   r`   rn   ro   r{   r   r   r   r   r   r   <module>   s   

	-		#