zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
U
P±d—=ã @spUddlmZddlZddlZddlZddlZddlZddlm    Z    ddl
m Z ddl m Z mZddlZddlZddlm ZddlmZmZmZzddlmZWnek
r¶dZYnXd    ZerÌdd
lmZej ej  e!¡d ¡Z"ej e"d ¡Z#ej e"d ¡Z$ej e"d¡Z%ej e"d¡Z&ej e"d¡Z'ej e"d¡Z(iZ)de*d<dddœdd„Z+dddœdd„Z,dddœdd„Z-ej.j/ej.j0edd ej1d!dd"d#d$œd%d&„ƒƒƒZ2dd'd(œd)d*„Z3ej.j/ej.j0edd ej. 4d+e3e#ƒ¡d#d$œd,d-„ƒƒƒZ5ej.j/ej.j0edd ej. 4d+e3e$ƒ¡dd#d.œd/d0„ƒƒƒZ6d1Z7d2Z8dddd3d4d#d5œd6d7„Z9d8d$œd9d:„Z:d8d$œd;d<„Z;e;ƒZ<d8e*d=<e< =e:ƒ¡d>d?d@œdAdB„Z>ej.j/ej.j0edd ej. 4d+e3e%ƒ¡dd#d.œdCdD„ƒƒƒZ?dEZ@e AdF¡ZBddddd4d#dGœdHdI„ZCej.j/ej.j0edd ej. 4d+e3e#ƒ¡dd#d.œdJdK„ƒƒƒZDdLdMdNdOdPdQdRdSdTdUdVdWdXœ ZEej.j/ej.j0edd d#d$œdYdZ„ƒƒZFdS)[é)Ú annotationsN)Ú defaultdict)ÚIterator)ÚIOÚ TYPE_CHECKING)Ú_PRECISION_DICTÚ_EXTENDED_PRECISION_LISTÚ_C_INTP)ÚapiTF)Ú ParameterSetÚdataÚpassÚfailÚrevealÚmisczmypy.iniz .mypy_cachezdict[str, list[str]]Ú OUTPUT_MYPYÚstr)ÚkeyÚreturncCs*tj |¡\}}tj || dd¡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Útail©rúUd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/typing/tests/test_typing.pyÚ    _key_func.sr )ÚmsgrcCs tj |¡\}}| dd¡dS)z'Strip the filename from a mypy message.rréÿÿÿÿ)rrrr)r!Ú_rrrrÚ_strip_filename7sr$z re.Match[str])ÚmatchrcCs | ¡dS)z4`re.sub` helper function for stripping module names.r)Úgroups)r%rrrÚ
strip_func=sr'zMypy is not installed)ÚreasonÚmodule)ZscopeZautouseÚNone)rcCsÀtj t¡r(ttj dd¡ƒr(t t¡t    t
t t fD]†}t  dtdt|g¡\}}}|rht d|›¡n|dkr†t d|›d|›¡| d    d
¡}tj| d ¡td }t d d„|Dƒ¡q4dS)zøClears 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 --config-filez --cache-dirz Unexpected mypy standard error
 
>rrzUnexpected mypy exit code: ú
 
Ú*ÚÚ
)rcss"|]\}}|r|t|ƒfVqdS©N)Úlist©Ú.0ÚkÚvrrrÚ    <genexpr>eszrun_mypy.<locals>.<genexpr>N)rrÚisdirÚ    CACHE_DIRÚboolÚenvironÚgetÚshutilÚrmtreeÚPASS_DIRÚ
REVEAL_DIRÚFAIL_DIRÚMISC_DIRr
ÚrunÚMYPY_INIÚpytestrÚreplaceÚ    itertoolsÚgroupbyrr rÚupdate)Ú    directoryÚstdoutÚstderrZ    exit_codeÚiteratorrrrÚrun_mypyBs(
ÿþ
û  rLzIterator[ParameterSet])rHrccsZt |¡D]J\}}}|D]:}tj |¡\}}|dkrtj ||¡}tj||dVqq
dS)N)z.pyiz.py)Úid)rÚwalkrÚsplitextrrCÚparam)rHÚrootr#ÚfilesÚfnameZ short_fnameÚextÚfullpathrrrÚget_test_caseshs rVrcCs8t}||kr4d}|d dd„||Dƒ¡7}t|ƒ‚dS)NzUnexpected mypy output
 
r.css|]}t|ƒVqdSr/)r$)r2r4rrrr5ysztest_success.<locals>.<genexpr>)rrÚAssertionError)rÚ output_mypyr!rrrÚ test_successqs
rY)rrc    CsDd}t|ƒ}| ¡}W5QRXtdd„ƒ}t}||ks<t‚||D]^}t|ƒ dd¡d}t d|¡}|dkr~t    d|›ƒ‚t
|  d    ¡ƒ}|||›d7<qDt |ƒD]’\}    }
|    d}|
  d
¡s¬d |
krØ||krØq¬||d} d | kr$|  d ¡\} } }|| ¡}| ¡}t|| |||ƒq¬t d|›d||›¡q¬dS)NTcSsdS)Nr-rrrrrÚ<lambda>†óztest_fail.<locals>.<lambda>r.rrz"(?P<lineno>\d+): (error|note): .+$zUnexpected error line format: Úlinenoú#z E:z# E:ú  # E: zUnexpected mypy output at line r+)ÚopenÚ    readlinesrrrWr$rÚrer%Ú
ValueErrorÚintÚgroupÚ    enumerateÚ
startswithÚ    partitionÚstripÚ
_test_failrCr)rÚ__tracebackhide__ÚfinÚlinesÚerrorsrXÚ
error_liner%r\ÚiÚlineZ target_lineÚ
expressionr#ÚmarkerÚexpected_errorrrrÚ    test_fail}sD
   þÿþþ 
 ÿrtz9Extra error at line {}
 
Expression: {}
Extra error: {!r}
zTError mismatch at line {}
 
Expression: {}
Expected error: {!r}
Observed error: {!r}
z
None | strrc)rrqÚerrorrsr\rcCs<|dkrtt |||¡ƒ‚n||kr8tt ||||¡ƒ‚dSr/)rWÚ
_FAIL_MSG1ÚformatÚ
_FAIL_MSG2)rrqrursr\rrrri·sÿrizdict[str, str]cCspddddddddd    d
d d d dœ }i}i}| ¡D]:\}}tt|ƒƒ}|jj|jjf}| |d|›¡||<q0|S)NÚc_ubyteÚc_ushortÚc_uintÚc_ulongÚ c_ulonglongÚc_byteÚc_shortÚc_intÚc_longÚ
c_longlongÚc_floatÚc_doubleÚ c_longdouble) ÚubyteÚushortÚuintcÚuintÚ    ulonglongÚbyteÚshortÚintcÚint_ÚlonglongÚsingleÚdoubleÚ
longdoubleúctypes.)ÚitemsÚgetattrÚnpZdtypeÚkindÚitemsizeÚ
setdefault)ÚdctÚretÚvisitedZnp_nameZct_nameZ    np_scalarrrrrÚ_construct_ctypes_dictÆs*ó rc0Cs€dd„t ¡Dƒ}ddddddd    d
d d d ddddddddddddddd|d›dd|d›dd|d ›dd|d!›dd|d"›dd|d#›dd$|d›dd$|d›dd$|d ›dd$|d!›dd$|d"›dd$|d#›dd%|d&›dd%|d'›dd%|d(›dd%|d)›dd*|d'›d+|d'›dd*|d(›d+|d(›dd*|d)›d+|d)›d|d"d,t›d-œ.S).NcSs(i|] \}}| d¡d| dd¡“qS)Ú.r"Únumpyz numpy._typing)rrDr1rrrÚ
<dictcomp>çsÿ z*_construct_format_dict.<locals>.<dictcomp>z*numpy.unsignedinteger[numpy._typing._8Bit]z+numpy.unsignedinteger[numpy._typing._16Bit]z+numpy.unsignedinteger[numpy._typing._32Bit]z+numpy.unsignedinteger[numpy._typing._64Bit]z,numpy.unsignedinteger[numpy._typing._128Bit]z,numpy.unsignedinteger[numpy._typing._256Bit]z(numpy.signedinteger[numpy._typing._8Bit]z)numpy.signedinteger[numpy._typing._16Bit]z)numpy.signedinteger[numpy._typing._32Bit]z)numpy.signedinteger[numpy._typing._64Bit]z*numpy.signedinteger[numpy._typing._128Bit]z*numpy.signedinteger[numpy._typing._256Bit]z$numpy.floating[numpy._typing._16Bit]z$numpy.floating[numpy._typing._32Bit]z$numpy.floating[numpy._typing._64Bit]z$numpy.floating[numpy._typing._80Bit]z$numpy.floating[numpy._typing._96Bit]z%numpy.floating[numpy._typing._128Bit]z%numpy.floating[numpy._typing._256Bit]zAnumpy.complexfloating[numpy._typing._32Bit, numpy._typing._32Bit]zAnumpy.complexfloating[numpy._typing._64Bit, numpy._typing._64Bit]zAnumpy.complexfloating[numpy._typing._80Bit, numpy._typing._80Bit]zAnumpy.complexfloating[numpy._typing._96Bit, numpy._typing._96Bit]zCnumpy.complexfloating[numpy._typing._128Bit, numpy._typing._128Bit]zCnumpy.complexfloating[numpy._typing._256Bit, numpy._typing._256Bit]znumpy.unsignedinteger[Z    _NBitByteú]Z
_NBitShortZ    _NBitIntCZ    _NBitIntPÚ_NBitIntZ _NBitLongLongznumpy.signedinteger[znumpy.floating[Z    _NBitHalfZ _NBitSingleZ _NBitDoubleZ_NBitLongDoubleznumpy.complexfloating[z, r“).Zuint8Zuint16Zuint32Zuint64Úuint128Úuint256Zint8Úint16Úint32Úint64Úint128Úint256Úfloat16Úfloat32Úfloat64Úfloat80Úfloat96Úfloat128Úfloat256Z    complex64Z
complex128Ú
complex160Ú
complex192Ú
complex256Ú
complex512r†r‡rˆZuintpr‰rŠr‹rŒrZintprŽrZhalfrr‘r’ZcsingleZcdoubleZ clongdoubler¢Zc_intp)rr”r    )ršrrrÚ_construct_format_dictæsdÿÁrµÚ FORMAT_DICTzIO[str]z&tuple[npt.NDArray[np.str_], list[str]])Úfilerc    Csp| ¡ dd¡}tjj| d¡ddj\}}}d |¡}tt     
d|¡ƒ}dd    „|Dƒ}|j f|Ž}|| d¡fS)
aExtract 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.r^)Úsepz/nz    \{(.*?)\}c    Ss"i|]}|t |d|›d¡“qS)z<UNRECOGNIZED FORMAT KEY ú>)r¶r:)r2r3rrrr Fsÿz"_parse_reveals.<locals>.<dictcomp>) ÚreadrDr–ÚcharrgrÚTrÚsetraÚfindallrw)    r·ÚstringÚexpression_arrayr#Zcomments_arrayÚcommentsZkey_setÚkwargsZfmt_strrrrÚ_parse_reveals3sÿ
þ rÃc     Cs²d}t|ƒ}t|ƒ\}}W5QRXt}||ks4t‚||D]p}t|ƒ}t d|¡}|dkrjtd|›ƒ‚t|     d¡ƒd}d|ksˆt‚||}    ||}
t
||
|    |d|ƒq<dS)z[Validate that mypy correctly infers the return-types of
    the expressions in `path`.
    Tz(?P<lineno>\d+): note: .+$NúUnexpected reveal line format: r\rzRevealed type is) r_rÃrrWr$rar%rbrcrdÚ _test_reveal) rrjrkrÀZ reveal_listrXrnr%r\rrrqrrrÚ test_revealOs$
  þ rÆzWReveal mismatch at line {}
 
Expression: {}
Expected reveal: {!r}
Observed reveal: {!r}
z (\w+\.)+(\w+))rrqrÚexpected_revealr\rcCs8t t|¡}t t|¡}||kr4tt ||||¡ƒ‚dS)z2Error-reporting helper function for `test_reveal`.N)Ú_STRIP_PATTERNÚsubr'rWÚ _REVEAL_MSGrw)rrqrrÇr\Zstripped_revealZstripped_expected_revealrrrrÅvs  ýÿrÅcCsvtj |¡\}}| tj¡dd…\}}tj |›d|›|¡}|dk    sLt‚|j    dk    sZt‚tj 
|¡}|j      |¡dS)z9Validate that the code in `path` properly during runtime.éþÿÿÿNrž) rrrOrr¸Ú    importlibÚutilÚspec_from_file_locationrWÚloaderÚmodule_from_specÚ exec_module)rZpath_without_extensionr#ÚdirnameÚfilenameÚspecZ test_modulerrrÚtest_code_runs‰s ÿ  rÕr£r¤r¨r©r­r®r¯r°r±r²r³r´) ééééé    é
é é ééééc     Csötj td¡}t}||kst‚t|dƒ}| ¡}W5QRX||D]¬}| d¡^}}}}t    |ƒ}t
|ƒ}    ||    d  d¡}
|  ¡}|dks’t‚t |    tkrÔ|dkr¶td|    ›ƒ‚qðtt |    } t||
| ||    ƒqD|dkrDd    } t||
| ||    ƒqDdS)
Nzextended_precision.pyiÚrrrr.>ruÚnoterurÄzModule has no attribute)rrrr@rrWr_r`rr$rcÚrstriprhÚLINENO_MAPPINGrrbr¶rÅri) rrXÚfZexpression_listÚ_msgr#Z_linenoZmsg_typr!r\rqrrrrrÚtest_extended_precision«s(      rè)GÚ
__future__rZimportlib.utilrÌrErrar;Ú collectionsrÚcollections.abcrÚtypingrrrCrŸr–Z numpy.typingZnptZnumpy.typing.mypy_pluginrrr    Zmypyr
Ú ImportErrorZNO_MYPYZ_pytest.mark.structuresr rrrÒÚ__file__ZDATA_DIRr=r?r>r@rBr7rÚ__annotations__r r$r'ÚmarkZslowZskipifZfixturerLrVZ parametrizerYrtrvrxrirrµr¶rGrÃrÆrÊÚcompilerÈrÅrÕrårèrrrrÚ<module>sž    
       #        ) I 
ô