ML ispUdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z mZmZddlmZddlmZmZmZmZmZmZded< ddlZ ddlZddlZd Zed Z e!ejDd d z Z#ded<ejHdZ%ded<dZ&ded<dZ'ded<dZ(ded<dZ)ded<dZ*ded<e+dZ,ded<d[d\dZ-d]dZ.d^d Z/d_d!Z0d`d"Z1dad#Z2dbd$Z3dcd%Z4Gd&d'e5Z6ddd(Z7ded)Z8dfd*Z9dgd+Z:d,Z;ded-<d.Zded3<d4Z?ded5< dhd6Z@ did7ZAGd8d9ZBdjd:ZC dkd;ZDiZEdZF dm dnd?ZGdod@ZHe jdAk(se jdBk(rdpdCZJndqdDZJdrdsdEZKdtdFZLdudGZMdvdHZNdwdIZOdxdJZPdydKZQdrdzdLZRd{dMZSd|dNZTd}dOZUGdPdQZVd~dRZWd~dSZXddTZYddUZZe jZ\ddVZ]ddWZ^ddXZ_d[ddYZ`ddZZay#e$rdZYwxYw#e$rd ZYwxYw)z3Utility functions with no non-trivial dependencies.) annotationsN) ContainerIterableSequenceSized) resources)IOAnyCallableFinalLiteralTypeVarr orjsonTFTmypytypeshedr TYPESHED_DIRs=([ \t\v]*#.*(\r\n?|\n))??[ \t\v]*#.*coding[:=][ \t]*([-\w.]+) ENCODING_REDEFAULT_SOURCE_OFFSETPDEFAULT_COLUMNS MINIMUM_WIDTH MINIMUM_WINDOWS_MAJOR_VT100iZ)MINIMUM_WINDOWS_BUILD_VT100)__init____new____call____init_subclass____class_getitem__SPECIAL_DUNDERSc`|r |tvry|jdxr|jdS)zReturns whether name is a dunder name. Args: exclude_special: Whether to return False for a couple special dunder methods. F__)r# startswithendswith)nameexclude_specials O/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/util.py is_dunderr+8s.4?2 ??4 8T]]4%88ctt| xr+|jdxr|jdxr|dk7SN_)r+r&r'r(s r* is_sunderr1Ds7  ^4??3#7 ^DMM# remaining componentss r*r<r<\sgI  W 388I.. .]]3* z?a AJqM* r,cv|ytt|}|jddjdS)zReturn the last component of the type name of an object. If obj is None, return 'nil'. For example, if obj is 1, return 'int'. nilr3z'>)strtypesplitrstrip)objts r* short_typerPhs7  { DIA 773<  " "4 ((r,ctj|}|rQ|jdrdnd}|jdjd}|j ds|dk(rd}||fSd}|d fS) z*PEP-263 for detecting Python file encodingr4ascii)z iso-latin-1-zlatin-1-z iso-latin-1zlatin-1utf8rI)rmatchgroupdecoder&)textr?lineencodingdefault_encodings r*find_python_encodingr]sst   t $F LLOq<<?))'2   ; <M@Y H~!##r,ct|ddS)a2Converts bytes into some human-readable representation. Unprintable bytes such as the nul byte are escaped. For example: >>> b = bytes([102, 111, 111, 10, 0]) >>> s = bytes_to_human_readable_repr(b) >>> print(s) foo >>> print(repr(s)) 'foo\n\x00' rRrI)repr)bs r*bytes_to_human_readable_reprras 71R=r,ceZdZdZy) DecodeErrorzException raised when a file cannot be decoded due to an unknown encoding type. Essentially a wrapper for the LookupError raised by `bytearray.decode` N)__name__ __module__ __qualname____doc__r,r*rcrcsr,rcc|jdrd}|dd}nt|\}} |j|}|S#t$r}t t ||d}~wwxYw)zmRead the Python file with while obeying PEP-263 encoding detection. Returns the source as a string. srUrSN)r&r]rX LookupErrorrcrJ)sourcer[r/ source_text lookuperrs r*decode_python_encodingrnsp )+62 !9mmH-   9#i.)y89s< AAAc ||} t|j}|S#t$rYywxYw#t$rYywxYw)zaTry reading a Python file as list of source lines. Return None if something goes wrong. N)rn splitlinesrcOSError)pathreadrk source_liness r* read_py_filerusW d 1&9DDFL   s5& 22 AAc|d|zdzkrd|zdz}t||kr|dfS||z|kr |d|dzdfS|t||z dz kr!||z |zdz}d||||zdzzdz|dz fSd|| dzt||z dz fS)aTrim a line of source code to fit into max_len. Show 'min_width' characters on each side of 'col' (an error location). If either start or end is trimmed, this is indicated by adding '...' there. A typical result looks like this: ...some_variable = function_to_call(one_arg, other_arg) or... Return the trimmed string and the column offset to adjust error location. rRr4rN...rS)rC)rZmax_lencol min_widthoffsets r*trim_source_liner|sY""i-!# 4yGQw Y HW~%q(( SY "Q &&w*Q.tFS9_q%899EA6A:MM 4 ? "CI$7!$; ;;r,cd}||vrgS|jd}g}t|D]9\}}|j|s|j|dz|t |df;|S)Nz# mypy:  r4)rL enumerater&r6rC)rkPREFIXlinesresultsirZs r*get_mypy_commentsrsr F V LL EGU#94 ??6 " NNAE4F #67 89 Nr,z JUNIT_HEADER_TEMPLATEz {text} JUNIT_TESTCASE_FAIL_TEMPLATEz {text} JUNIT_ERROR_TEMPLATEzr JUNIT_TESTCASE_PASS_TEMPLATEz JUNIT_FOOTERc ddlm}|rd}t|}n t|}d}tj |||t|xsd}|s|t j |||z }n|j D]\} } | D|tj |dj| | |dj |||  z }L|tj |dj| d |d |d | z }|tz }|S) Nr)escaper4)errorsfailurestimetests)rverplatformr~z"mypy-py{ver}-{platform} {filename})rrfilename)rYrrr(rzmypy-py-) xml.sax.saxutilsrrCrformatritemsrrBr) dtseriousmessages_by_fileversionrrrrxmlrmessagess r*_generate_junit_contentsrsB(%&'(  & & "#(q ' C  +22RZ2[["2"8"8":  Hh#3:: ( 34%=DD#hE ;3:: ( 34#"7)1XJ7 ; $<C Jr,cJt|||||}tjjtjj |}tj |dt |d5}|j|jddddy#1swYyxYw)NT)exist_okwbutf-8) rosrrdirnameabspathmakedirsopenwriteencode) rrrrrrrrxml_dirsfs r*write_junit_xmlr2s| #2w0@'8 TCwwrwwt45HKK4( dD %Q  7#$%%%s /!BB"c eZdZdZddZddZy)IdMapperzGenerate integer ids for objects. Unlike id(), these start from 0 and increment by 1, and ids won't get reused across the life-time of IdMapper. Assume objects don't redefine __eq__ or __hash__. c i|_d|_yr;id_mapnext_idselfs r*rzIdMapper.__init__Ms)+  r,c||jvr.|j|j|<|xjdz c_|j|S)Nr4r)ros r*idz IdMapper.idQs; DKK !\\DKKN LLA L{{1~r,N)returnNone)robjectrint)rdrerfrgrrrhr,r*rrDsr,rc,|jdddS)zBDrop the final component of a qualified name (e.g. ('x.y' -> 'x').r3r4r)r5)fullnames r* get_prefixrXs ??3 "1 %%r,c|dk(r|dfS|jd}|}|r|dz}t||k\}|dk7rdj|d| }||r d|zz|fSdz|fS)NrTr3r4)rLrCrB) cur_mod_idrelativer>is_cur_package_init_filepartsreloks r*correct_relative_importr]s1}t|   S !E C q Us B axXXeEcTl+ 6#, :B >>r :B >>r,z$Final[dict[type[object], list[str]]] fields_cachecddl|tvr=j|fd}|Dcgc]\}}|dk7s |dk7s|c}}t|<t|Scc}}w)NrcLj|xsj|SN)isgetsetdescriptorismemberdescriptor)rinspects r*z'get_class_descriptors..vs#755a8YG !r,cBtjj||Sr)rrrrB)aps r*rrsww||Aq!!r,ctjjtjjt j |y)zKill the current process without fully cleaning up. This can be quite a bit faster than a normal exit() since objects are not freed. N)sysstdoutflushstderrr_exit)statuss r* hard_exitrs0 JJJJHHVr,c$|jdS)z+Remove internal suffixes from a short name.')rMr0s r*unmanglers ;;s r,c|dz}||vr|Sd}|t|z|vr|dz }|t|z|vr|t|zS)zGet a simple redefinition name not present among existing. For example, for name 'foo' we try 'foo-redefinition', 'foo-redefinition2', 'foo-redefinition3', etc. until we find one that is not in existing. z -redefinitionrRr4)rJ)r(existingr_namers r*get_unique_redefinition_namersY O #F X  A 3q6/X % Q 3q6/X % CF?r,c|tjdddkr&tjdj|yy)zAReport issues with the Python used to run mypy, dmypy, or stubgenNrR)rS zXRunning {name} with Python 3.8 or lower is not supported; please upgrade to 3.9 or newerr0)r version_infoexitr)programs r*check_python_versionrs; f$  --3VV-A %r,c|Dcgc] }d|vs| }}|Dchc]}|jdd}}|Dcgc] }d|vs| }}t|t|t|fScc}wcc}wcc}w)zDCount total number of errors, notes and error_files in message list.: error::r: note:)rLrC)rer error_filesnotess r* count_statsr sx! 5AZ1_a 5F 5,23q1773<?3K3 31INQ 3E 3 v;E C $4 4463 3s A*A*A/ A4A4cd}g}d}|D]*}|dk(r|r|j|d}|dk(r| }||z },|j||S)z=Split line of text into words (but not within quoted groups).rT ")r6)msg next_wordres allow_breakcs r* split_wordsrsgICK  8 JJy !I  8)/KQ JJy Jr,cttjddxs&tjj xst S)zIGet current terminal width if possible, otherwise return the default one.MYPY_FORCE_TERMINAL_WIDTH0)rrgetenvshutilget_terminal_sizecolumnsrrhr,r*get_terminal_widthrs< BII13 78   # # % - -  r,cHt|}|jd}g}|rY|jd}|r||z n||z }t|t|zdz|kr |d|zz }n|j||}|rY|j|dd|zz} | j |S)aWrap a long error message into few lines. Breaks will only happen between words, and never inside a quoted group (to avoid breaking types such as "Union[int, str]"). The 'first_offset' is the width before the start of first line. Pad every next line with 'num_indent' spaces. Every line will be at most 'max_len' characters, except if it is a single word or quoted group. For example: first_offset ------------------------ path/to/file: error: 58: Some very long error message that needs to be split in separate lines. "Long[Type, Names]" are never split. ^^^^-------------------------------------------------- num_indent max_len rr4rr~)rpoprCr6rB) rrx first_offset num_indentwords next_linerr max_line_lenpaddings r* soft_wrapr's&  E ! IE IIaL /4w+'L:P y>C N *Q ., > y (I LL #!I  LLS:%%G << r,cHtj|jS)zCompute a hash digest of some data. We use a cryptographic hash because we want a low probability of accidental collision, but we don't really care about any of the cryptographic properties. )hashlibsha1 hexdigestdatas r* hash_digestr.2s <<  ' ' ))r,ctjdk7sJddj|ddjdg}t j |j ddd j}|S) z.Reproduce a gray color in ANSI escape sequencewin32z"curses is not available on WindowsrNrImrr4r)rrrBrXcursestparmr)cup set_colorgrays r*parse_gray_colorr7<se <<7 "H$HH "Sb*C01I << ((11a 8 ? ? AD Kr,ctjdtjdd} tt|S#t$rt|cYSwxYw)NMYPY_FORCE_COLOR FORCE_COLORr)rrboolr ValueError)env_vars r*should_force_colorr>DsKii*BIImS,IJGCL!! G}sAAAceZdZdZ d ddZddZddZddZ d ddZ d dd Z dd Z dd Z dd Z dddZ dd d ddZy)FancyFormatterzcApply color and bold font to terminal output. This currently only works on Linux and Mac. Fc||_||_tjdvrd|_yt s(|j r|j sd|_ytjdk(r|j |_n@tjdk(r|j |_n|j |_|js6|j|j|j|jdd|_yy)N)rrr0 emscriptenTr0rBr)redgreenblueyellownone)hide_error_codes hide_successrr dummy_termr>isattyinitialize_win_colorsinitialize_vt100_colorsinitialize_unix_colorsREDGREENBLUEYELLOWcolors)rf_outf_errrHrIs r*rzFancyFormatter.__init__Rs!1( <<I I"DO !#U\\^5<<>"DO  <<7 ""&"<"<">>DO \\\ )"&">">"@@DO"&"="="??DOxx ++ DKr,ctjdvsJd|_d|_d|_d|_d|_d|_d|_d |_ y ) SReturn True if initialization was successful and we can use colors, False otherwise)r0rBzzzzzzzzT) rrBOLDUNDERrQrPrOrRNORMALDIMrs r*rMz&FancyFormatter.initialize_vt100_colorsnsR||6666       r,c`tjdk(rtj}|jtks|j t kryddl}|jj}d}d}d}d}|j|j|||z|z|jy Jd ) rWr0FrNr4rRriTzRunning not on Windows) rrgetwindowsversionmajorrbuildrctypeswindllkernel32SetConsoleMode GetStdHandlerM)rwinverr`rbENABLE_PROCESSED_OUTPUTENABLE_WRAP_AT_EOL_OUTPUT"ENABLE_VIRTUAL_TERMINAL_PROCESSINGSTD_OUTPUT_HANDLEs r*rLz$FancyFormatter.initialize_win_colors|s <<7 "**,F ::<<"== }}--H&) #(+ %14 . #   # #%%&78'+,45   ( ( *...ur,ctjdk(}|stsy tjj }t j |t jd}t jd}t jd }t jd }t jd }|r|r|r|r|sy|j|_ |j|_|j|_t!||_t j$|t j&j|_t j$|t j*j|_t j$|t j.j|_t j$|t j2j|_y #tj$rJtdd5}t j |j dddn #1swYnxYwYwxYw#t j$rYywxYw) rWr0F)fdz /dev/nullrbNboldsmulsetafr4sgr0T)rrCURSES_ENABLEDrfilenor2 setuptermioUnsupportedOperationrerrortigetstrrXrZrXrYr7r[r3 COLOR_BLUErQ COLOR_GREENrP COLOR_REDrO COLOR_YELLOWrR) ris_winrkrrmunderr5set_eseqnormals r*rNz%FancyFormatter.initialize_unix_colorss(   (ZZ&&(   B'v&'OOG, ??5)(9fmmo KKM \\^ #H-LLF,=,=>EEG \\)V-?-?@GGI << 6+;+;<CCEll9f.A.ABIIK 3** 4+t,4$$ 3444 4 ||  sFG3I3I%I7 II I IIII)(I)c|jr|S|r |j}nd}|r||jz }|r||jz }||j|z|z|j zS)z2Apply simple color and style (underlined or bold).r)rJrXrYr[rSrZ)rrYcolorrm underlinedimstarts r*stylezFancyFormatter.stylese ??K IIEE  TZZ E  TXX Et{{5))D04;;>>r,Nc |xs t}|j}t|D]>\}}d|vrD|jdd\}}t ||t |t dz}|dz|z||<|j dtzshd|vsm|td }||dz} | jd} | tz } d | vrd} n| | | jd dz} |tz d z } t|| | t\}}dtz|z||<dt| z|z z| z}t |t ||kDr%t | d kDr|d t ||d z d z}|||dz<A|S)zHImprove readability by wrapping error messages and trimming source code.rerror:r4maxsplitzerror: )r!r^N~rSrw) rcopyrrLr'rCr&rindexrindexr|r)rrfixed_terminal_widthwidth new_messagesrrvlocr marker_line marker_columncolumnmarkerrx source_liner{new_marker_lines r*fit_in_terminalzFancyFormatter.fit_in_terminals%<(:(<}} !(+ 6HAuU" ;;x!;<SUSC N9RS"%.3"6 Q&; ;<EAQ345&q1uo + 1 1# 6 &)>>k) F)9K9KC9PST9TUF "77!;&6ugv}&]# V"%(="= "K Q"%)>)G&)P"QTZ"Z'#l1o*>>3v;QR?&56PLO8Lq8P&QTY&YO&5 QU#9 6:r,cd|vr|jdd\}}|jr)||jdddz|j|zS|j d}|d k7r ||d }|d |}nd }||jdddz|j|z|j|d zSd |vrN|jdd\}}|j|j |}||jddz|zS|j dtzr*d|vr|j|ddS|j|dS|S)zBColorize an output line by highlighting the status and error code.rrr4rrCTrm[rINrrFr znote:rErrrG)r)rLrHrhighlight_quote_groupsrfindunderline_linkr&r)rrvrrcodeposcode formatteds r*colorizezFancyFormatter.colorizesk  {{8a{8HC$$$**Xu4*@@4C^C^_bCcciinG"}78}(7m**Xu4*89--c23**T8,-  % {{7Q{7HC33D4G4G4LMIGV44y@ @   c$99 :%zz%Tz::::eU+ +Lr,c|jddzr|S|jd}d}t|D]@\}}|dzdk(r||j|dz }$||jd|zdzddz }B|S)zMake groups quoted with double quotes bold (including quotes). This is used to highlight types, attribute names etc. rrRrrrGTr)countrLrr)rrrr8rparts r*rz%FancyFormatter.highlight_quote_groupss 99S>A J # ' GGAt1uztzz$//tzz#*s"2FzFF  G  r,ctjd|}|s|S|j}|j}|d||j |||ddz||dzS)zuUnderline a link in a note message (if any). This assumes there is at most one link in the message. z https?://\S*NrGT)r)researchrendr)rnoterVrrs r*rzFancyFormatter.underline_link*sg  /40K iikFU|djjeC&DjQQTXY\Y]T^^^r,Tcn|jryd|dt|}|s|S|j|ddS)zFormat short summary in case of success. n_sources is total number of files passed directly on command line, i.e. excluding stubs and followed imports. rzSuccess: no issues found in source filerDTr)rIplural_sr)r n_sources use_colorrs r*format_successzFancyFormatter.format_success6sE   ,YK|HYDWCXYJzz#wTz22r,)blockersrc d|dt|d|dt|}|r|dz }n|d|dt|dz }|s|S|j|d d S) z)Format a short summary in case of errors.zFound z errorz in z filez$ (errors prevented further checking)z (checked r)rCTr)rr)rn_errorsn_filesrrrrs r* format_errorzFancyFormatter.format_errorDsyxjx'9&:$wiuXV]M^L_`  9 9C Z {,x 7J6K1M MCJzz#u4z00r,F) rTIO[str]rUrrHr;rIr;rrrr;)FFF) rYrJrz1Literal['red', 'green', 'blue', 'yellow', 'none']rmr;rr;rr;rrJr)r list[str]rz int | Nonerr)rvrJrrJ)rrJrrJ)rrJrrJ)T)rrrr;rrJ) rrrrrrrr;rr;rrJ)rdrerfrgrrMrLrNrrrrrrrrhr,r*r@r@Ls \a%,@DTX 8 /:$T ??A? ?  ?  ? ?,GK#!#9C# #J@" _ 3(111 1  11 1r,r@c||nt} tjj|tjj |f|k(S#t $rYywxYw)NF)rrrr commonpathrr<) typeshed_dirfiles r*is_typeshed_filerXsQ#/#;<Lww!!<1F"GHLXX sAA AAcd|vry||nt}tjj|d} tjj |tjj |f|k(S#t $rYywxYw)NstdlibF)rrrrrBrrr<)rr stdlib_dirs r*is_stdlib_filer`spt#/#;<LlH5Jww!!:rwwt/D"EF*TT sAA22 A>=A>c|jdsytdtjj tjj |DS)Nz.pyiFc3>K|]}|jdyw)z-stubsN)r').0 components r* z'is_stub_package_file..psb y!!(+bs)r'anyrrrrLr)rs r*is_stub_package_filerls= ==  bRWW]]277??[_K`=ab bbr,c|duxr|dk(Sr.rhr0s r*unnamed_functionrss t  + +r,cHttj|z dz S)Ni)rrperf_counter_ns)t0s r* time_spent_usrzs $$&+t3 44r,cJt|tr|n t|}|dk7ryy)Nr4sr) isinstancerrC)rrs r*rr~s#As#AQE zr,cdjtjdt|}|j drd|ddvr|ddk7r d|dddSd |d Sd |d S) zKReturns docstring correctly encapsulated in a single or double quoted form.r~z (?<=[^\\])\\nrrr4rIz"""z''z"")rBrrLr_r&)docstr docstr_reprs r*quote_docstringrs))BHH%5tF|DEKc" k!B' 'KOs,BQr*+3/ /K=##K=##r,ctL|r"tjtjz}ntj} tj||S|r't j|ddjdSt j|ddjdS#t$r}t |dk7rYd}~md}~wwxYw) N)optionzInteger exceeds 64-bit rangerRT)indent sort_keysr),r)r separators)r OPT_INDENT_2 OPT_SORT_KEYSdumps TypeErrorrJjsonr)rNdebug dumps_optionr s r* json_dumpsrs  !..1E1EEL"//L <<L9 9  zz#a48??HHzz#*ELLWUU 1v778 sB## C,CCcbttj|Stj|Sr)rloadsrr,s r* json_loadsrs& ||D!! ::d r,r)r(rJr)r;rr;)r(rJrr;)r7rJrr)r= Iterable[str]r>rJr str | None)r=rr>rJrztuple[str, str] | None)rNrrrJ)rYbytesrtuple[str, int])r`rrrJ)rkrrrJ)rrrJrszCallable[[str], bytes]rzlist[str] | None) rZrJrxrryrrzrrr)rkrJrzlist[tuple[int, str]]) rfloatrr;rdict[str | None, list[str]]rrJrrJrrJ)rrrr;rrrrrJrrJrrJrr)rrJrrJ) rrJrrr>rJrr;rztuple[str, bool])rz type[object]rz Sequence[str])Frh) rrrrrr;rztuple[str, ...]rr)rrrJrrJrr;)rrrJr`rJrrJ)rrJrrJrrJ)r)rrrr)r(rJrrJ)r(rJrzContainer[str]rrJ)rrJrr)rrrztuple[int, int, int])rrJrr)rr) rrJrxrr!rr"rrrJ)r-rrrJ)r4rrrJr)rrrrJrr;)rrJrr;)r(rrr;)rrrr)rz int | SizedrrJ)rrJrrJ)rNrrr;rr)r-rrr )brg __future__rr)rtrrrrrrcollections.abcrrrr importlibrimportlib_resourcestypingr r r r r r__annotations__r ImportError_cursesr2rqrrJfilesrcompilerrrrrr frozensetr#r+r1r9r@r<rPr]ra Exceptionrcrnrur|rrrrrrrrrrrrrrrrrrrrrr rrr'r.r7r>r@rrrrrtime_refrrrrrrhr,r*rsQ9" @@6== N CL3-33F;jHI eIRZZ ab Ub u  u &(U'%*U*"Q 9_  +) $ )("<@  u'e e 'e e/ / /2/ /  /  /d% % %2%  %  %  % %$(& ? ?" ?,/ ?KO ? ?68 27 VX )-CR @ ,<<7cllh6""   5"!H*I1I1X c,   5$"V,s FNs$H H*H'&H'*H54H5