o 6aD/ @sUddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z ddl Z ddlZddlmZmZzddlmZWn eyJdZYnwdZejejedZejed Zejed Zejed Zejed Zejed Z ejedZ!iZ"e e#e e#fe$d<de#de#fddZ%de#de#fddZ&e j'j(e j'j)edde j*ddddHddZ+ddZ,e j'j(e j'j)edde j'-de,ed d!Z.e j'j(e j'j)edde j'-de,ed"d#Z/d$Z0d%Z1de#d&e#d'e e#d(e2ddf d)d*Z3d+d,Z4e4Z5e e#e#fe$d-<d.e e#de e#fd/d0Z6e j'j(e j'j)edde j'-de,ed1d2Z7d3Z8de#d e#d4e#d(e2ddf d5d6Z9e j'j(e j'j)edde j'-de,ed7d8Z:d9d:d;dd?d@dAdBdCdDdE Z;e j'j(e j'j)edddHdFdGZrrzUnexpected mypy exit code: z * )rcss$|] \}}|r|t|fVqdSN)list.0kvrrr Qs"zrun_mypy..N)rrisdir CACHE_DIRboolenvirongetshutilrmtreePASS_DIR REVEAL_DIRFAIL_DIRMISC_DIRr runMYPY_INIpytestr replace itertoolsgroupbyrrrupdate) directorystdoutstderr exit_codeiteratorrrrrun_mypy1s$   rHccsht|D]+\}}}|D]#}tj|ddkr0tj||}tjj||d}tj||dVq qdS)Nrz.py)start)id)rwalkrsplitextrrelpathr>param)rCrootr filesfnamefullpathrMrrrget_test_casesTsrSrcCs8t}||vrd}|ddd||D7}t|dS)NUnexpected mypy output r)css|]}t|VqdSr*)r!)r-r/rrrr0ksztest_success..)rrAssertionError)r output_mypyrrrr test_successcs rWcCs:d}t| }|}Wdn1swYtdd}t}||vs(J||D])}t|}td|}|durCtd|t| d}|||d7<q,t |D]@\} } | d}| d sod | vrp||vrpqZ||d} d | vr| d d  } ||} t|| | |qZtd ||qZdS)NTcSsdS)Nr(rrrrrxsztest_fail..z"(?P\d+): (error|note): .+$zUnexpected error line format: linenor)r#z E:z# E:rrT)open readlinesrrr!rematch ValueErrorintgroup enumerate startswithrstripr5 _test_failr>r )r__tracebackhide__finlineserrorsrV error_liner^rYiline target_linemarkerexpected_errorrrr test_failos8       rpz*Extra error at line {} Extra error: {!r} zEError mismatch at line {} Expected error: {!r} Observed error: {!r} errorrorYcCs6|dur tt||||vrtt|||dSr*)rU _FAIL_MSG1format _FAIL_MSG2)rrqrorYrrrres recCsddtD}iddddddd d d d d ddddddddddddddddddd d!d"d#d$id%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6|d7d8d9d6|d:d8d;d6|d<d8d=d6|d>d8d?d6|d@d8dAd6|dBd8dCdD|d7d8dEdD|d:d8dFdD|d<d8dD|d>d8dD|d@d8dD|dBd8dG|dHd8dG|dId8dG|dJd8dG|dKd8dL|dIdM|dId8dL|dJdM|dJd8dL|dKdM|dKd8|d@dN S)ONcSs(i|]\}}|dd|ddqS).rnumpyz numpy.typing)rr?r,rrr sz*_construct_format_dict..uint8z)numpy.unsignedinteger[numpy.typing._8Bit]uint16z*numpy.unsignedinteger[numpy.typing._16Bit]uint32z*numpy.unsignedinteger[numpy.typing._32Bit]uint64z*numpy.unsignedinteger[numpy.typing._64Bit]uint128z+numpy.unsignedinteger[numpy.typing._128Bit]uint256z+numpy.unsignedinteger[numpy.typing._256Bit]int8z'numpy.signedinteger[numpy.typing._8Bit]int16z(numpy.signedinteger[numpy.typing._16Bit]int32z(numpy.signedinteger[numpy.typing._32Bit]int64z(numpy.signedinteger[numpy.typing._64Bit]int128z)numpy.signedinteger[numpy.typing._128Bit]int256z)numpy.signedinteger[numpy.typing._256Bit]float16z#numpy.floating[numpy.typing._16Bit]float32z#numpy.floating[numpy.typing._32Bit]float64z#numpy.floating[numpy.typing._64Bit]float80z#numpy.floating[numpy.typing._80Bit]float96z#numpy.floating[numpy.typing._96Bit]float128z$numpy.floating[numpy.typing._128Bit]float256z$numpy.floating[numpy.typing._256Bit] complex64z?numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit] complex128z?numpy.complexfloating[numpy.typing._64Bit, numpy.typing._64Bit] complex160z?numpy.complexfloating[numpy.typing._80Bit, numpy.typing._80Bit] complex192z?numpy.complexfloating[numpy.typing._96Bit, numpy.typing._96Bit] complex256zAnumpy.complexfloating[numpy.typing._128Bit, numpy.typing._128Bit] complex512zAnumpy.complexfloating[numpy.typing._256Bit, numpy.typing._256Bit]ubyteznumpy.unsignedinteger[ _NBitByte]ushort _NBitShortuintc _NBitIntCuintp _NBitIntPuint_NBitInt ulonglong _NBitLongLongbyteznumpy.signedinteger[shortintcznumpy.floating[ _NBitHalf _NBitSingle _NBitDouble_NBitLongDoubleznumpy.complexfloating[z, ) intpint_longlonghalfsingledouble longdoublecsinglecdouble clongdoubler)ritems)dctrrr_construct_format_dicts      !"#$r FORMAT_DICTfilecCst|dd}tjj|ddddddf}d|}tt d |}d d |D}|j d i|}|dS) zExtract and parse all ``" # E: "`` comments from the passed file-like object. All format keys will be substituted for their respective value from `FORMAT_DICT`, *e.g.* ``"{float64}"`` becomes ``"numpy.floating[numpy.typing._64Bit]"``. r'r(r)z # E: )sepNz/nz \{(.*?)\}c Ss"i|] }|t|d|dqS)z)rr5)r-r.rrrrwsz"_parse_reveals..r) readr?npchar partitionrrsetr]findallrs)rstringcomments_arraycommentskey_setkwargsfmt_strrrr_parse_revealss"  rc Csd}t| }t|}Wdn1swYt}||vs"J||D]3}t|}td|}|dur=td|t|dd}d|vsLJ||}t |||d|q&dS)NTz(?P\d+): note: .+$Unexpected reveal line format: rYrzRevealed type is) r[rrr!r]r^r_r`ra _test_reveal) rrfrgrhrVrjr^rYrnrrr test_reveals&     rzHReveal mismatch at line {} Expected reveal: {!r} Observed reveal: {!r} expected_revealcCs||vr tt|||dSr*)rU _REVEAL_MSGrs)rr rrYrrrrsrcCs\tj|\}}|tjdd\}}tj|d||}tj|}|j |dS)Nru) rrrLrr importlibutilspec_from_file_locationmodule_from_specloader exec_module)rpath_without_extensionr dirnamefilenamespec test_modulerrrtest_code_runs#s  rr|r}rrrrrrrrrr)  c Cstjtd}t}||vsJ||D]J}|d^}}}}t|}t|}|}|dvs1Jt |t vrP|dkrBt d|t t |}t ||||q|dkr]d}t||||qdS)Nzextended_precision.pyr>noterqrqrzModule has no attribute)rrrr;rrr!r`rdLINENO_MAPPINGrr_rrre) rrV_msgr _linenomsg_typrrYrnrrrtest_extended_precision>s&     r)rN)=importlib.utilrr@rr]r6 collectionsrtypingrrrrr>rvrnumpy.typing.mypy_pluginrrmypyr ImportErrorNO_MYPYrrr__file__DATA_DIRr8r:r9r;r=r2rstr__annotations__rr!markslowskipiffixturerHrS parametrizerWrprrrtr`rerrrrrrrrrrrrrs       #";