o
    i;                     @  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Zd dlm	Z	 d dl
mZ d dlmZmZ d dlZd dlZd dlmZ d dlmZmZmZ zd dlmZ W n eyZ   dZY nw d	Zered 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(i Z)de*d< d]ddZ+d^ddZ,d_ddZ-ej.j/ej.j0ed d!ej1d"dd#d`d%d&Z2dad)d*Z3ej.j/ej.j0ed d!ej.4d+e3e#d`d,d-Z5ej.j/ej.j0ed d!ej.4d+e3e$dbd.d/Z6d0Z7d1Z8dcd8d9Z9ddd;d<Z:ddd=d>Z;e; Z<d:e*d?< e<=e:  dedCdDZ>ej.j/ej.j0ed d!ej.4d+e3e%dbdEdFZ?dGZ@eAdHZBdfdJdKZCej.j/ej.j0ed d!ej.4d+e3e#dbdLdMZDdNdOdPdQdRdSdTdUdVdWdXdYdZZEej.j/ej.j0ed d!d`d[d\ZFdS )g    )annotationsN)defaultdict)Iterator)IOTYPE_CHECKING)_PRECISION_DICT_EXTENDED_PRECISION_LIST_C_INTP)apiTF)ParameterSetdatapassfailrevealmisczmypy.iniz.mypy_cachezdict[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   Y/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/numpy/typing/tests/test_typing.py	_key_func.   s   r    msgc                 C  s    t j| \}}|ddd S )z'Strip the filename from a mypy message.r   r   )r   r   r   r   )r!   _r   r   r   r   _strip_filename7   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_func=   s   r(   zMypy is not installed)reasonmodule)scopeautouseNonec                  C  s   t jtrtt jddrtt t	t
ttfD ]C} tdtdt| g\}}}|r4td|  n|dvrCtd| d|  |d	d
}tj|dtd}tdd |D  q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--config-filez--cache-dirz Unexpected mypy standard error

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

* 
)r   c                 s  s$    | ]\}}|r|t |fV  qd S N)list.0kvr   r   r   	<genexpr>e   s   " zrun_mypy.<locals>.<genexpr>N)r   r   isdir	CACHE_DIRboolenvirongetshutilrmtreePASS_DIR
REVEAL_DIRFAIL_DIRMISC_DIRr
   runMYPY_INIpytestr   replace	itertoolsgroupbyr   r    r   update)	directorystdoutstderr	exit_codeiteratorr   r   r   run_mypyB   s*   

rQ   rL   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   rG   param)rL   rootr#   filesfnameshort_fnameextfullpathr   r   r   get_test_casesh   s   r]   r   c                 C  s8   t }| |v rd}|ddd ||  D 7 }t|d S )NzUnexpected mypy output

r2   c                 s  s    | ]}t |V  qd S r3   )r$   )r6   r8   r   r   r   r9   y   s    ztest_success.<locals>.<genexpr>)r   r   AssertionError)r   output_mypyr!   r   r   r   test_successq   s   r`   c                 C  sV  d}t | }| }W d    n1 sw   Y  tdd }t}| |v s(J ||  D ]/}t|ddd }td|}|d u rItd| t	|
d	}||  | d7  < q,t|D ]H\}	}
|	d }|
d
sud|
vrv||vrvq`||d  }d|v r|d\}}}||  }| }t| |||| q`td| d||   q`d S )NTc                   S  s   dS )Nr1   r   r   r   r   r   <lambda>   s    ztest_fail.<locals>.<lambda>r2   r   r   z"(?P<lineno>\d+): (error|note): .+$zUnexpected error line format: lineno#z E:z# E:  # E: zUnexpected mypy output at line r/   )open	readlinesr   r   r$   r   rer%   
ValueErrorintgroup	enumerate
startswith	partitionstrip
_test_failrG   r   )r   __tracebackhide__finlineserrorsr_   
error_liner%   rb   ilinetarget_line
expressionr#   markerexpected_errorr   r   r   	test_fail}   sB   

r{   z9Extra error at line {}

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

Expression: {}
Expected error: {!r}
Observed error: {!r}
rx   errorrz   
None | strrb   ri   c                 C  s:   |d u rt t|||||vrt t||||d S r3   )r^   
_FAIL_MSG1format
_FAIL_MSG2)r   rx   r|   rz   rb   r   r   r   ro      s   ro   dict[str, str]c                  C  sp   ddddddddd	d
dddd} i }i }|   D ]\}}tt| }|jj|jjf}||d| ||< q|S )Nc_ubytec_ushortc_uintc_ulongc_ulonglongc_bytec_shortc_intc_long
c_longlongc_floatc_doublec_longdouble)ubyteushortuintcuint	ulonglongbyteshortintcint_longlongsingledouble
longdoublectypes.)itemsgetattrnpdtypekinditemsize
setdefault)dctretvisitednp_namect_name	np_scalarr   r   r   r   _construct_ctypes_dict   s*   r   c                  C  s  dd t  D } i ddddddd	d
dddddddddddddddddddddd d!d"d#d$i d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6| d7  d8d9d6| d:  d8d;d6| d<  d8d=d6| d>  d8d?d6| d@  d8dAd6| dB  d8dCdD| d7  d8dEdD| d:  d8dFdD| d<  d8dD| d>  d8dD| d@  d8dD| dB  d8dG| dH  d8dG| dI  d8dG| dJ  d8dG| dK  d8dL| dI  dM| dI  d8dL| dJ  dM| dJ  d8dL| dK  dM| dK  d8| d@ dNt dOS )PNc                 S  s(   i | ]\}}| d d |ddqS ).r"   numpyznumpy._typing)r   rH   r5   r   r   r   
<dictcomp>   s    z*_construct_format_dict.<locals>.<dictcomp>uint8z*numpy.unsignedinteger[numpy._typing._8Bit]uint16z+numpy.unsignedinteger[numpy._typing._16Bit]uint32z+numpy.unsignedinteger[numpy._typing._32Bit]uint64z+numpy.unsignedinteger[numpy._typing._64Bit]uint128z,numpy.unsignedinteger[numpy._typing._128Bit]uint256z,numpy.unsignedinteger[numpy._typing._256Bit]int8z(numpy.signedinteger[numpy._typing._8Bit]int16z)numpy.signedinteger[numpy._typing._16Bit]int32z)numpy.signedinteger[numpy._typing._32Bit]int64z)numpy.signedinteger[numpy._typing._64Bit]int128z*numpy.signedinteger[numpy._typing._128Bit]int256z*numpy.signedinteger[numpy._typing._256Bit]float16z$numpy.floating[numpy._typing._16Bit]float32z$numpy.floating[numpy._typing._32Bit]float64z$numpy.floating[numpy._typing._64Bit]float80z$numpy.floating[numpy._typing._80Bit]float96z$numpy.floating[numpy._typing._96Bit]float128z%numpy.floating[numpy._typing._128Bit]float256z%numpy.floating[numpy._typing._256Bit]	complex64zAnumpy.complexfloating[numpy._typing._32Bit, numpy._typing._32Bit]
complex128zAnumpy.complexfloating[numpy._typing._64Bit, numpy._typing._64Bit]
complex160zAnumpy.complexfloating[numpy._typing._80Bit, numpy._typing._80Bit]
complex192zAnumpy.complexfloating[numpy._typing._96Bit, numpy._typing._96Bit]
complex256zCnumpy.complexfloating[numpy._typing._128Bit, numpy._typing._128Bit]
complex512zCnumpy.complexfloating[numpy._typing._256Bit, numpy._typing._256Bit]r   znumpy.unsignedinteger[	_NBitByte]r   
_NBitShortr   	_NBitIntCuintp	_NBitIntPr   _NBitIntr   _NBitLongLongr   znumpy.signedinteger[r   r   znumpy.floating[	_NBitHalf_NBitSingle_NBitDouble_NBitLongDoubleznumpy.complexfloating[z, r   )intpr   r   halfr   r   r   csinglecdoubleclongdoubler   c_intp)r   r   r	   )r   r   r   r   _construct_format_dict   s   	
!"#$%&'()*r   FORMAT_DICTfileIO[str]&tuple[npt.NDArray[np.str_], list[str]]c           	      C  st   |   dd}tjj|dddj\}}}d|}tt	
d|}dd	 |D }|jdi |}||dfS )a  Extract and parse all ``"  # E: "`` comments from the passed
    file-like object.

    All format keys will be substituted for their respective value
    from `FORMAT_DICT`, *e.g.* ``"{float64}"`` becomes
    ``"numpy.floating[numpy._typing._64Bit]"``.
    r0   r1   r2   rd   )sepz/nz	\{(.*?)\}c              	   S  s"   i | ]}|t |d |dqS )z<UNRECOGNIZED FORMAT KEY >)r   r>   )r6   r7   r   r   r   r   F  s    z"_parse_reveals.<locals>.<dictcomp>Nr   )readrH   r   charrm   r   Tr   setrg   findallr   )	r   stringexpression_arrayr#   comments_arraycommentskey_setkwargsfmt_strr   r   r   _parse_reveals3  s   

r   c                 C  s   d}t | }t|\}}W d   n1 sw   Y  t}| |v s$J ||  D ]8}t|}td|}|du r?td| t|dd }d|v sNJ || }	|| }
t	| |
|	|d|  q(dS )z[Validate that mypy correctly infers the return-types of
    the expressions in `path`.
    TNz(?P<lineno>\d+): note: .+$Unexpected reveal line format: rb   r   zRevealed type is)
re   r   r   r$   rg   r%   rh   ri   rj   _test_reveal)r   rp   rq   r   reveal_listr_   rt   r%   rb   ry   rx   r   r   r   test_revealO  s(   
r   zWReveal mismatch at line {}

Expression: {}
Expected reveal: {!r}
Observed reveal: {!r}
z(\w+\.)+(\w+)expected_revealc                 C  s8   t t|}t t|}||vrtt||||dS )z2Error-reporting helper function for `test_reveal`.N)_STRIP_PATTERNsubr(   r^   _REVEAL_MSGr   )r   rx   r   r   rb   stripped_revealstripped_expected_revealr   r   r   r   v  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.Nr   )r   r   rU   r   r   	importlibutilspec_from_file_locationloadermodule_from_specexec_module)r   path_without_extensionr#   dirnamefilenamespectest_moduler   r   r   test_code_runs  s   r  r   r   r   r   r   r   r   r   r   r   r   r   )            	   
                     c                  C  s  t jtd} t}| |v sJ t| d}| }W d    n1 s#w   Y  ||  D ]U}|d^ }}}}t|}t	|}	||	d  
d}
| }|dv sSJ t|	 tv rs|dkrdtd|	 tt|	  }t| |
|||	 q,|dkrd	}t| |
|||	 q,d S )
Nzextended_precision.pyirr   r   r2   >   noter|   r|   r   zModule has no attribute)r   r   r   rD   r   re   rf   r   r$   ri   rstriprn   LINENO_MAPPINGr   rh   r   r   ro   )r   r_   fexpression_list_msgr#   _linenomsg_typr!   rb   rx   ry   r   r   r   test_extended_precision  s.   
r  )r   r   r   r   )r!   r   r   r   )r%   r&   r   r   )r   r-   )rL   r   r   rR   )r   r   r   r-   )r   r   rx   r   r|   r   rz   r}   rb   ri   r   r-   )r   r   )r   r   r   r   )r   r   rx   r   r   r   r   r   rb   ri   r   r-   )G
__future__r   importlib.utilr   rI   r   rg   r?   collectionsr   collections.abcr   typingr   r   rG   r   r   numpy.typingnptnumpy.typing.mypy_pluginr   r   r	   mypyr
   ImportErrorNO_MYPY_pytest.mark.structuresr   r   r   r   __file__DATA_DIRrA   rC   rB   rD   rF   r;   r   __annotations__r    r$   r(   markslowskipiffixturerQ   r]   parametrizer`   r{   r~   r   ro   r   r   r   rK   r   r   r   compiler   r   r  r  r  r   r   r   r   <module>   s    

	

#		)


 I


