
    Bwgt                        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	
      Z	 d dlmZ dZe
rd dlmZ d dlmZ ej6                  j9                  ej6                  j;                  e      d      Zej6                  j9                  ed      Z ej6                  j9                  ed      Z!ej6                  j9                  ed      Z"ej6                  j9                  ed      Z#ej6                  j9                  ed      Z$ej6                  j9                  ed      Z% ee&      Z'de(d<   d7dZ)d8dZ*d9dZ+ ejX                  dd      d:d       Z-d;dZ.ej                   j^                  ej                   j#                  ed
      ej                   ja                  d  e.e             d:d!                     Z1ej                   j^                  ej                   j#                  ed
      ej                   ja                  d  e.e!            d<d"                     Z2d#Z3d$Z4	 	 	 	 	 	 	 	 	 	 	 	 d=d%Z5d&Z6ej                   j^                  ej                   j#                  ed
      ej                   ja                  d  e.e"            d<d'                     Z7ej                   j^                  ej                   j#                  ed
      ej                   ja                  d  e.e             d<d(                     Z8d)d*d+d,d-d.d/d0d1d2d3d4d5Z9ej                   j^                  ej                   j#                  ed
      d:d6              Z:y# e$ r dZY w xY w)>    )annotationsN)defaultdict)TYPE_CHECKING)_EXTENDED_PRECISION_LIST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_cachezdefaultdict[str, list[str]]OUTPUT_MYPYc                    t         j                  j                  |       \  }}t         j                  j                  ||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)keydrivetails      U/var/www/horilla/myenv/lib/python3.12/site-packages/numpy/typing/tests/test_typing.py	_key_funcr!   6   sA    
 ''$$S)KE477<<tzz#q1!455    c                    t         j                  j                  |       \  }}|j                  dd      \  }}} t	        |      | j                         fS )z7Strip the filename and line number from a mypy message.r      )r   r   r   r   intstrip)msg_r   linenos       r    _strip_filenamer*   ?   sE    gg  %GAtZZQ'NAvsv;		##r"   c                (    | j                         d   S )z4`re.sub` helper function for stripping module names.r   )groups)matchs    r    
strip_funcr.   F   s    <<>!r"   module)scopeautousec                    t         j                  j                  t              rBt	        t         j
                  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}|j)                  d      D ]J  }d|v r|t+        |      }|| dz  }| j-                  |      /t.        |   j1                  |       d
}d}L  y)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_mypyrO   K   s<    	i  ?FGi JJ01M
Hh?  	$'GG-
 %!	 KK<VHEFf$KK5i[VHMN
#d# 
	 A!|$Q<QCr("J""1%1H%,,Z8

	 ! r"   c              #    K   t        j                  |       D ]m  \  }}}|D ]b  }t         j                  j                  |      \  }}|dv s*t         j                  j	                  ||      }t        j                  ||       d o y w)N)z.pyiz.py)id)r   walkr   splitextr   rE   param)rH   rootr(   filesfnameshort_fnameextfullpaths           r    get_test_casesr[   y   sy     ''), =a 	=E!ww//6Ko%77<<e4ll8<<		==s   AB	>B	zMypy is not installedr   c                n    t         }| |v r+d}|dj                  d ||    D              z  }t        |      y )NzUnexpected mypy output

r5   c              3  8   K   | ]  }t        |      d      yw)r   N)r*   ).0vs     r    	<genexpr>ztest_success.<locals>.<genexpr>   s     J1+A.Js   )r   r   AssertionError)r   output_mypyr'   s      r    test_successrc      sD    
 K{*tyyJD8IJJJS!! r"   c                0   d}t        |       5 }|j                         }d d d        t        d       }t        }| |v sJ ||    D ]   }t	        |      \  }}||xx   | dz  cc<   " t              D ]  \  }}	|dz   }|	j                  d      sd|	vr||vr%||dz
     }
d|
v rH|
j                  d      \  }}}||   j                         }|j                         }t        | ||||       yt        j                  d	| d
||            y # 1 sw Y   xY w)NTc                      y)Nr	    rf   r"   r    <lambda>ztest_fail.<locals>.<lambda>   s    r"   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errorsrb   
error_liner)   rN   linetarget_line
expressionr(   markererrorexpected_errors                   r    	test_failrz      sF    	d  s  $FK;!$' ,
,Z8
vZL++, U# 4QOOC T!fF&:FQJ'[ $/$9$9)$D!J66N((*E#\\^NtZGKK1&fVn=MN   s   DDz9Extra error at line {}

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

Expression: {}
Expected error: {}
Observed error: {!r}
c                    | t        t        j                  |||            ||vr!t        t        j                  ||||            y )N)ra   
_FAIL_MSG1format
_FAIL_MSG2)r   rv   rx   ry   r)   s        r    rn   rn      sT     Z..vz5IJJ	u	$Z..J
  	 
%r"   zReveal mismatch at line {}

{}
c                    d}t         }| |vry||    D ].  }t        |      \  }}t        t        j	                  ||             y)z[Validate that mypy correctly infers the return-types of
    the expressions in `path`.
    TN)r   r*   ra   _REVEAL_MSGr}   )r   ro   rb   rs   r)   s        r    test_revealr      sW     K;!$' E
,Z8
[//
CDDEr"   c                t   t         j                  j                  |       \  }}| j                  t         j                        dd \  }}t
        j                  j                  | d| |       }|J |j                  J t
        j                  j                  |      }|j                  j                  |       y)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_modules          r    test_code_runsr      s    
 !# 0 0 6A

266*23/GX>>11)1XJD ;;"""..11$7KKKK(r"   uint128uint256int128int256float80float96float128float256
complex160
complex192
complex256
complex512)                                    c                    t         j                  j                  t        d      } t        }| |v sJ t        |       5 }|j                         }d d d        ||    D ]i  }t        |      \  }}|dz
     j                  d      }t        |   t        v rt        t        j                  ||            d|vs[t        | ||d|       k y # 1 sw Y   {xY w)Nzextended_precision.pyir   r5   rx   zExpression is of type "Any")r   r   r   rB   r   ri   rj   r*   rstripLINENO_MAPPINGr   ra   r   r}   rn   )r   rb   fexpression_list_msgr)   r'   rv   s           r    test_extended_precisionr     s     77<<":;DK;	d (q++-( D! 	%d+$VaZ077=
&!%== !3!3FC!@AACj#'Df	( (s   CC)r   strreturnr   )r'   r   r   ztuple[int, str])r-   zre.Match[str]r   r   )r   None)rH   r   r   zIterator[ParameterSet])r   r   r   r   )r   r   rv   r   rx   r   ry   z
None | strr)   r%   r   r   );
__future__r   importlib.utilr   r   r=   r;   collectionsr   typingr   rE   numpy.typing.mypy_pluginr   r9   RUN_MYPYmarkskipif
pytestmarkmypyr   NO_MYPYImportErrorcollections.abcr   _pytest.mark.structuresr   r   r   r   __file__DATA_DIRr?   rA   r@   rB   rD   r7   listr   __annotations__r!   r*   r.   fixturerO   r[   slowparametrizerc   rz   r|   r~   rn   r   r   r   r   r   rf   r"   r    <module>r      s   "  	 	  #    = '"**4 22H [[L0   
 G( 577<<16:77<<&)77<<&)WW\\(H-
77<<&)77<<*-GGLL=1	 ,7t+<( <6$
 h-*  .* Z= G$;<!9:" ; = " G$;<!9:  ; =  F


  	
  
 G$;<
!;<E = = E G$;<!9:) ; = )  	  G$;< = _  Gs   #M9 9NN