
    	i              	          U 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
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 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$ee%e#e%         f         e&d<   de%de%fdZ'de%de(e)e%f         fdZ*dej+        e%         de%fdZ, e
j-        dd          d*d            Z.de%dd fd!Z/d"Z0d#Z1d$Z2e
j        j3        e
j                            ed%          e
j        4                    d& e/ee                    d*d'                                    Z5e
j        j3        e
j                            ed%          e
j        4                    d& e/e                    d&e%ddfd(                                    Z6e
j        j3        e
j                            ed%          e
j        4                    d& e/e                    d&e%ddfd)                                    Z7dS )+    N)defaultdict)TYPE_CHECKINGNPY_RUN_MYPY_IN_TESTSUITE)0 falseTz#`NPY_RUN_MYPY_IN_TESTSUITE` not set)reason)apiF)Iterator)ParameterSetdatapassfailrevealmisczmypy.iniz.mypy_cacheOUTPUT_MYPYkey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      V/srv/django_bis/venv311/lib/python3.11/site-packages/numpy/typing/tests/test_typing.py	_key_funcr    4   sF    
 '$$S))KE47<<tzz#q11!4555    msgc                     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)   =   sM    g  %%GAtZZQ''NAvsv;;		##r!   matchc                 6    |                                  d         S )z4`re.sub` helper function for stripping module names.r   )groups)r*   s    r   
strip_funcr-   D   s    <<>>!r!   module)scopeautousec                     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| d           n|dvrt%          j        d	| 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

F>   r   r   zUnexpected mypy exit code: z

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_mypyrM   I   s    	i  ! ?FFGG! 	i   J011M
Hh?    	$'G-
 % %!	  	VKEVEEuMMMMf$$KMiMMVMMuUUU
#d## 
	  
	 A!||$Q<<Q((("J""1%%1H%,,Z888

	 !   r!   directorieszIterator[ParameterSet]c               '     K   | D ]}t          j        |          D ]j\  }}}|D ]a}t           j                            |          \  }}|dvr)t           j                            ||          }t          j        ||          V  bkd S )N)z.pyiz.py)id)r   walkr   splitextr   rC   param)	rN   rF   rootr'   filesfnameshort_fnameextfullpaths	            r   get_test_casesrZ   w   s        = =	 gi00 	= 	=ND!U = =#%7#3#3E#:#: So--7<<e44l8<<<<<<<=	== =r!   z    zR
_______________________________________________________________________________

z{}:{} - reveal mismatch:

{}zMypy is not installedr   c                 ~   t           }| |vrd S t          j                            |           }g }||          D ]X}t	          |          \  }}|                    d                                          }|                    | d| d|            Y|r+t          j	        d
                    |          d           d S d S )Nzerror:r   z - r3   Fpytrace)r   r   r   relpathr)   removeprefixlstriprD   rC   r   r   )r   output_mypyr^   messagesmessager(   contents          r   	test_passre      s    
 K;good##G Ht$ ; ;)'22&&x007799799V9999:::: 8DIIh''7777778 8r!   c                    d}t           }| |vrdS t          j                            |           }g }||          D ]_}t	          |          \  }}t          j        |t                    }t          	                    |||          }|
                    |           `|r2t                              |          }	t          j        |	d           dS dS )z[Validate that mypy correctly infers the return-types of
    the expressions in `path`.
    TNFr\   )r   r   r   r^   r)   textwrapindent_FAIL_INDENT_FAIL_MSG_REVEALformatrD   	_FAIL_SEPr   rC   r   )
r   __tracebackhide__ra   r^   failures
error_liner(   	error_msgr	   reasonss
             r   test_revealrr      s     K;good##G H!$'    
+J77	OI|<<	!((&)DD ,..**GU++++++, ,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   rR   r   sep	importlibutilspec_from_file_locationloadermodule_from_specexec_module)r   path_without_extensionr'   dirnamerK   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!   )r   N)8importlib.utilrw   r   r;   r9   rg   collectionsr   typingr   rC   r7   RUN_MYPYmarkskipif
pytestmarkmypyr
   NO_MYPYImportErrorcollections.abcr   _pytest.mark.structuresr   r   r   r~   __file__DATA_DIRr=   r?   r>   r@   rB   r5   listr   str__annotations__r    tupler%   r)   Matchr-   fixturerM   rZ   ri   rl   rj   slowparametrizere   rr   r    r!   r   <module>r      sB        				 				   # # # # # #             
 '"*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+<+<[d3i( < < <63 63 6 6 6 6$ $sCx $ $ $ $bhsm     
 h---*  *  *  .-* Z	= 	=)A 	= 	= 	= 	= $	 
 G$;<<(!C!CDD8 8 8 ED =< 8( G$;<<
!;!;<<,c ,d , , , =< =< ,2 G$;<<!9!9::) ) ) ) ) ;: =< ) ) )s   A A('A(