a :jgr @sUddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl Z ddlmZdejvZeredvrd Ze jje d d Zzdd lmZWneyd ZYn0d Ze rddlmZejejedZejedZ ejedZ!ejedZ"ejedZ#ejedZ$ejedZ%ee&Z'de(d<dddddZ)dddddZ*d dd!d"d#Z+e j,d$d d%d&d'd(d)Z-dd*d+d,d-Z.e jj/e jjed.d e j0d/e.e d&d'd0d1Z1e jj/e jjed.d e j0d/e.e!dd&d2d3d4Z2d5Z3d6Z4dddd7d8d&d9d:d;Z5dZ7e jj/e jjed.d e j0d/e.e dd&d2d?d@Z8dAdBdCdDdEdFdGdHdIdJdKdLdM Z9e jj/e jjed.d d&d'dNdOZ:dS)P) annotationsN) defaultdict)Iterator) TYPE_CHECKING)_EXTENDED_PRECISION_LISTZNPY_RUN_MYPY_IN_TESTSUITE)0falseTz#`NPY_RUN_MYPY_IN_TESTSUITE` not set)reason)apiF) ParameterSetdatapassfailZrevealmisczmypy.iniz .mypy_cachezdefaultdict[str, list[str]] OUTPUT_MYPYstr)keyreturncCs*tj|\}}tj||dddS)zySplit at the first occurrence of the ``:`` character. Windows drive-letters (*e.g.* ``C:``) are ignored herein. :r)ospath splitdrivejoinsplit)rdrivetailrH/usr/local/lib/python3.9/site-packages/numpy/typing/tests/test_typing.py _key_func6sr ztuple[int, str])msgrcCs2tj|\}}|dd\}}}t||fS)z7Strip the filename and line number from a mypy message.r)rrrrintstrip)r!_rlinenorrr_strip_filename?sr'z re.Match[str])matchrcCs |dS)z4`re.sub` helper function for stripping module names.r)groups)r(rrr strip_funcFsr*module)scopeZautouseNone)rcCstjtr(ttjddr(ttt d}t t t tfD]}tdtdt|g\}}}|rrtd|n|dvrtd|d |d }d }|d D]P}d |vrq|d urt|}||d 7}||d urt||d }d }qq>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 ZNUMPY_TYPING_TEST_CLEAR_CACHETz(\s+)?\^(\~+)?z --config-filez --cache-dirz Unexpected mypy standard error >rrzUnexpected mypy exit code:  rN znote:)rrisdir CACHE_DIRboolenvirongetshutilrmtreerecompilePASS_DIR REVEAL_DIRFAIL_DIRMISC_DIRr runMYPY_INIpytestrrr r(rappend)Z split_pattern directorystdoutstderr exit_codeZ str_concatfilenameirrrrun_mypyKs<    rGzIterator[ParameterSet])rArccsZt|D]J\}}}|D]:}tj|\}}|dvrtj||}tj||dVqq dS)N)z.pyiz.py)id)rwalkrsplitextrr?param)rArootr%filesfnameZ short_fnameextfullpathrrrget_test_casesys rQzMypy is not installedrcCs8t}||vr4d}|ddd||D7}t|dS)NzUnexpected mypy output r/css|]}t|dVqdS)rN)r').0vrrr ztest_success..)rrAssertionError)r output_mypyr!rrr test_successs rX)rrcCsd}t|}|}Wdn1s*0Ytdd}t}||vsPJ||D]&}t|\}}|||d7<qXt|D]\}} |d}| dsd| vr||vrq||d} d| vr| d \} } } ||}| } t || | ||qt d |d ||qdS) NTcSsdS)NrrrrrrrUztest_fail..r/r#z E:z# E:z # E: zUnexpected mypy output at line r.) open readlinesrrr' enumerate startswith partitionr$ _test_failr?r)r__tracebackhide__ZfinlineserrorsrW error_liner&rFlineZ target_line expressionr%markerexpected_errorrrr test_fails6 &      riz9Extra error at line {} Expression: {} Extra error: {!r} zRError mismatch at line {} Expression: {} Expected error: {} Observed error: {!r} z None | strr#)rrferrorrhr&rcCs<|durtt|||n||vr8tt||||dS)N)rV _FAIL_MSG1format _FAIL_MSG2)rrfrjrhr&rrrr`s r`zReveal mismatch at line {} {} cCsBd}t}||vrdS||D] }t|\}}tt||qdS)z[Validate that mypy correctly infers the return-types of the expressions in `path`. TN)rr'rV _REVEAL_MSGrl)rrarWrdr&rrr test_reveals  rocCsvtj|\}}|tjdd\}}tj|d||}|dusLJ|jdusZJtj |}|j |dS)z9Validate that the code in `path` properly during runtime.N.) rrrJrsep importlibutilspec_from_file_locationloadermodule_from_spec exec_module)rZpath_without_extensionr%dirnamerEspecZ test_modulerrrtest_code_runss  r{Zuint128Zuint256Zint128Zint256Zfloat80Zfloat96Zfloat128Zfloat256Z complex160Z complex192Z complex256Z complex512) cCstjtd}t}||vsJt|}|}Wdn1sD0Y||D]X}t|\}}||dd}t |t vrt t ||qVd|vrVt|||d|qVdS)Nzextended_precision.pyirr/rjzExpression is of type "Any")rrrr<rr[r\r'rstripLINENO_MAPPINGrrVrnrlr`)rrWfZexpression_listZ_msgr&r!rfrrrtest_extended_precision s  &    r); __future__rimportlib.utilrsrr7r5 collectionsrcollections.abcrtypingrr?Znumpy.typing.mypy_pluginrr3ZRUN_MYPYmarkZskipifZ pytestmarkZmypyr ImportErrorZNO_MYPYZ_pytest.mark.structuresr rrry__file__ZDATA_DIRr9r;r:r<r>r1listr__annotations__r r'r*ZfixturerGrQZslowZ parametrizerXrirkrmr`rnror{rrrrrrs           -  #