ML iJ\ddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z mZmZmZmZmZmZddlmZmZmZdd lmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;md%d Z?d&d Z@d'dZAd'dZBd(dZCd)dZDd)dZE d*dZF d+ d,dZGdd d-dZH d.dZI d/dZJd0dZKd1dZLd2dZMGdde2e'ZNd3d ZOd4d!ZPd5d"ZQ d6d#ZRy)7) annotations)Callable)join) erase_type)map_instance_to_supertype)state)are_parameters_compatible find_memberis_callable_compatible is_equivalentis_proper_subtype is_same_type is_subtype)is_recursive_pairmake_simplified_uniontuple_fallback)$MYPYC_NATIVE_INT_NAMESTUPLE_LIKE_INSTANCE_NAMESAnyType CallableType DeletedType ErasedType FunctionLikeInstance LiteralTypeNoneType Overloaded Parameters ParamSpecType PartialType ProperType TupleTypeType TypeAliasType TypedDictTypeTypeGuardedType TypeOfAnyTypeTypeTypeVarLikeTypeTypeVarTupleType TypeVarType TypeVisitor UnboundTypeUninhabitedType UnionType UnpackTypefind_unpack_in_listget_proper_typeget_proper_types has_type_varsis_named_instancesplit_with_prefix_and_suffixct||r t|St||r t|Stjr t St S)zRReturn one of types (expanded) if it is a subtype of other, otherwise bottom type.)rr2rstrict_optionalr.rsts O/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/meet.py trivial_meetr==sF!Qq!! Aq q!!  "$ $: cdt||r t||St|}t|}t|trt|tr|j |j k(r|j s |j rwt||rk|j rO|j rCt|j jt|j jkDr|S|S|j r|S|St|ts0t|ts t||dr|St||dr|St|tr|St|tr|St|trt|ts||}}tj ||\}}|j#t%|S)z-Return the greatest lower bound of two types.Tignore_promotions)rr=r2 isinstancertype extra_attrsrlenattrsr-r rrr/rnormalize_callablesacceptTypeMeetVisitorr9s r< meet_typesrJJsRAAq!!AA!X:a#:qvv?O MMQ]] Q0B}}q}}**+c!--2E2E.FFH}}H a %jK.H QT :H QT :H!Z !W!Y 1i(@!1  # #Aq )DAq 88OA& ''r>c t|tr&t||jdr|S|jS|}|}t |}t |}||k(r|St|t r||j }t|t r|j }n|g}t|Dcgc]1}|D]*}t||dst||dr t||,3c}}St||rCt|t sJt|j Dcgc]}t||c}St|tr3t|s(t||jr|j|St||ds$t j"r t%St'St|t r1t|j Dcgc]}t||c}St|t(r|St|trt|j|r|St|t*rCt|t*r3t+j,t|j.|j.St|t*r,t|t0r|j2j5r|St|t0rx|j2j6r|St|t0rD|j2j6r.|j2j6j2|j2ur|St9||St|t:t*t<fr t9||St|t>r\t|t0rL|j2j@dk(r'tCdtE|jFDr|St9||S|Scc}}wcc}wcc}w)z7Return the declared type narrowed down to another type.Tr@F upper_bound)prohibit_none_typevar_overlapz builtins.dictc3<K|]}t|tywN)rBr).0r;s r< z'narrow_declared_type..s= '(Jq' "= s)$rBr&r type_guardr2r/relevant_itemsris_overlapping_typesrnarrow_declared_typeis_enum_overlapping_unionr+r4rM copy_modifiedrr8r.rrr(make_normalizeditemrrC is_metaclass alt_promoterJr"rr%fullnameallr3args) declarednarrowedoriginal_declaredoriginal_narroweddeclared_itemsnarrowed_itemsdnxs r<rVrVts^(O, Xx':':d SO"""  x(Hx(H8  (I&!002 h *%446N&ZN$( ' )AF!!Q%@%Q* *   (!84(I...$8@8O8O8Q R1 !(A . R   8[)/0 ((*>*> ?%%2C%DD !(HTX Y  "$ $:  Hi ($8@8O8O8Q R1 !(A . R   Hg &  Hk *z(:N:NPX/Y Hh 'Jx,J''(?? Hy(K@ A+->?? Hm ,Hh1O == ! !_ 4= ,?? ] 0 S" Ss&6O OOcTt|}t|tr1t|jdkDr |jS|j gSt|t rct|j }t|tr$t|jjdggSttjgSt|tr |j gSt|trt|j St|t"rt|j S|gS)aThis function takes any "Union-like" type and returns a list of the available "options". Specifically, there are currently exactly three different types that can have "variants" or are "union-like": - Unions - TypeVars with value restrictions - Overloads This function will return a list of each "option" present in those types. If this function receives any other type, we return a list containing just that original type. (E.g. pretend the type was contained within a singleton union). The only current exceptions are regular TypeVars and ParamSpecs. For these "TypeVarLike"s, we return a list containing that TypeVarLike's upper bound. This function is useful primarily when checking to see if two types are overlapping: the algorithm to check if two unions are overlapping is fundamentally the same as the algorithm for checking if two overloads are overlapping. Normalizing both kinds of types in the same way lets us reuse the same algorithm for both. r)r2rBr+rEvaluesrMrrrCmrorr'implementation_artifactr*r/listitemsr)typrMs r<get_possible_variantsrqs2 # C#{# szz?Q :: OO$ $ C '%coo6 k8 ,[--11"5r:; ; 99:;; C) *  C #CII C $CIIu r>cttxrMjjxr5t|txr#t fd|j DS)zOReturn True if x is an Enum, and y is an Union with at least one Literal from xc3K|]D}tt|xtxr#jjjk(FywrP)rBr2rrCfallback)rQzprhs r<rRz,is_enum_overlapping_union..sC  OA..q < Z1::??AZ Z sA A )rBrrCis_enumr/anyrT)rhyrvs` @r<rWrWsX 1h FFNN q) $   %%'  r>cttxr0t|txrtfd|jDS)z?Return True if x is a Literal and y is an Union that includes xc3:K|]}t|k(ywrP)r2)rQrurhs r<rRz&is_literal_in_union..!s9A_Q''9s)rBrr/rxro)rhrys` r<is_literal_in_unionr|s: 1k" : q) $ : 99 9r>cXt|txr|jjdk(SNzbuiltins.object)rBrrCr])r;s r< is_objectr%s" a " Kqvv:K'KKr>cFt|txrt|tSrP)rBrr)t1t2s r<is_none_typevarlike_overlapr)s b( # G 2(GGr>c|t|txr+t|txr|jjdk(Sr~)rBrrrCr]rs r<is_none_object_overlapr-s82x  2 r8 $ 2 GG   1 1r>c~|rt|||xst|||St|||xst|||S)Nr@)r r)leftrightproper_subtyperAs r<are_related_typesr5sY %+< Q ud>O P Q$9JK z 4+<P  r>FNct|tst|try tn||fvryt|tr#t|trj ||ft ||f\}}t|t st|t rJdtttf}t||s t||rytjsvt|tr#tj|j}t|tr#tj|j}t ||f\}}t|tst|tr xst!|xs t!|St#||s$t#||st%||s t%||ryrt'||s t'||ryt)||ryt+|}t+|}rt-||s t-||rydfd t/|dkDs.t/|dkDs t|t0st|t0r|D]} |D]} | | s yytjr"t|t2t|t2k7ryt|t4rt|t4r t7||St9||rt;||St|t4r |j<}nt|t4r |j<}t?|rt?|r tA||St|tBr tE|}nt|tBr tE|}t|tFr-t|tFr|jH|jHSt|tFst|tFrdfd } | ||xs | ||St|tJr"t|tJrtM||d d St|tJst|tJryt|tNr"t|tNrtQ||d d Sd} d} t|tNr!t|tRrtUd ||d } |} t|tNr!t|tRrtUd ||d } |} ttW| tXr| | J| | St|tNr |j<}t|tNr |j<}t|tZrCt|tZr3|j\|j\k(r|j<}|j<}n:yt|tZr |j<}nt|tZr |j<}t|tRrVt|tRrEt)||ry|j^j`d k(r|j^j`tbvry|j^je|j^j`rtg||j^}nG|j^je|j^j`rtg||j^}ny|j^jhr |j^jjJ|j^jlJ|j^jj}|j^jl}|j^jnjp|}t|trsJ|jD}tu|jv||\}}}tu|jv||\}}}|tCty||fz|z}|tCty||fz|z}n|jv}|jv}t/|t/|k(rt{fdt}||Dryyt_|t_|k7sJt_|dt_|y)aECan a value of type 'left' also be of type 'right' or vice-versa? If 'ignore_promotions' is True, we ignore promotions while checking for overlaps. If 'prohibit_none_typevar_overlap' is True, we disallow None from overlapping with TypeVars (in both strict-optional and non-strict-optional mode). If 'overlap_for_overloads' is True, we check for overlaps more strictly (to avoid false positives), for example: None only overlaps with explicitly optional types, Any doesn't overlap with anything except object, we don't ignore positional argument names. TNFz%Unexpectedly encountered partial type)rrAc Bt||jS)zEncode the kind of overlapping check to perform. This function mostly exists, so we don't have to repeat keyword arguments everywhere. )rArNoverlap_for_overloads seen_types)rUcopy)rrrArrNrs r<_is_overlapping_typesz3is_overlapping_types.._is_overlapping_typess+ $  /*G"7!(   r>) overlappingc t||f\}}t|tr-t|tr|j|j St|trt|t rt|jt rF|jjj}| ||S|jjdSt|jtr|jjdSy)z-Special cases for type object types overlaps. builtins.typeF) r3rBr(rrZret_typerrCmetaclass_typehas_baser)rr left_metars r<_type_object_overlapz2is_overlapping_types.._type_object_overlaps+D%=9KD%$)j .M,TYYGG$)j.Idii2 $  = =I ,4YFF ::..?? 73 ::..??r>) is_compatr ignore_pos_arg_namesallow_partial_overlap__call__) is_operatorz builtins.intc36K|]\}}||ywrP)rQleft_arg right_argrs r<rRz'is_overlapping_types..ts$'Hi&h :z vs rr#rr#returnbool)?rBr&setr$addr3r r-rrrr8r/ make_unionrTrrrWr|rrrqrrEr)rr%are_typed_dicts_overlappingtyped_dict_mapping_pairtyped_dict_mapping_overlaprtis_tupleare_tuples_overlappingr"rr(rZrr rr rr r2rrvaluerCr]rrrhas_type_var_tuple_typetype_var_tuple_prefixtype_var_tuple_suffixdefn type_varsr*r6r_rnr^zip)rrrArNrr illegal_types left_possibleright_possiblelrrcallotherprefixsuffixtvtrt left_prefix left_middle left_suffix right_prefix right_middle right_suffix left_args right_argsrs ```` @r<rUrUBs4"$(Juo,NU * $$ &:e]+Ke}%"D%=1KD%$ $ 5+(F===u!*k:M$ &*UM*J  dI &''(;(;(=>D eY '(()=)=)?@E&e}5 e$ Jug$>((OIdOOy?OO "$. $UD 1 tU + ud + !$ .2HPT2U e$9M^ *$/M*51N% &tU 37RSXZ^7_    MQ ~  " dO , e_ - A# (A.   D(!;z%QY?Z!Z$ &:e]+K*48MNN u -)$CXYY D- (}} E= )~(5/%dE3HII D) $d# E9 %u%$!j&A$TYY ;;$!Zx%@ ($D%0U4HPT4UU$ # 5*(E(  +#%:!:"&   $ #z%'D$ %*UL*I%  +#%:!:"&    D E$ %*UH*E:ueF%&:dH+E:tTtD/$'6E$555$T511$ %}}%&$ $E;)G :: $==DNNE D+ &}} E; '$!j&A  %(=Qb  ::  . 0TYY5G5GKa5a 99  ejj11 2,T5::>D ZZ !3!3 4-eTYY?E :: - -::33? ??::33? ??ZZ55FZZ55F**//++F3Cc#34 44))H4P 665 1Kk8T FF8 4L, $yk1BH'M&OOR]]I%4 3Ex)P(RRUaaJ IJ y>S_ ,+.y*+E :e $Fd De &FF $ r>r@cDtt|t||dS)zMThe same as 'is_overlapping_erased_types', except the types are erased first.T)rArN)rUr)rrrAs r<is_overlapping_erased_typesrs' 45+&*  r>c|jD]7}||jvry||j||j|r7y|jD]7}||jvry||j||j|r7yy)z?Returns 'true' if left and right are overlapping TypeDictTypes.FT) required_keysro)rris_overlappingkeys r<rrs !! ekk !djjou{{3/?@ "" djj djjou{{3/?@  r>ct||f\}}t||xs|}t||xs|}t|ts Jd|dt|ts Jd|dt |j }t |j }|t |t|j }|t |t|j }t|j t|j k7rytfdt|j |j Dsyt|jdst|jdry|j|jS)z6Returns true if left and right are overlapping tuples.zType z is not a tupleFc36K|]\}}||ywrPr)rQrrrs r<rRz)are_tuples_overlapping..sM1~a#Mrbuiltins.tupleT) r3 adjust_tuplerBr"r1roexpand_tuple_if_possiblerEr^rr5partial_fallback)rrr left_unpack right_unpacks ` r<rrsJ#D%=1KD% e $ ,D  % .E dI &E%v_(EE & eY 'G5)GG '&djj1K&u{{3L'c%++.>?(DJJ@ 4::#ekk** MDJJ 0LM M//1ABFW /Gd33U5K5KLLr>ct|j|dzkDr|S|dzt|jz }g}|jD]}t|ts|j |%t |j }t|tr |j}nt|tsJ|}|j jdk(sJ|j|jdg|z|j|S)Nrrrro)rErorBr0appendr2rCr*rrr]extendr_rX)tuptargetextra new_itemsitunpackedinstances r<rrs 399~ " QJSYY 'EIii 5"j)   R "277+ h 0 1..Hh1 11H}}%%)9999(--*+e34 5   9  --r>ct|trX|jjdk(r?t|tr|j nd}t |j dg|z|Sy)zGFind out if `left` is a Tuple[A, ...], and adjust its length to `right`rrrN)rBrrCr]r"lengthr_)rrrgs r<rrsS$!dii&8&8ct|}t|txs+t|txr|jj dk(S)Nr)r2rBr"rrCr])rps r<rrs? # C c9 % 3!Kchh&7&7;K&Kr>ceZdZddZddZddZddZddZd dZd!dZ d"dZ d#d Z d$d Z d%d Z d&d Zd'd Zd(dZd)dZd*dZd+dZd,dZd-dZd.dZd/dZd0dZd1dZd2dZd3dZy)4rIc||_yrPr:)selfr:s r<__init__zTypeMeetVisitor.__init__s r>ct|jtr&tjr t S|jSt|jt r |jSt tjSrP) rBr:rrr8r.rr' special_formrr;s r<visit_unbound_typez"TypeMeetVisitor.visit_unbound_typesS dffh '$$&((vv  066M9112 2r>c|jSrPrrs r< visit_anyzTypeMeetVisitor.visit_any vv r>cXt|jtrTg}|jD]8}|jjD]}|j t ||:t |S|jDcgc]}t ||j}}t |Scc}wrP)rBr:r/rorrJr)rr;meetsrhrys r<visit_union_typez TypeMeetVisitor.visit_union_types dffi ( "EWW 33ALLAq!123 3 %U++56GGc|SrPrrs r<visit_uninhabited_typez&TypeMeetVisitor.visit_uninhabited_typesr>ct|jtrtjr|S|jSt|jt r |jS|SrP)rBr:rrr8r.rs r<visit_deleted_typez"TypeMeetVisitor.visit_deleted_typesC dffh '$$vv  066MHr>c|jSrPrrs r<visit_erased_typez!TypeMeetVisitor.visit_erased_type'rr>ct|jtr|jj|jk(ry|jj|jk(r |jS|jj |j |jj|jS|j|jS)NrL)rBr:r+idrMrXmeetdefaultrs r<visit_type_varzTypeMeetVisitor.visit_type_var*s dffk *tvvyyADD/@vv!!Q]]2vv 66''DIIdff>P>PRSR_R_4`'a a<<' 'r>cn|j|k(r |jS|j|jSrP)r:rrs r<visit_param_specz TypeMeetVisitor.visit_param_spec2s) 66Q;66M<<' 'r>ct|jtrT|jj|jk(r1|jj|jkDr |jS|S|j |jSrP)rBr:r*rmin_lenrrs r<visit_type_var_tuplez$TypeMeetVisitor.visit_type_var_tuple8sY dff. /DFFII4E!VV^^aii7466 >Q ><<' 'r>ctrP)NotImplementedErrorrs r<visit_unpack_typez!TypeMeetVisitor.visit_unpack_type>s!!r>c t|jtrt|jt|jjk7r|j |jSddlm}|jt|jj|jDcgc]\}}|||c}}S|j |jScc}}w)Nr) join_types) arg_types) rBr:rrEr r mypy.joinr rXr)rr;r s_at_as r<visit_parametersz TypeMeetVisitor.visit_parametersAs dffj )1;;3tvv'7'7#88||DFF++ ,??@CDFFDTDTVWVaVa@bcHC:c3/c# <<' 'ds)C c t|jtr|j|jjk(rt ||jst |j|r4g}|jj r|j}|jj J|jjJ|jj }|jj}|jjj|}t|tsJ|j}t|j||\}} } t|j||\} } } |tt| |fz| z}| tt| |fz| z}n"|j}|jj}t!|||jjjD]\}}}|j#||}t|trdt|tr|j%|j&Ut|t(sJt+|jj-|g}|j/|t|j|St0j2r t)St5S|jj6}|r$|j|jjur|S|jjj6}|r$|j|jur |jSt ||jr|St |j|r |jSt0j2r t)St5St|jt8rD|jj:r.t=j>|}|rktA||jSt|jt8r{|jjCra|jjErGt |jjF|r |jS|jI|jSt|jtJrtA||jSt|jtrtA||jSt|jtLrtA||jSt|jtNrtA||jS|jI|jS)N)r_)(rBr:rrCrrrrrrr*rr6r_r"rnrrrror.r0rXrrr8rr\r is_protocolrunpack_callback_protocolrJ is_type_objr[rtrr(rr%)rr;r_r:rrrrts_prefixs_middles_suffixt_prefixt_middlet_suffixs_argst_argstasatvrr\rs r<visit_instancezTypeMeetVisitor.visit_instanceMs dffh 'vv$a(Jtvvq,A(*Dvv55!FF vv;;GGG vv;;GGG!"!=!=!"!=!=ffkk33F;)#/?@@@##57SFFFF84(H8TFFFF84(H"*YtH~x-P,R!RU]!]!)YtH~x-P,R!RU]!]!"!%&)&&!&&++:O:O&P * B#yyR0%b*:; *$ : $ DJJ 7 ('1$'H H'H'1"2C2C2Q2QX\W]2Q2^'_ D) *$AFFD11,,.00'z)ff00 ;#3#3tvv{{#BH"ffkk55 ;#3#3qvv#=66Ma(H*66M,,.00'z)  -!&&2D2D003D!$//  -$&&2D2D2F166K^K^K`$&&//1-vv <<' '  )a( (  *a( (  ,a( (  .a( (||DFF##r>ct|jtrtj||jrt ||jr tj ||jSt||j}|jr|jjsE|jjr$|jjjsd|_ tt|jtr|j|jS|St|jt r|jr|j#spt%|jj&|j}t|t(tfst!j*|S|j|jSt|jt,rM|jj.j0r-tj2|j}|r t%||S|j|jS)NT)rBr:rris_similar_callablesr combine_similar_callablesmeet_similar_callablesr type_object is_abstractfrom_type_typer2rr.rr( is_genericrJrZrrYrrCrr)rr;resultresrs r<visit_callable_typez#TypeMeetVisitor.visit_callable_types dffl +0I0I!TVV0TQ'55a@@+Atvv6FQ]]_%@%@FF&&(TVV-?-?-A-M-M(,%/&//:OL||DFF++M  )ammoallnTVV[[!**5CcHo#>?//44<<' '  )dffkk.E.E008D!!T**||DFF##r>c|j}t|trj|j|jk(rt |jSt ||r|St ||r|St |j|jSt|jtrM|jjjr-tj|j}|r t ||St |j|SrP) r:rBrrorrrJrtrrCrrr)rr;r:rs r<visit_overloadedz TypeMeetVisitor.visit_overloadeds FF a &ww!''!!!''**Aq!Aq!!!**ajj99  )dffkk.E.E008D!!T**!**a((r>cpt|j}t|j}|||j|jk(r]g}t|jD]=}|j |j |j||j|?|Sy|||j|jk(rf||k(r`|}|j|}t |tsJt|j} |j|} t | tsJt| j} t | trt | tsy|j | | } t | tsyg} t|jd||jd|D] \}}| j t||"g}t|j|dzd|j|dzdD] \}}|j t||"| t| gz|zSy||}|}|}n |J|}|}|}|j|}t |tsJt|j}t |tsy|j|jdz kry|}|j|z dz }tt|j||\}}}g}t||jd|D]&\}}|j |j ||(|D]0}|j |j ||jd2|rCt||j| dD]&\}}|j |j ||(|S)aMeet two tuple types while handling variadic entries. This is surprisingly tricky, and we don't handle some tricky corner cases. Most of the trickiness comes from the variadic tuple items like *tuple[X, ...] since they can have arbitrary partial overlaps (while *Ts can't be split). This function is roughly a mirror of join_tuples() w.r.t. to the fact that fixed tuples are subtypes of variadic ones but not vice versa. Nrr)r1rorrangerrrBr0r2rCrrrJr6tupler_)rr:r;s_unpack_indext_unpack_indexroi unpack_indexs_unpack s_unpackedt_unpack t_unpackedrm_prefixsitim_suffixvariadicfixedunpackr prefix_len suffix_lenrmiddlerfivimis r< meet_tupleszTypeMeetVisitor.meet_tuplessz-QWW5,QWW5  !n&<xxzQXXZ'$&qxxz*DALL1771:qwwqz!BCD   %.*DxxzQXXZ'Nn,L- 77<0!(J777,X]]; 77<0!(J777,X]]; ":x8Z T\=]yyZ8!$1')!!''-<"8!''-<:PQ8FBOOJr2$678')!!'',*:*<"=qww|VWGWGY?Z[8FBOOJr2$678:d#3"44x??  %H)LE!- --H)LE -&*---"6;;/(H- <<>HOO-1 1! __&3a7 != %++  J" &(..*"=> ,FB LL2r* + , :B LL2x}}Q'78 9 : fhnnj[\&BC 0B TYYr2./ 0 r>c t|jtrN|j|j|}||j |jSt|t |St|jt r|jjjtvra|jjrK|j|jDcgc]%}t||jjd'c}St||jr|S|jjjrt!||jr|S|j |jScc}w)Nrr)rBr:r"rErrrrCr]rr_rXrorJr rr)rr;rors r<visit_tuple_typez TypeMeetVisitor.visit_tuple_types dffi ($$TVVQ/E}||DFF++UN1$56 6  )vv{{##'@@TVV[[WXW^W^-_QSjTVV[[^.L-_``"1dff-44Atvv9N||DFF##.`s*E5cRt|jtr@|jj|D]V\}}}t ||r(||j v||jj vk7s;|j |jcSg}|jj|D]3\}}}||j||f|J|j||f5t|} |jj} |j |jj z} |j|jjz} t| | | | St|jtrt||jr|S|j |jSrP)rBr:r%rr rrzipallrdictcreate_anonymous_fallback readonly_keysrr) rr;namerr item_list item_name s_item_type t_item_typerortrrLs r<visit_typeddict_typez$TypeMeetVisitor.visit_typeddict_type3sg dffm ,"ffjjm 0 a$Q*tq/FDFF000/ <<//  0 13I7;vv}}Q7G ?3 ; *$$i%=>'222$$i%=>  ?OEvv779HOOdff.B.BBMOOdff.B.BBM  }hO O  )jDFF.CH<<' 'r>ct|jtr|j|k(r|St|jtr"t |j |jr|S|j |jSrP)rBr:rrrrtrrs r<visit_literal_typez"TypeMeetVisitor.visit_literal_typeLsV dffk *tvv{H  )jTVV.LH<<' 'r>cJd)NzInternal errorrrs r<visit_partial_typez"TypeMeetVisitor.visit_partial_typeTs &&&ur>ct|jtrc|j|j|jj}t|t s!tj ||j}|St|jtr%|jjjdk(r|St|jtr|j||jS|j|jS)N)liner) rBr:r(rrZrrYrXrrCr]rr)rr;rps r<visit_type_typezTypeMeetVisitor.visit_type_typeXs dffh '))AFFDFFKK0Cc8,..s@J  )dffkk.B.Bo.UH  -99Q' '<<' 'r>cJd|)Nz!This should be never called, got rrs r<visit_type_alias_typez%TypeMeetVisitor.visit_type_alias_typees=9!==ur>ct||SrP)rJ)rr:r;s r<rzTypeMeetVisitor.meeths!Qr>ct|trttjSt j r tStSrP) rBr-rr'rrr8r.r)rrps r<rzTypeMeetVisitor.defaultks7 c; '9112 2$$&((z!r>N)r:r!rNone)r;r-rr!)r;rrr!)r;r/rr!)r;rrr!)r;r.rr!)r;rrr!)r;rrr!)r;r+rr!)r;rrr!)r;r*rr!)r;r0rr!)r;rrr!)r;rrr!)r;rrr!)r;rrr!)r:r"r;r"rzlist[Type] | None)r;r"rr!)r;r%rr!)r;rrr!)r;r rr!)r;r(rr!)r;r$rr!r:r#r;r#rr!)rpr#rr!)__name__ __module__ __qualname__rrrrrrrrrrrrrrr*r,rErGrRrTrVrYr[rrrr>r<rIrIs 3,  (( ( " (S$j$8)&L\$((2(' (> "r>rIcddlm}m}|||\}}g}tt |j D]4}|j ||j ||j |6|jjjdk7r |j}n |j}|j|t|j|j|dS)Nr)match_generic_callables safe_joinzbuiltins.function)r rrtrM) r rdrer.rEr rrtrCr]rXrJr)r;r:rdrer r2rts r<r#r#us< "1a (DAqI 3q{{# $D1;;q>1;;q>BCD  zz#66:::: ??AJJ 3   r>cr|sttjS|d}|ddD]}t||}|S)Nrr)rr'rmrJ)typesmetr;s r<meet_type_listrisG y8899 (C 12Y!a ! Jr>ct||f\}}t|trt|trJt|tr||}}nt|tr||}}nyt|txr|jj dS)aIs this a pair where one type is a TypedDict and another one is an instance of Mapping? This case requires a precise/principled consideration because there are two use cases that push the boundary the opposite ways: we need to avoid spurious overlaps to avoid false positives for overloads, but we also need to avoid spuriously non-overlapping types to avoid false positives with --strict-equality. Ftyping.Mapping)r3rBr%rrCr)rr_rs r<rrsz#D%=1KD%$ .j 6VV V$ &5 E= )$5 eX & P5::+>+>?O+PPr>c t||f\}}t|trt|trJt|trt|tsJ||c }n)t|tsJt|tsJ||c }t d|j j Dd}| jryt d|j j D}t||}t|j\} jj}|j jdjd}t|trt tr j S jr*||syt fd jDS||syt! j"j% jz } t' fd| DS)aSCheck if a TypedDict type is overlapping with a Mapping. The basic logic here consists of two rules: * A TypedDict with some required keys is overlapping with Mapping[str, ] if and only if every key type is overlapping with . For example: - TypedDict(x=int, y=str) overlaps with Dict[str, Union[str, int]] - TypedDict(x=int, y=str) doesn't overlap with Dict[str, int] Note that any additional non-required keys can't change the above result. * A TypedDict with no required keys overlaps with Mapping[str, ] if and only if at least one of key types overlaps with . For example: - TypedDict(x=str, y=str, total=False) overlaps with Dict[str, str] - TypedDict(x=str, y=str, total=False) doesn't overlap with Dict[str, int] - TypedDict(x=int, y=str, total=False) overlaps with Dict[str, str] * A TypedDict with at least one ReadOnly[] key does not overlap with Dict or MutableMapping, because they assume mutable data. As usual empty, dictionaries lie in a gray area. In general, List[str] and List[str] are considered non-overlapping despite empty list belongs to both. However, List[int] and List[Never] are considered overlapping. So here we follow the same logic: a TypedDict with no required keys is considered non-overlapping with Mapping[str, ], but is considered overlapping with Mapping[Never, Never]. This way we avoid false positives for overloads, and also avoid false positives for comparisons like SomeTypedDict == {} under --strict-equality. c3@K|]}|jdk(s|yw)ztyping.MutableMappingNr]rQbases r<rRz-typed_dict_mapping_overlap..sU$DMM=T,TUNFc3@K|]}|jdk(s|yw)rkNrorps r<rRz-typed_dict_mapping_overlap..sXDdmmGW6W4Xrrrc3JK|]}j|ywrPrrQkrtyped value_types r<rRz-typed_dict_mapping_overlap..s Xq;u{{1~z:X #c3JK|]}j|ywrPrrus r<rRz-typed_dict_mapping_overlap..s Qq;u{{1~z:Qry)r3rBr%rnextrCrlrLrr_ as_anonymousrtbasesr.rr^rrokeysrx) rrrrmutable_mappingmappingkey_typertstr_type non_requiredrwrxs ` @@r<rrsD#D%=1KD%$ .j 6VV V$ &%***U u$)))%///d uU%**..UW[O"u':':XEJJNNXXG %eW 5E+EJJ7Hj!!#,,H}}""1%**1-H(O,J1X&&&& 8X.XEDWDWXXX8X.5;;++-.1D1DD QLQQQr>r_)r`r#rar#rr#)rpr#r list[Type])rhr!ryr!rr)r;r!rr)rr!rr!rr) rr#rr#rrrArrr)FFFN)rr#rr#rArrNrrrrzset[tuple[Type, Type]] | Nonerr)rr#rr#rArrr)rr%rr%rCallable[[Type, Type], bool]rr)rr#rr#rrrr)rr"rintrr")rr!rr!rzTupleType | None)rpr#rr)r;rr:rrr)rgrrr#r)rr#rr#rrrr)S __future__rtypingrmypyrmypy.erasetyper mypy.maptyper mypy.stater mypy.subtypesr r r r r rr mypy.typeopsrrr mypy.typesrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r=rJrVrqrWr|rrrrrUrrrrrrrIr#rirrrr>r<rs"%2RQ%%%%%%%%%%T '(TfR/d LH      04  IM     $*/"'04 A A AA$( A  A . A AJ ;@    37     -?[ 0!M !M!M-I!M !MH.*@"k*-@"F ,Q(GR GRGR*FGR GRr>