ML i\ddlmZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZmZmZmZmZmZmZmZmZmZmZmZdd lmZdd lmZdd l m!Z!dd l"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-ddZ.ddZ/ddZ0d dZ1d!dZ2d"dZ3GddeZ4 d#dZ5GddeZ6d$dZ7GddZ8d%dZ9y)&) annotationsN) defaultdict) cmp_to_key)Callable)State) format_type)PYTHON_EXTENSIONS) LDEF Decorator ExpressionFuncBase MemberExprMypyFileNodeOverloadedFuncDefRefExpr SymbolNodeTypeInfoVar)FineGrainedBuildManager)ExtendedTraverserVisitor)tuple_fallback) FunctionLikeInstance LiteralType ProperType TupleType TypedDictType TypeVarType UnionTypeget_proper_type)fill_typevars_with_anycd|j|kDxs |j|k(xr|j|kDSN)linecolumnor%r&s V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/inspections.pynode_starts_afterr**s+ 66D= @AFFdN@qxx&/@@c|j:|j.|j|ks|j|k(r|j|kryy)NTF)end_line end_columnr's r)node_ends_beforer/.s? zz!,,": ::  d 2q||f7L r+cr|jd|jdzd|jd|jS)z1Format expression span as in mypy error messages.:)r%r&r-r.)exprs r) expr_spanr47s5ii[$++/*!DMM?!DOO;L MMr+ct|tr|gSt|tr t|gSt|tr |j gSt|t r |j gSt|tr |j gSt|trb|jr8g}|jD]%}|jtt|'|Stt|jSt|tr8g}|jD]%}|jtt|'|SgS)zBReturns the Instance fallback for this type if one exists or None.) isinstancerrrrfallbackrrrvaluesextendget_instance_fallbackr! upper_boundr items)typrests r)r:r:<s #x u C #s#$$ C ' ~ C & ~ C % ~ C % ::CZZ F 01CDE FJ$_S__%EFF C # BA JJ,_Q-?@ A B Ir+cb|j|}|rit|tr |jS|jr?t|t sJ|j d}t|tsJ|jS|S|j|}|r |jnd}t|tr|Sy)z7Find the node defining member 'name' in given TypeInfo.rN) get_methodr6r var is_propertyrr<getnoder)nameinfomethoddecrEvs r) find_noderKWs__T "F fi (::    f&78 88,,q/Cc9- --77N xx~DII4 a H r+c||}||vr||S d|vry|jdd\}}|j|}||S1)znFind module by a node fullname. This logic mimics the one we use in fixup, so should be good enough. .Nr2maxsplit)rsplitrD)fullnamemodulesheadtailmods r)find_module_by_fullnamerVms\ D wt}  d?[[q[1 dkk$ ?J r+c eZdZdZddZddZy) SearchVisitorzGVisitor looking for an expression whose span matches given one exactly.cJ||_||_||_||_d|_yr$)r%r&r-r.result)selfr%r&r-r.s r)__init__zSearchVisitor.__init__s%    $)- r+ct||j|jryt||j|j ry|j|jk(rb|j|jk(rI|j|jk(r0|j |j k(rt |tr||_|jduS)NF) r*r%r&r/r-r.r6r rZr[r(s r)visitzSearchVisitor.visits Q 4;; 7 At}}doo > FFdii  dmm+DKK' /!Z( {{d""r+N) r%intr&r`r-r`r.r`returnNoner(rrabool__name__ __module__ __qualname____doc__r\r_r+r)rXrXsQ. #r+rXc||kr td||k(r||kr tdt||||}|j||jS)z=Find an expression matching given span, or None if not found.z$"end_line" must not be before "line"z#"end_column" must be after "column") ValueErrorrXacceptrZ)treer%r&r-r.visitors r)find_by_locationrpsX$?@@4J&0>??D&(J?GKK >>r+c eZdZdZddZddZy)SearchAllVisitorzGVisitor looking for all expressions whose spans enclose given position.c.||_||_g|_yr$)r%r&rZ)r[r%r&s r)r\zSearchAllVisitor.__init__s  (* r+ct||j|jryt||j|jryt |t r|j j|y)NFT)r*r%r&r/r6r rZappendr^s r)r_zSearchAllVisitor.visitsO Q 4;; 7 Atyy$++ 6 a $ KK  q !r+N)r%r`r&r`rarbrcrerjr+r)rrrrsQ+ r+rrcxt||}|j|tt|jS)zFFind all expressions enclosing given position starting from innermost.)rrrmlistreversedrZ)rnr%r&ros r)find_all_by_locationrys.tV,GKK ( ))r+c@eZdZdZdddddddd ddZddZddZddZdd Z d d Z dd Z d!d Z d"d Z d#dZ ddZd$dZd$dZd%dZ d&dZ d'dZd(dZ d)dZd*dZd*dZd*dZy)+InspectionEnginez:Engine for locating and statically inspecting expressions.rF) verbositylimit include_span include_kindinclude_object_attrs union_attrs force_reloadc||_||_||_||_||_||_||_||_d|_yr$) fg_managerr|r}r~rrrrmodule) r[rr|r}r~rrrrs r)r\zInspectionEngine.__init__sH%" (($8!&($( r+c|jjjj}d|jjj_ |jj |j J|jj |j|j fgg||jjj_y#||jjj_wxYw)z4Reload given module while temporary exporting types.TN)rmanageroptions export_types flush_cachepathupdateid)r[stateolds r) reload_modulezInspectionEngine.reload_modulesoo%%--::7;''4 ? OO ' ' )::) )) OO " "UXXuzz$:#;R @;>DOO # # + + 83DOO # # + + 8s AC'C9c|jjjj|}||j |dfSt ||jjj |j}|j||dfS)zFormat type for an expression using current options. If type is known, second item returned is True. If type is not known, an error message is returned instead, and second item returned is False. F)r|T) rr all_typesrD missing_typerrr| add_prefixes)r[ expression expr_typetype_strs r)rzInspectionEngine.expr_types OO++5599*E  $$Z0%7 7 t..66$..   :6<.item_attrss0EE! .Yt_-- .Lr+c@||jvry||jvryy)Nr2r)mro)xys r) cmp_typesz1InspectionEngine.collect_attrs..cmp_typess!AEEzAEEzr+Nrrr2)key)rdict[TypeInfo, list[str]]razset[str])rrrrrar`) typerrsortedrrurrwrkeysr)r[ instancesrr all_attrsinstancerrr intersectionitemcombined_attrsrF sorted_basesrZs r) collect_attrszInspectionEngine.collect_attrssp   y ! $HE--##C,,#2h 1$TZZ0d  1   U # $")A,/ abM -D Jt, ,L - %T* :D :>) J:D''4<+?&t,33D9: : :n113I9NO   0D!$')$/F4L  0  r+c |D]f}|jdkr |jn |j}||Dcgc]}d|d }}|jd|ddj |dhycc}w)Nr2"z": [, ])r|rFrQrujoin)r[ attrs_strs attrs_dictrcls_nameattrrs r)_fill_from_dictz InspectionEngine._fill_from_dict1sy ED$(NNQ$6tyyDMMH-7-=>Tqa[>E>   (4 %0@/AC D E>s A-c |jjjj|}||j |dfSt |}t |}|s|jg}|j|}t|trut|jtr[|j}t|j}d|vr|jdd|j d|Dcgc]}d|d c}i}ni}t|t"rD|j%r4t'|j)} |jt | } ni} g} |r0|D]+} | j+| ddj-|| d-|j/| | |j/| ||j1d dj-| d |d fScc}w) avFormat attributes that are valid for a given expression. If expression type is not an Instance, try using fallback. Attributes are returned as a JSON (ordered by MRO) that maps base class name to list of attributes. Attributes may appear in multiple bases if overridden (we simply follow usual mypy logic for creating new Vars etc). F __builtins__z""rz: [rr{}T)rrrrDrr!r:rrr6rrErrrremoverQr is_type_objr" type_objectrurrr) r[rrrrrErrFmod_dicttemplate class_dict base_attrsrUs r) expr_attrszInspectionEngine.expr_attrs9sOO++5599*E  $$Z0%7 7#I. ))4 ))+,I'' 2  j' *z*//8/T??D4::&E& ^,T]]O2.0O1TF!0OPHH i .93H3H3J-i.C.C.EFH++,A(,KLJJ  J!!SETYYx}-E,Fa"HI J Z4 Z4  2dii &;% r)rrurrfr~r4r)r[rZrprefixesprefixs r)rzInspectionEngine.add_prefixessw    OOtJ/889 ;    OOIj1 2 XXh'&0FFr+c t|||dz ||}||d|d|d|} d| dddS||\} } | d| rddSddS#t$r}dt|icYd}~Sd}~wwxYw) zzGet type of an expression matching a span. Type or error is returned as a standard daemon response dict. r2errorNr1zCan't find expression at span routerrstatusr)rprlstr) r[rnr%r&r-r.rHrrspaninspection_strsuccesss r) run_inspection_by_exact_locationz1InspectionEngine.run_inspection_by_exact_locations ')$fqj(JWJ  V1VHAhZq =D;D6B2YZ[ ["("4%bAPPaPP 'SX& & 'sA A# AA#A#ct|||dz }|s|d|}d|dddSg}d}|D]%} || \} } | sd}| s|j| '|jr|d|j}dj|d|dS) zGet types of all expressions enclosing a position. Types and/or errors are returned as a standard daemon response dict. r2r1z'Can't find any expressions at position rrrN )ryrur}r) r[rnr%r&rH expressionspositioninspection_strsrrrrs r)run_inspection_by_positionz+InspectionEngine.run_inspection_by_positions+4vzB q)H@ K  % 7J&,Z&8 #NG&&~6  7 ::-l ;Oyy1"OOr+ctfdtDsdddifStjj t fd|j jjDd}||_ || dddd fSifS) zFind module by path, or return a suitable error message. Note we don't use exceptions to simplify handling 1 vs 2 statuses. c3@K|]}j|ywr$)endswith).0extfiles r) z/InspectionEngine.find_module..%sC#4==%CsNrz Source file is not a Python filec3BK|]}|jk(s|ywr$)abspath)rsabs_paths r)rz/InspectionEngine.find_module..+sYA199PXCXaYszUnknown module: rr2r) anyr osrrnextrrr8r)r[rrrs ` @r) find_modulezInspectionEngine.find_module s C1BCC'#EFF F77??4(Y!6!6!=!=!?Y[_` JO-&tf-bA F  ]_  r+c t|\}}|j|\}}||sJ|S|jr"|jj s |j r|j||jJt|dk(r'|\}} } } |j|j|| | | |St|dk(sJ|\}} |j|j|| |S#t$r}dt|icYd}~Sd}~wwxYw)z{Top-level logic to inspect expression(s) at a location. This can be reused by various simple inspections. rN) parse_locationrlrrrnrrrlenrr) r[locationrHrposrrerr_dictr%r&r-r.s r)run_inspectionzInspectionEngine.run_inspection2s  '&x0ID#**40x =O8OzzUZZ99T=N=N   u %zz%%% s8q=14 .D&(J88 D&(J 3x1}} f..uzz4PP- 'SX& & 'sC!! D* C<6D<Dc:|j||jS)z)Get types of expression(s) at a location.)r rr[r s r)get_typezInspectionEngine.get_typeSs""8T^^<E& 8&.F@  QQQ Q  Q  Q9Q Q2PPP P 9 P  P@ $QQ%MQ QB=>r+r{c|jddkr td|jdd}|^}}|jddkr||Dcgc] }t|c}fS|jdd}|^}}|jddkr|||zDcgc] }t|c}fStdcc}wcc}w)Nr1rz7Format should be file:line:column[:end_line:end_column]rN)countrlrPr`)r partsstartrestp start_rests r)rrfs~~cQRSS OOC!O ,ELED {{3!t,!s1v,,, LLqL )EEJ {{3!zD'89!s1v999 N OO -:s B:B?)r(rr%r`r&r`rard)r3r rar)r=rrar)rFrrGrrazVar | FuncBase | None)rQrrRzdict[str, State]raz State | None) rnrr%r`r&r`r-r`r.r`razExpression | None)rnrr%r`r&r`razlist[Expression])r rraztuple[str, list[int]]): __future__rr collectionsr functoolsrtypingr mypy.buildr mypy.messagesrmypy.modulefinderr mypy.nodesr r r r rrrrrrrrmypy.server.updatermypy.traverserr mypy.typeopsr mypy.typesrrrrrrrr r! mypy.typevarsr"r*r/r4r:rKrVrXrprrryr{rrjr+r)r/s" # %/    73'   1AN 6,&#,#4    '* 69 GJ  /$*ccL Pr+