
    C>qj              
       Z   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                  j                  e d      Z	 d d	lmZ d
Ze	rd dlmZ ej,                  j/                  ej,                  j1                  e      d      Zej,                  j/                  ed      Zej,                  j/                  ed      Zej,                  j/                  ed      Zej,                  j/                  ed      Zej,                  j/                  ed      Zej,                  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jR                  e#   de#fdZ* e
jV                  dd      d+d       Z,de#de!d   fd Z-d!Z.d"Z/d#Z0e
j                  jb                  e
j                  j                  ed$      e
j                  je                  d% e-ee            d+d&                     Z3e
j                  jb                  e
j                  j                  ed$      e
j                  je                  d% e-e            d%e#ddfd'                     Z4e
j                  jk                  d(      e
j                  jb                  e
j                  j                  ed$      e
j                  jk                  d)      e
j                  je                  d% e-e            d%e#ddfd*                                   Z6y# e$ r dZY w xY w),    N)defaultdict)TYPE_CHECKING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_cacheOUTPUT_MYPYkeyreturnc                     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)r   drivetails      ]/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/numpy/typing/tests/test_typing.py	_key_funcr   2   sA    
 ''$$S)KE477<<tzz#q1!455    msgc                     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)r!   _r   linenos       r   _strip_filenamer(   ;   sE    gg  %GAtZZQ'NAvsv;		##r    matchc                 (    | j                         d   S )z4`re.sub` helper function for stripping module names.r   )groups)r)   s    r   
strip_funcr,   B   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| d       n |dvrt%        j&                  d	| 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

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_mypyrL   G   s@    	i  ?FGi JJ01M
Hh?  	$'GG-
 %!	 KK<VHEuMf$KK5i[VHMuU
#d# 
	 A!|$Q<QCr("J""1%1H%,,Z8

	 ! r    directoriesr   c            	      <   g }| D ]  }t        j                  |      D ]z  \  }}}|D ]o  }t         j                  j                  |      \  }}|dvr*t         j                  j	                  ||      }	|j                  t        j                  |	|             q |  |S )N)z.pyiz.py)id)r   walkr   splitextr   rC   rB   param)
rM   
test_casesrE   rootr&   filesfnameshort_fnameextfullpaths
             r   get_test_casesrZ   u   s    J  J	 ggi0 	JND!U J#%77#3#3E#: So-77<<e4!!&,,xK"HIJ	JJ r    z    zR
_______________________________________________________________________________

z{}:{} - reveal mismatch:

{}zMypy is not installedr   c                 N   t         }| |vry t        j                  j                  |       }g }||    D ]H  }t	        |      \  }}|j                  d      j                         }|j                  | d| d|        J |r't        j                  dj                  |      d       y y )Nzerror:r   z - r2   Fpytrace)r   r   r   relpathr(   removeprefixlstriprC   rB   r   r   )r   output_mypyr^   messagesmessager'   contents          r   	test_passre      s    
 K;ggood#G Ht$ ;)'2&&x07797)1VHCy9:;
 DIIh'7 r    c                 r   d}t         }| |vryt        j                  j                  |       }g }||    D ]R  }t	        |      \  }}t        j                  |t              }t        j                  |||      }|j                  |       T |r-t        j                  |      }	t        j                  |	d       yy)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formatrC   	_FAIL_SEPr   rB   r   )
r   __tracebackhide__ra   r^   failures
error_liner'   	error_msgr	   reasonss
             r   test_revealrr      s     K;ggood#G H!$'  
+J7	OOI|<	!((&)D	  ..*GU+ r    zignore::DeprecationWarningz1ignore:numpy.fix is deprecated:DeprecationWarningc                 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   rQ   r   sep	importlibutilspec_from_file_locationloadermodule_from_specexec_module)r   path_without_extensionr&   dirnamerJ   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    )r   N)7importlib.utilrw   r   r:   r8   rg   collectionsr   typingr   rB   r6   RUN_MYPYmarkskipif
pytestmarkmypyr
   NO_MYPYImportError_pytest.mark.structuresr   r   r   r~   __file__DATA_DIRr<   r>   r=   r?   rA   r4   listr   str__annotations__r   tupler$   r(   Matchr,   fixturerL   rZ   ri   rl   rj   slowparametrizere   rr   filterwarningsr    r    r   <module>r      s7    	 	   #   
 '"**4 22H [[L0   
 G 577<<16:77<<&)77<<&)WW\\(H-
77<<&)77<<*-GGLL=1	 ,7t+<[d3i( <63 63 6$ $sCx $bhhsm  
 h-*  .* Z n)=  $	 
 G$;<(!CD8 E = 8( G$;<
!;<,c ,d , = = ,2 89G$;<OP!9:) ) ) ; Q =  :
)Q  Gs   L L*)L*