
    Dg'"                    6   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                            e d
          Zdej        v Zeredvrd	Zej                            e d
          Z	 d dlmZ dZn# e$ r d	ZY nw xY w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<   dGdZ)dHdZ*dId!Z+ ej,        d"d	#          dJd%            Z-dKd(Z.ej        j/        ej                            ed)          ej        0                    d* e.e                     dJd+                                    Z1ej        j/        ej                            ed)          ej        0                    d* e.e!                    dLd,                                    Z2d-Z3d.Z4dMd5Z5d6Z6ej        j/        ej                            ed)          ej        0                    d* e.e"                    dLd7                                    Z7ej        j/        ej                            ed)          ej        0                    d* e.e                     dLd8                                    Z8d9d:d;d<d=d>d?d@dAdBdCdDdEZ9ej        j/        ej                            ed)          dJdF                        Z:dS )N    )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                    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tails      S/var/www/sysmax/venv/lib/python3.11/site-packages/numpy/typing/tests/test_typing.py	_key_funcr#   D   sF    
 '$$S))KE47<<tzz#q11!4555    msgtuple[int, str]c                    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!   linenos       r"   _strip_filenamer-   M   sM    g  %%GAtZZQ''NAvsv;;		##r$   matchre.Match[str]c                6    |                                  d         S )z4`re.sub` helper function for stripping module names.r   )groups)r.   s    r"   
strip_funcr2   T   s    <<>>!r$   module)scopeautouseNonec                    t           j                            t                    rFt	          t           j                            dd                    rt          j        t                     t          j
        d          } t          t          t          t          fD ]}t          j        dt"          dt          |g          \  }}}|rt%          j        d|            n|dvrt%          j        d| d	|            d
}d}|                    d          D ]Y}d|v r|t+          |          }|| dz  }|                     |          $t.          |                             |           d
}d}Zd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is           r"   run_mypyrT   Y   s    	i  ! ?FFGG! 	i   J011M
Hh?    	$'G-
 % %!	  	OKEVEEFFFFf$$KMiMMVMMNNN
#d## 
	  
	 A!||$Q<<Q((("J""1%%1H%,,Z888

	 !   r$   rM   Iterator[ParameterSet]c              #    K   t          j        |           D ]i\  }}}|D ]`}t           j                            |          \  }}|dv r8t           j                            ||          }t          j        ||          V  ajd S )N)z.pyiz.py)id)r   walkr   splitextr   rJ   param)rM   rootr+   filesfnameshort_fnameextfullpaths           r"   get_test_casesra      s      '),, = =a 	= 	=E!w//66Ko%%7<<e44l8<<<<<<		== =r$   zMypy is not installedr   c                    t           }| |v r9d}|d                    d ||          D                       z  }t          |          d S )NzUnexpected mypy output

r:   c              3  @   K   | ]}t          |          d          V  dS )r   N)r-   ).0vs     r"   	<genexpr>ztest_success.<locals>.<genexpr>   s/      JJ1++A.JJJJJJr$   )r   r   AssertionError)r   output_mypyr%   s      r"   test_successri      sY    
 K{*tyyJJD8IJJJJJJS!!! r$   c                   d}t          |           5 }|                                }d d d            n# 1 swxY w Y   t          d           }t          }| |v sJ ||          D ]'}t	          |          \  }}||xx         | dz  cc<   (t          |          D ]\  }}	|dz   }|	                    d          sd|	vr||vr(||dz
           }
d|
v r[|
                    d          \  }}}||                                         }|                                }t          | ||||           t          j        d	| d
||                     d S )NTc                     dS )Nr
    rl   r$   r"   <lambda>ztest_fail.<locals>.<lambda>   s     r$   r:   r   #z E:z# E:z  # E: zUnexpected mypy output at line r9   )open	readlinesr   r   r-   	enumerate
startswith	partitionr*   
_test_failrJ   r   )r   __tracebackhide__finlineserrorsrh   
error_liner,   rS   linetarget_line
expressionr+   markerexpected_errors                  r"   	test_failr      s    	d  s                              $$FK;!$' , ,
,Z88
vZ++++U##  4QOOC  	T!!fF&:&:FQJ'[  $/$9$9)$D$D!J6#F^1133N\\^^FtZHHHHKN&NNfVnNN    s   377z9Extra error at line {}

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

Expression: {}
Expected error: {}
Observed error: {!r}
r|   errorr~   
None | strr,   r)   c                    |)t          t                              |||                    ||vr*t          t                              ||||                    d S )N)rg   
_FAIL_MSG1format
_FAIL_MSG2)r   r|   r   r~   r,   s        r"   rt   rt      sj     Z..vz5IIJJJ	n	$	$Z..J
 
   	 
%	$r$   zReveal mismatch at line {}

{}
c                    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-   rg   _REVEAL_MSGr   )r   ru   rh   ry   r,   s        r"   test_revealr      sq     K;!$' E E
,Z88
[//
CCDDDE Er$   c                t   t           j                            |           \  }}|                     t           j                  dd         \  }}t
          j                            | d| |           }|J |j        J t
          j        	                    |          }|j        
                    |           dS )z9Validate that the code in `path` properly during runtime.N.)r   r   rY   r   sep	importlibutilspec_from_file_locationloadermodule_from_specexec_module)r   path_without_extensionr+   dirnamerR   spectest_modules          r"   test_code_runsr      s    
 !# 0 0 6 6A

26**233/GX>11X D ;""".11$77KKK(((((r$   uint128uint256int128int256float80float96float128float256
complex160
complex192
complex256
complex512)                                    c                    t           j                            t          d          } t          }| |v sJ t          |           5 }|                                }d d d            n# 1 swxY w Y   ||          D ]}t          |          \  }}||dz
                               d          }t          |         t          v r(t          t                              ||                    d|vrt          | ||d|           d S )Nzextended_precision.pyir   r:   r   zExpression is of type "Any")r   r   r   rG   r   ro   rp   r-   rstripLINENO_MAPPINGr   rg   r   r   rt   )r   rh   fexpression_list_msgr,   r%   r|   s           r"   test_extended_precisionr     sA    7<<":;;DK;	d (q++--( ( ( ( ( ( ( ( ( ( ( ( ( ( ( D! 	 	%d++$VaZ077==
&!%=== !3!3FC!@!@AAACj#'Df  	 	s   A##A'*A')r   r   r   r   )r%   r   r   r&   )r.   r/   r   r   )r   r6   )rM   r   r   rU   )r   r   r   r6   )r   r   r|   r   r   r   r~   r   r,   r)   r   r6   );
__future__r   importlib.utilr   r   rB   r@   collectionsr   collections.abcr   typingr   rJ   numpy.typing.mypy_pluginr   r>   RUN_MYPYmarkskipif
pytestmarkmypyr   NO_MYPYImportError_pytest.mark.structuresr   r   r   r   __file__DATA_DIRrD   rF   rE   rG   rI   r<   listr   __annotations__r#   r-   r2   fixturerT   ra   slowparametrizeri   r   r   r   rt   r   r   r   r   r   rl   r$   r"   <module>r      s8   " " " " " " "     				 				  # # # # # # $ $ $ $ $ $              = = = = = = '"*4  222H [L0    
 '"*4  222H [L0    
 GG    GGG
  5 5444447<<116::7<<&))7<<&))W\\(H--
7<<&))7<<*--GLL=11	 ,7;t+<+< < < < <6 6 6 6$ $ $ $   
 h---*  *  *  .-* Z= = = = G$;<<!9!9::" " " ;: =< " G$;<<!9!9::      ;: =<  F

    G$;<<
!;!;<<E E E =< =< E G$;<<!9!9::) ) ) ;: =< )  	   G$;<<   =<   s   B B$#B$