o
    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r@edvr@d	Zejje d
dZdejv ZerVedvrVd	Zejje d
dZzd dlmZ W n eyr   d	ZY nw dZer}d 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j,ejjed%d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    Q/var/www/html/venv/lib/python3.10/site-packages/numpy/typing/tests/test_typing.py	_key_funcD   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_filenameM   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_funcT   s   r.   zMypy is not installed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 )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
    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_mypyY   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_cases   s   r[   r   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.   slowfixturerO   r[   parametrizera   rt   rw   ry   ri   rz   r{   r   r   r   r    r    r    r!   <module>   s    

	

	

-		#
