ML i,dZddlmZddlmZddlmZmZddlm Z ddl m Z ddl m Z mZmZmZmZmZmZmZmZmZerddlmZ dd Z dd ZGd d Zy )zLUtilities for mapping between actual and formal arguments (and their types).) annotations)Sequence) TYPE_CHECKINGCallable)nodes)map_instance_to_supertype) AnyTypeInstance ParamSpecType TupleTypeType TypedDictType TypeOfAnyTypeVarTupleType UnpackTypeget_proper_type)ArgumentInferContextct|}t|Dcgc]}g}}g}d} t|D]\} } | tjk(r_| |ks || j s|| j | | dz } M|| tjk(sd|| j | y| tjk(rt|| } t| trutt| jD]R} | |ks || tjk7r|| j | n|| tjk7sN| dz } T"| |ks)|| jdr@|| j | || tjk(rl| dz } | |krNy| jr|Jd|| }||vrJ||j|tjk7r%||j|j | tj|vs||jtjj | ,| tjk(sJt|| } t| tr| jD]n}||vr$||j|j | +tj|vs>||jtjj | p|j | |rt|D cgc]V} || r7|| r||| dtjk(r|| tjk7s|| tjk(r| X}} |D]} |D]} || j | |Scc}wcc} w)a3Calculate mapping between actual (caller) args and formals. The result contains a list of caller argument indexes mapping to each callee argument index, indexed by callee index. The caller_arg_type argument should evaluate to the type of the actual argument type with the given index. rT)starz/Internal error: named kinds without names given)lenrange enumeraterARG_POSis_starappendARG_STARr isinstancer items ARG_STAR2is_namedindexr) actual_kinds actual_names formal_kinds formal_namesactual_arg_typenformalsiformal_to_actualambiguous_actual_kwargsfiai actual_kindactualt_nameunmatched_formalss Q/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/argmap.pymap_actuals_to_formalsr4s< H5:8_(E(E(E)+ B$\243K %-- 'H}#B'//1$R(//3!GB!"%7$R(//3 ENN *%ob&9:G'9-s7==12$AH}'+u>,R077;!'+u~~=!GB$8m#B'00d0;(,33B7#B'5>>9!GB8m ! ! #+ ^-^ ^+#D|# \5G5G5M(NRWR`R`(` !3!3D!9:AA"EL0 !3!3EOO!DELLRP%//1 11%ob&9:G'=1#MMYD|+(););D)ABII"ML8(););EOO)LMTTUWX Y(..r2i43lHo  R (,#$4R$8$;<N $6B5??2     * 0B' 0 $++B/ 0 0 _)F|  s N87AN=ct|||||}|Dcgc]}g}}t|D] \}} | D]} || j|"|Scc}w)z8Calculate the reverse mapping of map_actuals_to_formals.)r4rr) r#r$r%r&r'r*r0actual_to_formalformalactualsactuals r3map_formals_to_actualsr:}sz.lL,6B(B(B(B$%564 4F V $ + +F 3 44  )Cs Ac:eZdZdZddZ d ddZy)ArgTypeExpanderaUtility class for mapping actual argument types to formal arguments. One of the main responsibilities is to expand caller tuple *args and TypedDict **kwargs, and to keep track of which tuple/TypedDict items have already been consumed. Example: def f(x: int, *args: str) -> None: ... f(*(1, 'x', 1.1)) We'd call expand_actual_type three times: 1. The first call would provide 'int' as the actual type of 'x' (from '1'). 2. The second call would provide 'str' as one of the actual types for '*args'. 2. The third call would provide 'float' as one of the actual types for '*args'. A single instance can process all the arguments for a single call. Each call needs a separate instance since instances have per-call state. c.d|_d|_||_y)Nr) tuple_index kwargs_usedcontext)selfr@s r3__init__zArgTypeExpander.__init__s,0 c|}t|}|tjk(rt|trt|j }t|t r|jrsddlm }|||jjr7t||jjjjdSttj St|t"r|j$t'|j(k\rd|_n|xj$dz c_|j(|j$dz }t|t*ry|swt|j} t| trt| j } n| } t| t r| jj,dk(sJ| jd}|St|t.r|Sttj S|tj0k(rMddlm }t|t2r|j4t7|_|tj0k7r||j(vr|@Jt7|j(j9|j4z j;}|j4j=||j(|St|t rT|||jj>r7t||jj>jjdSt|t.r|Sttj S|S)aReturn the actual (caller) type(s) of a formal argument with the given kinds. If the actual argument is a tuple *args, return the next individual tuple item that maps to the formal arg. If the actual argument is a TypedDict **kwargs, return the next matching typed dict value type based on formal argument name and kind. This is supposed to be called for each formal, in order. Call multiple times per formal if multiple actuals map to a formal. r) is_subtyperzbuiltins.tuple) rrrrr upper_boundr args mypy.subtypesrEr@ iterable_typertyper r from_errorr r>rrrfullnamer r rr?setkeyspopadd mapping_type) rA actual_typer. formal_name formal_kind allow_unpackoriginal_actualrEitemunpackedfallbacks r3expand_actual_typez"ArgTypeExpander.expand_actual_types&&%k2 %.. (+'78.k.E.EF +x0[5E5E4k4<<+E+EF4#T\\%?%?%D%Dd1#9#7#788K3##s;+<+<'=='(D$$$)$"(()9)9A)=>dJ/ .tyy9H!(,<=#283G3G#H#+"8X6$MM226FFG$==+D K7""y3344 EOO + 0+}5##+'*uD$%//1k[EVEV6V&222$'{'8'8'='='?#@4CSCS#S"X"X"ZK  $$[1"((55K2zT\\668 1dll>W>W>\>\]bbK7""y3344# "rCN)r@rreturnNone)F) rRr r. nodes.ArgKindrSz str | NonerTr]rUboolr[r )__name__ __module__ __qualname____doc__rBrZrCr3r<r<sW*# _#_##_# _# # _#  _# _#rCr<N) r#list[nodes.ArgKind]r$Sequence[str | None] | Noner%rdr&zSequence[str | None]r'Callable[[int], Type]r[list[list[int]]) r#rdr$rer%rdr&zlist[str | None]r'rfr[rg)rb __future__rcollections.abcrtypingrrmypyr mypy.maptyper mypy.typesr r r r r rrrrr mypy.inferrr4r:r<rcrCr3rosR"$*2   /_%_-_&_' _ + _  _D%-&#  +   &}#}#rC