o
    Gg!                     @  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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yV   dZY nw dZe
rgd dlmZ 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,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)TYPE_CHECKING)_EXTENDED_PRECISION_LISTZNPY_RUN_MYPY_IN_TESTSUITE)0 falseTz#`NPY_RUN_MYPY_IN_TESTSUITE` not set)reason)apiF)Iterator)ParameterSetdatapassfailZ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   _C:\Users\micha\Documents\internet-seite\env\Lib\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)scopeZ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
    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   sB   


rI   rC   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   rA   param)rC   rootr&   filesfnameZshort_fnameextfullpathr   r   r   get_test_casesy   s   rT   zMypy is not installedr   c                 C  s8   t }| |v rd}|ddd ||  D 7 }t|d S )NzUnexpected mypy output

r1   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   rZ   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>r1   r   #z E:z# E:z  # E: zUnexpected mypy output at line r0   )open	readlinesr   r   r(   	enumerate
startswith	partitionr%   
_test_failrA   r   )r   __tracebackhide__ZfinlineserrorsrY   
error_liner'   rH   lineZtarget_line
expressionr&   markererrorexpected_errorr   r   r   	test_fail   s:   

rl   z9Extra error at line {}

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

Expression: {}
Expected error: {}
Observed error: {!r}
rh   rj   rk   
None | strr'   r$   c                 C  s:   |d u rt t|||||vrt t||||d S )N)rX   
_FAIL_MSG1format
_FAIL_MSG2)r   rh   rj   rk   r'   r   r   r   rb      s   rb   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(   rX   _REVEAL_MSGro   )r   rc   rY   rf   r'   r   r   r   test_reveal   s   rr   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   rM   r   sep	importlibutilspec_from_file_locationloadermodule_from_specexec_module)r   Zpath_without_extensionr&   dirnamerG   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 s"w   Y  ||  D ]+}t|\}}||d  d}t	| t
v rJtt||d|vrVt| ||d| q+d S )Nzextended_precision.pyir   r1   rj   zExpression is of type "Any")r   r   r   r>   r   r]   r^   r(   rstripLINENO_MAPPINGr   rX   rq   ro   rb   )r   rY   fZexpression_list_msgr'   r!   rh   r   r   r   test_extended_precision  s"   


r   )r   r   r   r   )r!   r   r   r"   )r)   r*   r   r   )r   r/   )rC   r   r   rJ   )r   r   r   r/   )r   r   rh   r   rj   r   rk   rm   r'   r$   r   r/   );
__future__r   importlib.utilrv   r   r9   r7   collectionsr   typingr   rA   Znumpy.typing.mypy_pluginr   r5   ZRUN_MYPYmarkZskipifZ
pytestmarkZmypyr
   ImportErrorZNO_MYPYcollections.abcr   Z_pytest.mark.structuresr   r   r   r|   __file__ZDATA_DIRr;   r=   r<   r>   r@   r3   listr   __annotations__r    r(   r,   ZfixturerI   rT   ZslowZparametrizerZ   rl   rn   rp   rb   rq   rr   r~   r   r   r   r   r   r   <module>   s    


	

-		#
