ML i UdZddlmZddlZddlZddlZddlmZddlm Z m Z m Z ddl m Z mZddlmZmZmZmZmZmZddlmZmZddlZddlmZdd lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%dd l&m'Z'm(Z(m)Z)dd l*m+Z+dd l,m-Z-m.Z.dd l/m0Z0ddl1m2Z2m3Z3m4Z4ddl5m6Z6m7Z7m8Z8ddl9m:Z:m;Z;mm?Z?m@Z@mAZAddlBmCZCddlDmEZEddlFmGZGmHZHddlImJZJddlKmLZLmMZMddlNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZddlmZmZmZmZmZddlmZddlmZddlmZmZmZmZmZddlmZddlmZmZmZmZmZmZmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZdd lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZdd!lmZmZmZmZdd"lmZdd#lmZdd$lmZdd%lmZeeeeXeeeeeeebebg dfZd&ed'<d(Zd)ed*<gd+Zd)ed,<hd-Zd)ed.<Gd/d0eZdWd1ZdXd2ZGd3d4eZejGd5d6ejZejZd)ed7<ej Zd)ed8<ejZ d)ed9<Gd:d;eee+Z dYdZd<Z Gd=d>e%jZ dWd?ZdWd@ZdWdAZ d[dBZd\dCZGdDdEe%jZd]dFZGdGdHe%jZd]dIZGdJdKe%jZd^dLZ d_dMZd`dNZ dadOZdbdPZdcdQZdddRZdedSZdfdTZ dgdUZ!dhdVZ"y)izGExpression type checker. This file is conceptually part of TypeChecker.) annotationsN) defaultdict)IterableIteratorSequence)contextmanager nullcontext)CallableClassVarFinalOptionalcastoverload) TypeAlias assert_never) applytype erasetypejoinmessage_registrynodes operatorstypes)ArgTypeExpandermap_actuals_to_formalsmap_formals_to_actuals)ExpressionCheckerSharedApi)analyze_member_access has_operator)StringFormatterChecker) erase_type!remove_instance_last_known_valuesreplace_meta_vars) ErrorInfo ErrorWatcherreport_internal_error) expand_typeexpand_type_by_instancefreshen_all_functions_type_varsfreshen_function_type_vars)ArgumentInferContextinfer_function_type_argumentsinfer_type_arguments)literal)map_instance_to_supertype)is_overlapping_typesnarrow_declared_type) ErrorMessage)MessageBuilder format_type)C ARG_NAMEDARG_POSARG_STAR ARG_STAR2IMPLICITLY_ABSTRACT LAMBDA_NAME LITERAL_TYPE REVEAL_LOCALS REVEAL_TYPEArgKindAssertTypeExprAssignmentExpr AwaitExpr BytesExprCallExprCastExprComparisonExpr ComplexExprConditionalExprContext DecoratorDictExprDictionaryComprehension EllipsisExpr EnumCallExpr Expression FloatExprFuncDef GeneratorExpr IndexExprIntExpr LambdaExprListComprehensionListExpr MemberExprMypyFileNamedTupleExprNameExpr NewTypeExprOpExprOverloadedFuncDef ParamSpecExprPlaceholderNode PromoteExprRefExpr RevealExprSetComprehensionSetExpr SliceExprStarExprStrExpr SuperExpr SymbolNodeTempNode TupleExprr TypeAliasExprTypeApplication TypedDictExprTypeInfo TypeVarExprTypeVarLikeExprTypeVarTupleExpr UnaryExprVar YieldExpr YieldFromExpr)PRECISE_TUPLE_TYPES)FunctionContextFunctionSigContext MethodContextMethodSigContextPlugin) ENUM_BASES)state) find_member is_equivalent is_same_type is_subtypenon_method_protocol_membershas_await_expression)check_for_explicit_any fix_instancehas_any_from_unimported_typeinstantiate_type_aliasmake_optional_type set_any_tvarsvalidate_instance) callable_typecustom_special_methoderase_to_union_or_bound false_onlyfixup_partial_typefreeze_all_type_vars function_typeget_all_type_vars get_type_varsis_literal_type_likemake_simplified_unionsimple_literal_type true_onlytry_expanding_sum_type_to_uniontry_getting_str_literalstuple_fallbacktype_object_type))LITERAL_TYPE_NAMESTUPLE_LIKE_INSTANCE_NAMESAnyType CallableType DeletedType ErasedType ExtraAttrs FunctionLikeInstance LiteralType LiteralValueNoneType Overloaded ParametersParamSpecFlavor ParamSpecType PartialType ProperType TupleTypeType TypeAliasType TypedDictType TypeOfAnyTypeType TypeVarIdTypeVarLikeTypeTypeVarTupleType TypeVarType UnboundTypeUninhabitedType UnionType UnpackTypefind_unpack_in_listflatten_nested_tuplesflatten_nested_unionsget_proper_typeget_proper_typeshas_recursive_types has_type_varsis_named_instancesplit_with_prefix_and_suffix)is_generic_instanceis_overlapping_noneis_self_type_likeremove_optional) type_state) fill_typevars)split_module_names)ExpressionVisitor _TypeAlias ArgCheckerr MAX_UNIONS) builtins.setzbuiltins.frozensetztyping.KeysViewztyping.ItemsViewzbuiltins._dict_keyszbuiltins._dict_itemsz_collections_abc.dict_keysz_collections_abc.dict_itemsOVERLAPPING_TYPES_ALLOWLIST>builtins.memoryviewbuiltins.bytesbuiltins.bytearrayOVERLAPPING_BYTES_ALLOWLISTceZdZdZy) TooManyUnionszyIndicates that we need to stop splitting unions in an attempt to match an overload in order to save performance. N__name__ __module__ __qualname____doc__T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/checkexpr.pyrrsrrct|tr |jryt|}t|txs.t|t xrt d|jDS)NFc32K|]}t|ywN)allow_fast_container_literal.0its r z/allow_fast_container_literal..s(\b)Eb)I(\) isinstancer is_recursiverrrallitemsts rrrsT!]#A a " 1i \S(\TUT[T[(\%\rc\t|jts |jrt|jtr'|jr|j |jt|t rt|jt xr|jj}t|jtr/|jt|jjyd|jvr0|s.|j |jjdddyt|tr(t|jtr |j}nyt!dt#|t|jtrv|jryy)zRecursively extracts all module references from a reference expression. Note that currently, the only two subclasses of RefExpr are NameExpr and MemberExpr..rzUnknown RefExpr subclass: N)rnoderWfullnameaddrYrsis_suppressed_importrnupdater module_namersplitrVexprr`AssertionErrortype)routputrs rextract_refexpr_namesrs TYY )T]] dii *t}} JJt}} % dH %#-dii#=#`$))B`B` $))X. 01F1FGH  %.B 4==//Q7:;  j )$))W-yy #=d4j\!JK K- TYY )T]]rceZdZdZy)FinishedzDRaised if we can terminate overload argument check early (no match).NrrrrrrsNrrceZdZdZdZdZdZy) UseReversezCUsed in `visit_op_expr` to enable or disable reverse method checks.rrN)rrrrDEFAULTALWAYSNEVERrrrrrsMG F ErrUSE_REVERSE_DEFAULTUSE_REVERSE_ALWAYSUSE_REVERSE_NEVERc eZdZUdZded<ded<ded<ded <d ed <d ed <ded< ddZddZddZdddZddd ddZ ddZ ddZ dddZ ddZ dddZddZddZddZdd Zdd!Zdd"Z dd#Z dd$Z dd%Zdd&Z dd'Z dd(Zdd)Z d dd+Z dd,Zdd-Zd.gd/d0gd1Zd2ed3<d4d5gid6d7gid6d7gid6d8d5gid9Z d:ed;<dd<Z!dd=Z" dd>Z# dd?Z$ dd@Z% ddAZ& ddBZ' d ddCZ( ddDZ) ddEZ* d ddFZ+ddGZ, d ddHZ- ddIZ.ddJZ/ddKZ0ddLZ1ddMZ2 ddNZ3 ddOZ4 ddPZ5 ddQZ6ddRZ7 ddSZ8 ddTZ9 d ddUZ: ddVZ; ddWZ< d ddXZ= ddYZ> ddZZ? dd[Z@ dd\ZA dd]ZB dd^ZC d d d_ZDd d`ZEeF d daZGd dbZH d dcZI d dddZJddeZK ddfZLdΐddgZM d ddhZN ddiZOddjZPddkZQddlZRddmZSddnZTddoZUddpZVddqZWddrZXddsZYddtZZdduZ[d*d*dddv d dwZ\ d d!dxZ] d d"dyZ^ d#dzZ_ d$d{Z` d d%d|Zadd}Zbdd~Zcd&dZdd'dZed(dZfd(dZg d d)dZhd*dZid+dZjd,dZkd-dZld.dZmd/dZn d d0dZo d1dZpd2dZqd3dZrd4dZsd5dZtd6dZud7dZvdd d8dZw d9dZx d:dZyd;dZzddZ}d?dZ~d@dZdAdZdBdZ dCdZdDdZ dEdZdFdZ dGdZdHdZdIdZdJdZdKdZdLdZdMdZ d dNdZdOdZdPdZdΐdQdZ dR dSdZdTdZ dU dVdZddWdZdXdZdYdZd dZd dZdZdZd[dZdΐd\dZ d d]dZdΐd^dZd_dZd`dZdadZdbdZdcdZdddZdedZdfdZdgd„ZdhdÄZdYdĄZdYdńZedidƄZe djdDŽZ d djdȄZdkdɄZdkdʄZy*(lExpressionCheckerz^Expression type checker. This class works closely together with checker.TypeChecker. mypy.checker.TypeCheckerchkr2msgzlist[Type | None] type_contextzdict[Expression, ProperType] resolved_typerstrfrm_checkerr{pluginzArgumentInferContext | None_arg_infer_context_cachec||_||_||_||_|jj du|_d|_dg|_i|_ t|j|j|_ i|_ d|_ |jjj t_d|_i|_d|_d|_d|_y)z%Construct an expression type checker.NF)rrrper_line_checking_time_nsoptionsline_checking_statscollect_line_checking_stats in_expressionrtype_overridesrrr is_calleeold_type_inferencerinfer_polymorphicr expr_cachein_lambda_expr _literal_true_literal_false)selfrrrrs r__init__zExpressionChecker.__init__@s )B&+.;;+J+JRV+V(#!F 794TXXtxxH +/88+;+;+N+N'N $(,%  $.2/3rcFi|_|jjyr)rrclearr#s rresetzExpressionChecker.resetls rct||jj|j|}|j ||}|jj |j ||S)z_Type check a name expression. It can be of any kind: local, member or global. )rr module_refsanalyze_ref_exprnarrow_type_from_bindercheck_deprecatedr)r#eresultnarroweds rvisit_name_exprz!ExpressionChecker.visit_name_exprpsW a!5!56&&q)//6: !!!&&!,rFcd}|j}t|tr%|jrt t j St|trC|j||}t|trb|jj||||}nBt|tr|j|j|}nt|tr|jf|jj!r2|j"r&|jj%|j&|t t j(}n|j}nt|t*t,t.t0t2fr"|j5|||j6xs|}n>t|t8rJd|j:dt t j(}t|t,rt|t<rPt|j>t@r6|jB|j>_!|jD|j>_"tG|jHdrtKjL|}|J|S)NzPlaceholderNode z leaked to checker)'rrrYis_special_formrr special_formrsanalyze_var_refrrhandle_partial_var_typerHvarr\rin_checked_functionrhandle_cannot_determine_typename from_errorrOrnrrWrpanalyze_static_referenceis_alias_rvaluer^rrret_typerlinecolumnis_type_type_contextrrerase_typevars)r#r.lvaluer/rs rr+z"ExpressionChecker.analyze_ref_expr{s"vv a "q'8'89112 2 dC ))$2F&+.99&&$PQR i ())$((A6F / 0yy 88//1djjHH99$))QG !5!56 w)XW X224A? @99? (>(> ? ? g & t7J'KL L h '""..t44"22 ++'doo>> i (.='')+- 99cI:  k *??#34 4 }.>? @##% % h '-<4##D) a')J`J`Ba ay++,,  s GG c0|jrt|j}t|tru|jdk(r|j dS|j r|j |jS|jdvr|j|jdk(dS|jS|js@|jjr&|jj|j|ttj S)Nz typing.Anytyping._SpecialForm>TrueFalserW builtins.bool)rrrrrrMis_literal_contextlast_known_valuer;infer_literal_expr_typeis_readyrr9r:rrr5)r#r8contextvar_types rr6z!ExpressionChecker.analyze_var_refs 88&sxx0H(H-<<</??+@AA**,1J1J1V#444880077F8JO\\88O<Q>Q**1-;;qzz4+<+t@tBfst|tr|rt|j4t6r|j4jDsytt |j4j8x}tFr/|jHs>j(jJjLdk\sj0jOt|tPst|j4tRs!|j4jTr3j0j3jjd j|j4jVsj0j3jjd jYd} tjtZrt]jjjjjjfd } t_t!jjD cgc]D} tajb| | D cgc] } j j| "c} F} } } t| jjjjjejgd  } t j j| dd}d}d}dtjtPrjjhxsdtjj4t6rOt jj4j8}t|tjr|jljhstjtnrtj(jqjjrrEjj}j(jujjr}j(jJjvrj(jyrt|tr|jzr}|jt|k7rj||Jj||r2tfdj(jJjDsj0j|j|||}tjtPrkt!jdk(rSjjhdvrjjjhdk(rjtjtnr*jjdk(rjt |}t|tFrt|j}t|tr0|js$j(jj|sjt|t<rZjjr?j(j0j|t;tjS|S#t,$rYwxYwcc} wcc} } w)NTr)r issubclassrrLiteralAny TypedDictNewTypec@jj|Sr)rqargs)ir.r#s rz9ExpressionChecker.visit_call_expr_inner..[s$++affQi0rrI)r?fallback)always_allow_anyrc3TK|]}|k(xsj|d!yw)rN) startswith)rprs rrz:ExpressionChecker.visit_call_expr_inner..s6'A =!4!4s!W!=='s%()zbuiltins.isinstancebuiltins.issubclassrformat)QrvcalleerrQrurrqrr?rcheck_typeddict_call arg_kinds arg_namesrrYr;lenmypycheckerflattenrlookup_qualifiedrbis_expr_literal_typercannot_use_function_with_typerrrtrrrnrlrkno_argsruses_pep604_syntaxrpython_versiontype_arguments_not_allowedr`rnrN is_newtypetry_infer_partial_typerSrrangerjoin_type_listrRrMrrrrVhas_typer lookup_typedisallow_untyped_callsr9implicitr9method_fullnameanyuntyped_calls_excludeuntyped_function_call check_call_expr_with_callee_typecheck_runtime_protocol_testcheck_protocol_issubclasscheck_str_format_callrrr ambiguousbinder unreachablealways_returns_nonedoes_not_return_valuerr<)r#r.rmrOrNtyprrt union_targetrformal_to_actualrj arg_types callee_typerRmemberr?rs`` @rrpz'ExpressionChecker.visit_call_expr_inners  $ $QXX .!((I.((7!0QXXQU1V!W ,l;!01C1L1L!M!.-@@@00"AKKaffaI[ qxx * !==AFF q ||++AFF1I6' \c8,#xx88B(,HH::188==)UVWJtyy)<,TYY-=-=>F!&'2>>qxx}}eUVW !&(3 sI."3<>'IHH77:c7+ 388X0Nxx..>>qxx}}k[\],,>>qxx}}iYZ[O' \P ##A& ahh +5  """"0   s188#5#567##EUVWEX$YT[[%;$YZI(""""))+)<= L& KK,QUK V   ahh (xx((0DH!((--3()=)=>fh/%{{33H qxx4HH%%ahhmm4"hh22188==A  HH   3 3,,.; 5$$  K/F$6"...// VD3'))??'$..{A>88 Hk6  ahh (S[A-=xx  $RR003xx  $99..q1 ahh + 0I  & &q )"8, h *,X^^9//0 0$^%Zs*?%ee1!%e, e1 e)(e),e1ct|jtsJd}t|jjtr"|jjj }n_|j j|jjr/t|j j|jj}t|tr|jjrt|jtrvt|jj trR|jj |jj j}t|t"r t|}t%|}t|tr&t|j tr |j }||j&j)||yy)z>More precise type checking for str.format() calls on literals.N)rrrVrrfvaluerrrrrris_enumr[rstrrdrtry_getting_literalrr)r#r. format_valuer value_typebase_typs rrz'ExpressionChecker.check_str_format_calls<!((J/// ahhmmW -88==..L XX  qxx}} -!$(("6"6qxx}}"EFC3)HH$$s33[As33993? XX^^C,@,@,F,FGLL j$/)*5C*3/H(K0ZPS5T'~~  #    5 5a F $rct|}t|tr&|jrt|j}nt|t r |j }d}t|tr|jj}n{t|ttfr6|jjj|}| |jnd}n/t|trt|jj}|r|d|Sy)zConvert a method name to a fully qualified name, based on the type of the object that it is invoked on. Return `None` if the name of `object_type` cannot be determined. Nr)rrr is_type_objr?ritemrrrrrrget_containing_type_inforr)r#rR method_name type_nameinfos rrz!ExpressionChecker.method_fullnames&k2 k< 0[5L5L5N*+*>*>?K  X .%**K k8 ,#((11I  m[%A B'',,EEkRD)-)9 tI  Y /&{388AAI [+/ /rcDt|tr|j|jryt|tr|jt |j j|j}t|tr |j}nTt|trC|jr3t |j}t|tr |j}nyy|j|j}|r|j|jryy)zPCheck if `node` refers to something explicitly annotated as only returning None.TF)rr`defn_returns_nonerrVrrrrrrrrr?getr;)r#rrrr?syms rrz%ExpressionChecker.always_returns_nones dG $%%dii0 dJ 'DII,=!$(("6"6tyy"ABC#x(xxC.3??3D*3<<8h1#==D ((499%Ct--chh7rcpt|trIt|jtxr-tt |jj t St|trtfd|jDSt|trt |j}|js4t|tr$tt |j t ryt|tr9|jjd}|rj|jryy)z'Check if `defn` can _only_ return None.c3@K|]}j|ywr)r)rrr#s rrz6ExpressionChecker.defn_returns_none..sKt--d3KT__call__F)rrOrrrr?rr\rrrs is_inferredrrrr)r#defnrrs` rrz#ExpressionChecker.defn_returns_nones dG $dii6: 2 23X<  d- .K KK K dC !$)),C$$sL1s||>;KL HHLL;;BNN.,sIy)44Iskwargsrrr)rziprfvalidate_typeddict_kwargs check_typeddict_call_with_kwargsrrr<rr5rrIcheck_typeddict_call_with_dictrrBrnrcrrrINVALID_TYPEDDICT_ARGS) r#rrrrr^ orig_calleerjrr/validated_kwargsalways_present_keys unique_args rrz&ExpressionChecker.check_typeddict_call#sv CIyIISA '!*4?SUYZF336&3QF!8>5 "5<<,g{DW9//0 0 t9>ilg5aJ*h/::J,,g{*h/Jz?R?RT\4]::J//55w 88Wk[^[`a a  &==wGy++,,7TsFctt}t}d}|D]\}}|r|j|}t ||} d} | rt | dk(r| d} | B|xs|} |j jtj| tjy|g|| <|j| |}|j||||ry|j jjrX|Vg} |j D]'} | |j"vs| |vs| j%| )| r|j&j)| |||fS)Nrrcode)rlistrcrqrrrrr$TYPEDDICT_KEY_MUST_BE_STRING_LITERALcodes LITERAL_REQrvalidate_star_typeddict_itemr extra_checksr required_keysappendr"non_required_keys_absent_with_star)r#rrr/rlast_star_founditem_name_expritem_argkey_typevalues literal_value key_context absent_keyskeys rrz+ExpressionChecker.validate_typeddict_kwargsMsaT"!e(. $NH;;~61.(K $ c&kQ.$*1IM ("0".sBr3"***BsrT)rrqrrrrrelevant_itemsrvalid_unpack_fallback_itemr%unsupported_target_for_star_typeddictrcrkeysri make_unionset_linerr) r#rrr/rinferred possible_tdsrall_keysrargfirstrs @rrz.ExpressionChecker.validate_star_typeddict_items#4;;xf;#MN h .$:L ) ,()@)@)BC !dM2 ''-88>HHBB4R  ! 00: HH : :8X N U (B   'H ( (C$$l%^cUWU]U]obhhsm%^_C LL "B\BB#'', #;"3KNE%eX6(-cls '*es #&%F3Ks ""3'1 (2/&_s -GGct|tryt|tr|jj dsyt ||j jd}tdt|jDS)NTtyping.MappingFc3<K|]}t|tywr)rrras rrz?ExpressionChecker.valid_unpack_fallback_item..sQa:a)Q) rrrrhas_baser.rlookup_typeinforrr)r#rmappeds rrz,ExpressionChecker.valid_unpack_fallback_itemse c7 ##x(0A0ABR0S*30H0HIY0Z[Q3CFKK3PQQQrc|j||}|W|\}}|jt|jcxkxr&t|jjkScSy)NrF)rrrcrr)r#rrr^r/r_s rmatch_typeddict_call_with_dictz0ExpressionChecker.match_typeddict_call_with_dictsj //vf/M  "(  a''3/?/D/D/F+Gc3v||O`O`ObKcc cc crc|j||}||\}}|j|||||SttjS)Nr)rr^rr)rrrrr<)r#rrr^rr/rrs rrz0ExpressionChecker.check_typeddict_call_with_dictse//vf/M  4: 1 188''$7 9 9//0 0rc|jJ|jj}t|trt|tsJ|j ||j jS)aConstruct a reasonable type for a TypedDict type in runtime context. If it appears as a callee, it will be special-cased anyway, e.g. it is also allowed to accept a single positional argument if it is a dict literal. Note it is not safe to move this to type_object_type() since it will crash on plugin-generated TypedDicts, that may not have the special_alias. ) special_aliasrtrrrtypeddict_callable_from_contextr type_vars)r#rrts rrOz$ExpressionChecker.typeddict_callables]!!---##**&*-*V]2SSS33FDIIj@jBtDjFd|ddZn| Scc}wcc}wcc}wcc} w#1swYxYw#1swYxYw) Nr^) expected_keys actual_keysr^rrzTypedDict item "" expression) lvalue_typervaluer^r lvalue_name rvalue_name)$r to_be_mutated readonly_keysrreadonly_keys_mutatedrrunexpected_typeddict_keysrrrr<rrrrrrrOrrPrlocal_type_mapcheck_callable_callrr=r4rrcheck_simple_assignmentr1rINCOMPATIBLE_TYPESrrTYPEDDICT_ITEM)r#rrr^rrr&assigned_readonly_keysr infer_calleer orig_ret_typerr? item_nameitem_expected_type item_values item_values rrz2ExpressionChecker.check_typeddict_call_with_kwargssRkkm   %063G3G%G "%../Ew.W  $7 7K6<Y#(;! #cVEYEY>Y!$3 ##k1y3344%k2 k< 0&L##11=#66v7K7KL  $CCFK XX # # % txx'>'> #77&,]]_5Ta5""#c&k1V[[]#  M1  #=1(M2H-5^^-A-A-C  )I)F"$Y/ "- JHH44$6) *(,??EEEL`L`'7yk$C$05   U##!<6    sUM( 6M- M- M2 (M2 ,NM<" M7.AM<0N7M<<N NNct|jtrDt|jjtr |jjj sy|j jj}|r|j|jvry|j|j}t|jtr0t|jjtr |jSy)zGet variable node for a partial self attribute. If the expression is not a self attribute, or attribute is not variable, or variable is not partial, return None. N) rrrYrrsis_selfrscopeenclosing_classr;rdrr)r#rrrs rget_partial_self_varz&ExpressionChecker.get_partial_self_var]s tyy( +499>>3/ &&xx~~--/tyy 2jj# chh $CHHMM;)O88Orrrdiscard) builtins.listrzClassVar[dict[str, list[str]]] item_argsextendrCr builtins.dictr)rCrFzcollections.OrderedDictrz)ClassVar[dict[str, dict[str, list[str]]]]container_argsc`t|jtsy|j}t|jtrf|j |j}|y|\}}|j ||j|}|#||vr|jj|||yyyt|jtrlt|jjtrF|jjy|jj}|jj}|j |}|y|\}}t|j} | | j y|j ||j|} | |j#|} t$j&j)| |jj*r`| jJ| jj,} |jj/| | | g} |jj|| |yyyyy)z-Try to make partial type precise from a call.N)rrrVrr`get_partial_var&try_infer_partial_value_type_from_callr;rreplace_partial_typerQrurnindexget_partial_instance_typerrrqrris_valid_inferred_typerrnamed_generic_type)r#r.rretr8 partial_typesrrurL partial_typerrtypenamenew_types rrz(ExpressionChecker.try_infer_partial_types!((J/  fkk7 +&&v{{3C{!$ C==acRC3-#7--c3 F$8  Y /Jv{{?O?OQX4Y{{##/;;##DKK%%E&&t,C{!$ C4SXX>L#|'>'>'FDDQ UXYJ%;;u-<<66xAQAQR',,888+0099H#xx::8hPZE[\HHH11#xO S&5Z /rc|j}|!t|tr|j|}t|tsy|j j |}|y||fSr)rrrVrArsrfind_partial_types)r#refr8rQs rrIz!ExpressionChecker.get_partial_vars^hh ;:c:6++C0C#s#33C8  M!!rcfjjryt|j}|y|jr!|jjj }n$|jJ|jj }|j vr|j |vr|jtgk(rpj|jd}tjj|jjrjj||gSy|j vr|j |vr|jtgk(rt#j|jd}t%|t&rx|jj }|j ||vrMt)fd|jDr/jj|t+|jSyt%|t,rjj/|Sy)zCTry to make partial type precise from a call such as 'x.append(y)'.Nrc3K|]8}tjj|jj:ywr)rrrNrr)r item_typer#s rrzKExpressionChecker.try_infer_partial_value_type_from_call..s4% ;;ItxxGWGWXs>A)rcurrent_node_deferredrMrrrrDrr5rqrrrrNrrOrGrrrrrrrM) r#r. methodnamer8rRrSrZarg_type arg_typenames ` rrJz8ExpressionChecker.try_infer_partial_value_type_from_calls 88 ) )0:    " "#..33<N>NOxx228i[II$! ++ +d11(;; y(&t{{166!9'=>H(H-'}}55 4#6#6x#@#LL)1 $xx::8T(--EXYYHg.xx**844rc t|j} t| D cgc]} g} } t| D cgc]} g} } t| D cgc]} g}} t| D cgc]} g}} t|D]\}}|D]u}| |j ||| |j |||r||j ||n||j d||j ||w|V|j j |}|J|t| ||j||j| | |jS|j j|}|Jt|}|t|| ||j||j| | |j Scc} wcc} wcc} wcc} w)aUse special case logic to infer the return type of a specific named function/method. Caller must ensure that a plugin hook exists. There are two different cases: - If object_type is None, the caller must ensure that a function hook exists for fullname. - If object_type is not None, the caller must ensure that a method hook exists for fullname. Return the inferred return type. N)rrcallee_arg_namesrdefault_return_typerr^api) rrrr`rrarr^rb)rrr enumeraterrget_function_hookrwrr?rget_method_hookrry)r#rrrrrrrrRr^ num_formalsrformal_arg_typesformal_arg_exprsformal_arg_namesformal_arg_kindsformalactualsactualcallbackmethod_callbacks rapply_function_pluginz'ExpressionChecker.apply_function_plugins.&**+ :? :L-MQb-M-M@Ek@R3S1B3S3S@Ek@R3S1B3S3S=B;=O0P0P0P()9: COFG! C (// &0AB (//V =$V,33If4EF$V,33D9 (// &0AB C C  {{44X>H' ''..%+%5%5.(.)#   #kk99(CO". ..)+6K"$..%+%5%5.(.)#   G.N3S3S0Ps F= G G+ G ct|trt|j}t |||j|j fd}t |Dcgc]}g} }t|D]#\} } | D]} | | j| %|| |St|tsJg} |jD]:}j||||}t|tsJ| j|<t| Scc}w)z@Helper to apply a signature hook for either a function or methodc,j|Srrqrrr#s rrz8ExpressionChecker.apply_signature_hook..5$++d1g.r) rrrrrrrrcrrrapply_signature_hook)r#rrrrhookrfrrrhrkrlrmrradjusteds` ` rrvz&ExpressionChecker.apply_signature_hook%s% fl +f../K5    .   EJ+DV7Wq7W 7W#,-=#> B%BF$V,33DLAB B(&1 1fj1 11E  '44T4IW[\!(L999 X& 'e$ $8Xs D c <j||||fdS)zKApply a plugin hook that may infer a more precise signature for a function.c@t||jSr)rxr)rsigr^r#signature_hooks rrzAExpressionChecker.apply_function_signature_hook..Ts~.@sGUYU]U].^_r)rv)r#rrrr^rr|s` ` `rapply_function_signature_hookz/ExpressionChecker.apply_function_signature_hookEs'((     _   rc Vt|j||||fdS)zIApply a plugin hook that may infer a more precise signature for a method.c Bt||jSr)rzr)rr{r^ pobject_typer#r|s rrz?ExpressionChecker.apply_method_signature_hook..is .$\4gtxxP#r)rrv) r#rrrr^rrRr|rs ` ` `@rapply_method_signature_hookz-ExpressionChecker.apply_method_signature_hookWs3'{3 ((      rc t|}|{t|trk|6|jj |}|r|j |||||||S|S|jj |} | r|j|||||| S|S)a6Attempt to determine a more accurate signature for a method call. This is done by looking up and applying a method signature hook (if one exists for the given method name). If no matching method signature hook is found, callee is returned unmodified. The same happens if the arguments refer to a non-method callable (this is allowed so that the code calling transform_callee_type needs to perform fewer boilerplate checks). Note: this method is *not* called automatically as part of check_call, because in some cases check_call is called multiple times while checking a single call (for example when dealing with overloads). Instead, this method needs to be called explicitly (if appropriate) before the signature is passed to check_call. )rrrrget_method_signature_hookrget_function_signature_hookr}) r# callable_namerrrr^rrRmethod_sig_hookfunction_sig_hooks rtransform_callee_typez'ExpressionChecker.transform_callee_typeos0!(  $FL)I&"&++"G"G "V";;i)[Ra %)KK$K$KM$Z!$==i)EV rc|jsJt|jdk7st|dk7rytt |jdt sytt |j t sy|jj5|jj5t |j|dd}ddddddttr|Sy#1swY$xYw#1swY(xYw)zSCheck if this looks like an application of a generic function to overload argument.rNrr) r rrrrrr?rr1rrPrqr)r#rrr]s r"is_generic_decorator_overload_callz4ExpressionChecker.is_generic_decorator_overload_calls$$$$ {$$ % *c$i1n/+*?*?*BC\R/+*>*>?N XX $ $ T'') T*4;;tAwT;+RS T T h +O  T T T Ts$D2 C5D5C> :DD cg}g}|jD]}t|}|jj5}|j ||gt g|\} } dddj r`t } t| ts|t } t| ts|j| |j| |r|syt|t|fS#1swYxYw)aType-check application of a generic callable to an overload. We check call on each individual overload item, and then combine results into a new overload. This function should be only used if callee_type takes and returns a Callable. rN) rrirrP check_callr5has_new_errorsrrrrr) r#r overloadedrKr/ inferred_argsrr err item_result inferred_arg p_item_resultp_inferred_args rhandle_decorator_overload_callz0ExpressionChecker.handle_decorator_overload_calls $$ )Dt$C'') `S,0OOK#QXPY[^,_) \ `!!#+K8Mm\:,\:Nnl;   0 MM- ( )]&!:m#<<&>#$$0#0#8#8 rcg}|jD]}|jj5t|||ddd||j|j | }ddd|j |jd}|t|j||}|r|nd} |j|j|||| t|S#1swYrxYw)zFType check calling a member expression where the base type is a union.F)rTis_super is_operator original_typerin_literal_context self_typeNT)skip_non_overlapping) rrrPrrrZr,rrrrr) r#r.rRrresrrr0ritem_object_types rrz'ExpressionChecker.check_union_call_exprs--/ C'') ,#" %"-'+'>'>'@!  33AHHdY]3^H 00f=M&3s  JJ55h=Rbc ) .%S))+  s .CC c Ht|}t|trO|jr+|j ||} | |j || |} | | S|j ||||||||St|tr|j|||||||St|ts|jjs|j||St|tr|j|||||St|trt!d||ddd| xs||j|j# } |j$j&dz}|j)|| |||||} |j+| |||||||} |r|jj-||| St|t.r |j+|j0|||||St|t2r2|j5|j6|}|j+||||||St|t8r#|j+t;||||||||| St|t<rt=}|j>|_||fS|j@jC||ttDjFfS)aType check a call. Also infer type arguments if the callee is a generic function. Return (result type, inferred callee type). Arguments: callee: type of the called value args: actual argument expressions arg_kinds: contains nodes.ARG_* constant for each argument in args describing whether the argument is positional, *arg, etc. context: current expression context, used for inference. arg_names: names of arguments (optional) callable_node: associate the inferred callable type to this node, if specified callable_name: Fully-qualified name of the function/method to call, or None if unavailable (examples: 'builtins.open', 'typing.Mapping.get') object_type: If callable_name refers to a method, the type of the object on which the method is being called rFTrTrrrrrz .__call__)r)$rrrr rrr2rcheck_overload_callrrr9check_any_type_callrcheck_union_callrrrZrrrr store_typer upper_boundranalyze_type_type_calleerrrrrr not_callablerr<)r#rrrr^rrrrRrroverloaded_result call_functionr/rrPs rrzExpressionChecker.check_calls@!( fl +!DDVTR ))-(K(K G)%)400++   +++iM;PW  (0L0L0N++D&9 9  *((y)WU U  )1 +5vHH#'#:#:#< M#KK00;>M 66}dIw SYM__ F##M6:M  ,??""D)Wi  )00gFD??4y'9m\ \  *??v&$#   0!#C",,CM3; 88((979CWCW;XX Xrc z |jj}||jr |j}t|j} |j r&t | tr| jj}t |tr |jtvr|j|fS|j rx|jjr^|jsRjj!t"j$j'|jj|n|j r|jj(r|js|jj*s|j} i} | j,D])\} } | t.k(rj1| | | | <%d| | <+j2j5|jj| ||j7}|rt |j8t:rd}t=|D]\}}|t>k7rtjA|}t |tBrtEd|jFDsW|rIj2j!d|tHjJtMtNjP|fcSd}t|j} t | tRr>| jTr2tW|j}tY||j[|}|j]rt_|}ja||}tc|||jd|jffd}|j]r\tEd|jTD}ji||||||}|r'tc|||jd|jffd }|jk}||t>tlgk(rto|d k(rjAd }jAd }t |tprt |tprt|jrttjvk(rW|jrttjxk(r:|jz|jzcxk(r|jzk(rnn|j|fSj}|||}j||||||||j|||||| |j r[to|d k(rMt|jjdr(|j[tj|d }|rjj|||re|jj|s|Fjj|r+j|||||||| }|j[|}|j|fS)zxType check a call that targets a callable value. See the docstring of check_call for more information. Fc3<K|]}t|tywrrrrrs rrz8ExpressionChecker.check_callable_call..s>23Jq*->rz.sdkk$q'*rc3HK|]}t|ttfywr)rrrrvs rrz8ExpressionChecker.check_callable_call..s"EF 1}.>?@s "c,j|Srrsrts rrz7ExpressionChecker.check_callable_call..sdkk$q'2rrrrrRr)Jwith_unpacked_kwargswith_normalized_var_argsr;rr?rrrrrr`r|rrfrom_type_typerrrCANNOT_INSTANTIATE_PROTOCOLr is_abstractfallback_to_anyabstract_attributesr8can_return_noner!cannot_instantiate_abstract_classvar_argrrrr6rqrrrrCALL_ARGrrr<rr r(r copy_modified is_genericr)+infer_function_type_arguments_using_contextrrrr+ param_specr7rrflavorrARGSKWARGSidinfer_arg_types_in_contextcheck_argument_countcheck_argument_typesrrMrmake_normalizedrrrdrerp)r#rrrr^rrrrRr?rr attr_nameabstract_statusr seen_unpackr arg_kindr]fresh_ret_typer need_refreshrarg1arg2r new_ret_types` ` rr2z%ExpressionChecker.check_callable_calls ,,.GGI  V[["KKM"6??3    Jx$B$MM22M mW --2H2HJ2V??F* *    ""$00)) HHMM <<CCFDVDVDXD]D]^     ""$00))&&(88%%'D46 .2.F.F ;* ?"&99595I5I$PY5Z' 25:' 2  ; HH 6 6""$))+> .." z'++z: K!$T9!5 ' Xx'*4;;s+;<!(I6#>7?~~>;# Z#!&& 'y';';)BF    /7FEEfgVF1         *      JPJZJZL77i4DlT[F$:$$$$2 $ &&(  "h 22$%*;;tAw'D;;tAw'D4/t]3KK?#7#77KK?#9#99GGtww7*--7..33FD)M]^  !!          !! y$0@'Wb "    Y1$foot/OP))83K3KIVWL3Y)ZF  HH   v 6   T[[%B%B=%Q'DKK,G,G ,V55  L))<)@F&&rctjsy|jD]}|jj |}|!|j }t |tr |j}t |tr |j}t |tsv|jt |jtsJtt|jj cSy)zIs the given attribute a method with a None-compatible return type? Overloads are only checked if there is an implementation. F)r}strict_optionalmrordrrrr\implrHfuncrOrrrrr?)r#rrrusymnoders rrz!ExpressionChecker.can_return_noneFs $$HH FDjjnnY/G<>>%hj$))2D2DEE Frc t|trttj|St|trrt |j |j}t|tr|jd}t||}t|tr|jg}|St|trKt|jDcgc]}|jt||c}|jSt|t r|jt|j"|}t|}t|tr|j|}|St|t$r3t%|j&Dcgc]}|j|c}}|St|t(r=t+|j j,dk7r|jt+||St|t.r|j1|S|j2j5||ttj6Scc}wcc}w)zzAnalyze the callee X in X(...) where X is Type[item]. Return a Y that we can pass to check_call(Y, ...).  source_anyT)r)r rbuiltins.tuple)rrrfrom_another_anyrrrrMrrr'rrrrr@rrrrrrrrrrunsupported_type_typer<)r#rr^rexpandedrrcs rrz*ExpressionChecker.analyze_type_type_callee^s dG $955$G G dH %"499doo>C#|,''t'<.sD9H(L1$11B1?O dI &#11311/"2EwO   dK ( 22?4CSCS3TV]^F$V,F&,/--t-<MFJ/#V\\$ZQ__d_%C$Z[M dI &>$+?+D+D+M+MQa+a001EwO O dM *77= = &&tW5y++,,3 %[s "IIcg}|D]I}|j|}t|r|jt9|j|K|S)zInfer argument expression types in an empty context. In short, we basically recurse on each argument without considering in what context the argument was called. )rqhas_erased_componentrr)r#rrr r]s r infer_arg_types_in_empty_contextz2ExpressionChecker.infer_arg_types_in_empty_contextsO  %C{{3'H#H- 8:& 8$  %  rcRtj}t|r dt_|S)axAdjust type inference of unions if type context has a recursive type. Return the old state. The caller must assign it to type_state.infer_unions afterwards. This is a hack to better support inference for recursive types. Note: This is performance-sensitive and must not be a context manager until mypyc supports them better. T)r infer_unionsr)r#rolds r$infer_more_unions_for_recursive_typez6ExpressionChecker.infer_more_unions_for_recursive_types$%% | ,&*J # rcdgt|z}t|D]c\}}|D]Y}||jr|j|} |j | } |j ||| ||<| t _[et|D]\}} | r |j ||||<!td|DsJttt|S)aInfer argument expression types using a callable type as context. For example, if callee argument 2 has type List[int], infer the argument expression with List[int] type context. Returns the inferred types of *actual arguments*. Nc3$K|]}|du ywrr)rrs rrz?ExpressionChecker.infer_arg_types_in_context..s0b2T>0s) rrcis_starrrrqrrrrrr) r#rrrrrrrlair]rrs rrz,ExpressionChecker.infer_arg_types_in_contexts#'#d)!3#$45 2JAw 2 },,.%//2H CCHMC"kk$r(H=CG.1J+ 2 2cN .DAqT!W-A .0C0000DJ$$rcz|jd}|s|St|t}|j}t |r!t |rt |}t |}t |}t|ts,t|trBtd|jDr&t|st|s|jSt|j ||d}g}|D];} t#| s t%| r|j'd+|j'| =|j)|||dS)a Unify callable return type to type context to infer type vars. For example, if the return type is set[t] where 't' is a type variable of callable, and if the context is set[int], return callable modified by substituting 't' with 'int'. r3c3NK|]}tt|tywr)rrr)rus rrzPExpressionChecker.infer_function_type_arguments_using_context..sZAJq1;?Zs#%Tskip_unsatisfiedN)rr"rr?rrrrrrrrrrrr,r has_uninhabited_componentrrapply_generic_arguments) r#callable error_contextrK erased_ctxr? proper_retrnew_argsr s rrz=ExpressionChecker.infer_function_type_arguments_using_contexts,#O 'sJL9 $$ x (-@-E'x0H(4J%X. z; /*i0ZIYIYZZ2's+4H4M--//#   *t ') %C(-1Ec1J%$  %++ h ,  rc jjrjj5j ||}dddj |t } g} t|D]0\} } | | dkDr| jd | j| 2t| |||jjj\} }d| vrj|||| ||\} jdk(rt | dk(rt|vst|vrt| d}t!|t"t$frj'd| d<nG|rt)j'd|s*jj+t,j.|jj0j2sTt5fd| Dr?|r't7||j8j:fd }t||||jjjd \}}j=||}t?j@||}|tCd |Dr tE||St%}d |_#|Dcgc]A}|;tI|tKjL|zDcic]}|jN|c}ndC} }}n0tQtRjTgt jLz} jW| |S#1swYxYwcc}wcc}}w) zInfer the type arguments for a generic callee type. Infer based on the types of arguments. Return a derived callable type that has the arguments applied. Nr)r^strictrdictr builtins.strc3K|]O}|duxsEtt|txs*tt |tj zQywr)rrrrcrr )rrrs rrzBExpressionChecker.infer_function_type_arguments..ss]?T Foa0/BF}Q'(3{/D/D+EEF?sAAc,j|Srrsrrr#s rrzAExpressionChecker.infer_function_type_arguments..s$++d1g"6rT)r^rallow_polymorphicc3\K|]$}|duxrtt|t &ywr)rrrrs rrzBExpressionChecker.infer_function_type_arguments..s3/TMY*_Q5G*Y&YY/s*,),rr9rrPrget_arg_infer_passesrrcrr+argument_infer_context#infer_function_type_arguments_pass2 special_sigr4r7rrrrrMrrr&KEYWORD_ARGUMENT_REQUIRES_STR_KEY_TYPErrrrrrrr apply_polyrrrr&rr rrr unannotatedapply_inferred_arguments)r#rrrrrrr^r arg_pass_nums pass1_argsrr rr first_argpoly_inferred_args free_varspoly_callee_typeappliedunknownrrs``` rr+z/ExpressionChecker.infer_function_type_arguments&sh 88 ' ' ) '')  ;;y2B   !55T9.>D M-/J#I. +3 #a'%%d+%%c*  + = 335xx335  M1M!/3/W/W$!  0,m''61 &!+)+yI/E,M!,<= i(O)DE'+~'FM!$"*T__^5TV_*`HHMM"2"Y"Y[bc88##663?' ?<  (>!!#--#--6 ($1N$ 77988779&* 1-"I$(#?#?!3W$ $../?K&3///,)1"N)+$(!0 !=$tK.rurr$)rrcrrrrrrrrrrrrPrr+r )r#rrrrrold_inferred_argsrr^rrr rrs` ` rr z5ExpressionChecker.infer_function_type_arguments_pass2s2./  0 ?@ (FAs#/:;?STW?X#' a  (22; wW %%'? " 5%%%%.   XX # # % 77T9.>I  9     //1   qM))  s ;C>>Dc|jCt|jjd|jjd|_|jS)Nrtyping.Iterable)rr*rrMr's rr z(ExpressionChecker.argument_infer_contextsN  ( ( 0,@##$45txx7J7JK\7]-D ),,,rc dg|z}t|jD]\}}d} t|j|} t| tr| j ry||D]q} t|| } t| t rtd| | d} | t| } t| tsN| jr[t|| trod} n| r|jts||D]} d|| < |S)aReturn pass numbers for args for two-pass argument type inference. For each actual, the pass number is either 1 (first pass) or 2 (second pass). Two-pass argument type inference primarily lets us infer types of lambdas more effectively. rFrT)rr) rcrrrrrrr~r rSrqArgInferSecondPassQuery)r#rrrr num_actualsrrr skip_param_specp_formalrp_actual call_methods rr z&ExpressionChecker.get_arg_infer_passess  cK 0 01 FAs#O&v'7'7':;H(L1h6I6I6K)!,A.y| ?#mBT T  U++KPPrc |"tttj}i} |D]!} | D]} | j | ddz| | <#|j |||| |\} } t |jD]Q\}}||}|jr|s~| s||jr9|jj||||rJ|rHd|vrD|j|||n0|j|xsd}|jj|||d} |jsht!||r[|j"j%s t't)|dt*s|jj-|||d} |j/rJ|rH||dt0j2t0j4fvr |jj7||d} n|j9|s0|j:dk7r!|jj|||d} t=|dkDst?fd|D}||dt0j@k(r#|dkDr|jjCd|d} ||dt0j4k(s-|dkDs4|jjCd |d} T| S) aOCheck that there is a value for all required arguments to a function. Also check that there are no duplicate values for arguments. Report found errors using 'messages' if it's not None. If 'messages' is given, 'context' must also be given. Return False if there were any errors. Otherwise return True rrr?Fpartialc3VK|] }tt|t"ywr)rrr)rk actual_typess rrz9ExpressionChecker.check_argument_count..| s),#?<?#C]S,s&)z)ParamSpec.args should only be passed oncez+ParamSpec.kwargs should only be passed once)"rirrr5r check_for_extra_actual_argumentsrcr is_required is_positionalrtoo_few_argumentsmissing_classvar_callable_notermissing_named_argumentris_duplicate_mappingrr9rrrduplicate_argument_valueis_namedrr4r7too_many_positional_argumentsrr rsumr6r)r#rr/ actual_kinds actual_namesrr^rRr all_actualsrlrokis_unexpected_arg_errorrkind mapped_argsargnameparamspec_entriess ` rrz&ExpressionChecker.check_argument_count8 s$ ?wy'='=>?G ') ' ;G ;!,A!6!: A ; ;'+&K&K L, k7' # # !!1!12* #GAt*1-K!+>U%%'HH..vw M"} 9M;;KX_`$..q18SGHH33FGWM\\^(<\<)88//1Z#LQ$@A96HH55faIB  Q0%//8ZZ66vwG""$0"v'9'9Y'FHH..vw MB%)(+,!,,)%$KN3u~~EJ[^_J_ &QSZ["#KN3uFK\_`K` &SU\]"U* #V rchd}d}t|D]\} } | |vr| tjk7st|| r}| tjk7rjd}| tj k7r|j j||q|sJd|| } | J|| } |j j|| | |d}| tjk(rtj|jvs| tjk(st|| } t| ttfs|j| dt| j ks<| tjk7st| ts|j j||n|j j#|| |d}d}||fS)zCheck for extra actual arguments. Return tuple (was everything ok, was there an extra keyword argument error [used to avoid duplicate errors]). FTz/Internal error: named kinds without names givenr)rcrr6is_non_empty_tupler7r4rtoo_many_argumentsunexpected_keyword_argumentrrrrrrrr"too_many_arguments_from_typed_dict)r#rr/r;r<r=r^r?r>rr@act_nameact_type actual_types rr0z2ExpressionChecker.check_for_extra_actual_arguments s#(  .% #GAt$'+=l1o+N'5??*HH//@'Z)ZZ<+AH#///+AHHH888U\].2+&5>>AQAQ+Q(-l1o> kI}+EF"q!,s;3D3D/EE5??2*[R_:` HH77H HHGG & W7;3"K% #R***rct|trt|tr|jdd\}}|jj |}|jt|j trO|j js8|j js!|jjd|d|yyyyyyy)Nrr)maxsplitr'zN" is considered instance variable, to make it class variable use ClassVar[...]) rrrrrrrrsr is_classvarrnote)r#rRrr^rvar_namers rr4z0ExpressionChecker.missing_classvar_callable_note s k: .:k83T'..sQ.?KAx##''1DJtyy#$>yy,,TYY5J5JHHMMH:&GG6K,%?4U .rc J |xs |j}t|j} t||D]\} } t | } | t j k(r-|j| s|jj| || t jk(se|j| rwt| |jjd} |jj| | |t!|D]\} }t |j"| }d}|Dcgc]}|| }}t%|dkDrAt ||d}t'|t(rt%|j*dk(rt'|j*dt,r|t j gt j.gt%|dz zzk(r|j*dg|ddDcgc]}|| c}z}t'|t,r}t |j0}t'|t(rX|j*sJ|j*}t j gt j.gt%|j*dz zz}d}|sK|Dcgc]}|| }}t'|t,rt |j0}t'|t(r_t3|j*}|!|j*}t.gt%|z}n|j*|}t'|t,sJt |j0}t'|t4rH|j*}t7t%|j*D cgc]} | |k7rt.nt }} n| gt%|z}t%t%|cxk(rt%|k(sJJt%t%|k7rgt%|t%|kDr'|jjjA||n'|jjjC||dzt%|t%|k(sJt%|t%k(sJt|||||D]S\}}}}} | jE|||jF | t'|t,}!||!||||dz| dz||||| Uycc}wcc}wcc}wcc} w) zCheck argument types against a callable type. Report errors if the argument types are not compatible. The check_call docstring describes some of the arguments. _typeshed.SupportsKeysAndGetItemFrrNTr) allow_unpack)$ check_argrr rrrr6is_valid_var_argrinvalid_var_argr7is_valid_keyword_var_argrrrMinvalid_keyword_var_argrcrrrrrrr5rrrrrrrrrFr3expand_actual_typer)"r#rrrrrr^rTrRmapperr]r is_mappingrrlorig_callee_arg_typeexpanded_tuplerr; p_actual_typer/ p_callee_typecallee_arg_typescallee_arg_kinds unpacked_typeinner_unpack_index inner_unpackinner_unpacked_typermrK actual_kindcallee_arg_typecallee_arg_kindexpanded_actuals" rrz&ExpressionChecker.check_argument_types s"/  !?"%i"; P Hh&x0H5>>)$2G2G2Q((7;5??*43P3PQY3Z'dhh112TU 00:wO P$$45l JAw#263C3CA3F#G #N29:QIaL:L:7|a / '!*0E F }i8M//0A5"=#6#6q#9:F$(8EMM?cRYl]^N^;_(__$1$7$7$:#;U\]^]_U`>aPQy|>a#aL!"6 C(78L8Q8Q(R %mY?#0#6#66#6/ ! > >2J?$34H4M4M$NM!-;-@ATAT-U*-5/+>?Q+RL#-lJ#GG#G2A,BSBS2T/)*=?OP4A3F3F 0.33}7J7J3K-L4"()014F/FGH$T4" 04" (22Ex'P P'P':'?'?'H'HL\'\ \'\$1$7$78K9K$L':'?'?'B&C'*7|c-:M:M6N'NQR'R'T%T'4&9&9:Lq:P:R&S%T!1 5<9s7|3K 0#M3CD,@+A(,4:()-BBB,11::>NNNN,9,>,>q,A+BS\+Q(,39s7|+C((<'=G 'L$(.(8(8(;'N>NOHH22$'+3 E&&(33(+wU48822455guzz5#Prc |j}j|}j||||} d} d} d} j|| } d}t fd|Dr j j 5j| ||||||| | }dddr`|Dcgc]}|d }}|Dcgc]}|d } }t||j|jjt| f} j| |||||||}|7| 5t|d| dr!t!t#|dt$s| sd} nd}| M| I| D]D}t!t#|x}t&sj(j+|j,|F| S|Ft!t#|dx}t&r&j(j+|j,||Sj/| |||||} t1| dkDr| d}nVt%t2j4}t7|sd}nt8j:}j j=||||j?|||||||}|r,| s*j(jAtBjD||S#1swYxYwcc}wcc}w#t$rd}YwxYw) z(Checks a call to an overloaded function.NFc3@K|]}j|ywr) real_union)rr r#s rrz8ExpressionChecker.check_overload_call.. s9ts#9rrrTrrrR)#rrplausible_overload_call_targetspossible_none_type_var_overlaprrrPunion_overload_resultrr@rAcombine_function_signaturesrrinfer_overload_return_typerrrrrrwarn_deprecated definitionoverload_erased_call_targetsrrr<is_operator_methodrOPERATORno_variant_matches_argumentsrrrTOO_MANY_UNION_COMBINATIONS)r#rrrrrrRr^rplausible_targetserased_targetsinferred_typesunioned_resultnone_type_var_overlapunion_interruptedunioned_returnrreturnsinferred_resultr(rrtrr/s` rrz%ExpressionChecker.check_overload_call s,,.99$?  @@ y)V 59,037 !% C CIO` a! 9y9 9 XX++- %)%?%?)!!!%#- &N ""-;<qt+E?1-~a/@A"??13E#FP-!%"&  %)%3HM!}'E"E!|T00wGH" !  &q/ABB!LQ((w?" ":: y)Yg  ~  "*!,FY112F%m4~~ HH 1 1&)WSW 1 X     '#!  %: HHMM*FF P U  $=%C! )$(! )s6&K J4K ( K: K4J>9K KKc |dd}g}g}d}d} t|D]-\} } | tk(r || sd}| tk(s#|| r,d} /|jD]} t ||| j | j fd} |jj5| j|j| ng|j| ||| drQ|r| jr|j| n1| r| jr|j| n|j| ddd||zS#1swYxYw)aEReturns all overload call targets that having matching argument counts. If the given args contains a star-arg (*arg or **kwarg argument, except for ParamSpec), this method will ensure all star-arg overloads appear at the start of the list, instead of their usual location. The only exception is if the starred argument is something like a Tuple or a NamedTuple, which has a definitive "shape". If so, we don't move the corresponding alternative to the front since we can infer a more precise match using the original order.ct|}t|ttfxs(t|txr|j j Sr)rrrrrris_named_tuplers r has_shapezDExpressionChecker.plausible_overload_call_targets..has_shape. s>!#&CcI}#=>3)Echh.E.E rFTc|Srrrrs rrzCExpressionChecker.plausible_overload_call_targets..A s iXYlrNrrreturnbool)rr6r7rrrrrrPrrr is_var_arg is_kw_arg) r#rrrrrmatches star_matchesargs_have_var_argargs_have_kw_argr@rrs ` rr}z1ExpressionChecker.plausible_overload_call_targets sB$  ')+- ! Y 2 (ID#x #$(!y 3#'  ( >> ,C59cmmS]]DZ  '') ,>>#/ NN3'..Iy:JD)S^^$++C0)cmm$++C0s+! , ,  ,,g%%% , ,s B D22D; c g} g} g} ttt|} g} |D],}|j|jjusJ|jj 5}|jj 5}|j|||||||\}}ddddddj }|s| s!|jjfcSt}t|tr| j|n| j|| j| j|| j/| syt| | |||rt| r(|jj| d| d| dfSt| Dcgc] }t!|c}r:|jj| dt!| dt!| dfS|jt#t$j&||||||S|jj| d| d| dfS#1swYxYw#1swYxYwcc}w)aAttempts to find the first matching callable from the given list. If a match is found, returns a tuple containing the result type and the inferred callee type. (This tuple is meant to be eventually returned by check_call.) If multiple targets match due to ambiguous Any parameters, returns (AnyType, AnyType). If no targets match, returns None. Assumes all of the given targets have argument counts compatible with the caller. )rrrrr^rrRNr)rmap has_any_typerrrPr1rr store_typesrrrrany_causes_overload_ambiguityall_same_typesr rrr5)r#rrrrrrrRr^r return_typesrargs_contain_any type_mapsrwrwr? infer_typeis_match p_infer_types rrz,ExpressionChecker.infer_overload_return_typeW s\*')#% %'s<;<24 $ $C88txx||+ ++'') QXX,, +/??"!"+"+ '&3$/,;,(Hj  ++--H(HH((+#Z//.z: lL9NN<0NN3'##H-%%j1  #; $> *7L)YXa bl+$$Yq\2#Aq(999L ISC IJ$$Yq\2!,q/2J~a?P4QQQ"9#9#9:''#"/ +' HH 1 .?N1$55 5i    J!Js*&I=I I"I& I II# c hg}|D]*}|j||||||s|j|,|S)zReturns a list of all targets that match the caller after erasing types. Assumes all of the given targets have argument counts compatible with the caller. )erased_signature_similarityr) r#rrrrrr^rrs rrz.ExpressionChecker.overload_erased_call_targets sH')$ $C//9isGs#  $ rcR|r|syd}t|D]A}t|tst|jD]}t|tsd}AC|syt d|D}t |D]-tfd|Dstfd|Ds-yy)aHeuristic to determine whether we need to try forcing union math. This is needed to avoid greedy type variable match in situations like this: @overload def foo(x: None) -> None: ... @overload def foo(x: T) -> list[T]: ... x: int | None foo(x) we want this call to infer list[int] | None, not list[int | None]. FTc3FK|]}t|jywr)rrrrs rrzCExpressionChecker.possible_none_type_var_overlap.. sEaQ[[)Es!c3jK|]*}tt|jt,ywr)rrrrrrrs rrzCExpressionChecker.possible_none_type_var_overlap.. s*JK ?1;;q>:HE03c3jK|]*}tt|jt,ywr)rrrrrs rrzCExpressionChecker.possible_none_type_var_overlap.. s*MN ?1;;q>:KHr)rrrrrminrr)r#rrhas_optional_argr]r min_prefixrs @rr~z0ExpressionChecker.possible_none_type_var_overlap s!  (3 Hh 2(8 dH-'+$   E3DEE z" AO`Rc  rc <| tk\rtt|D]\} } |j| sn:|j ||5|j |||||||| } ddd | gSy|sZ|j ||5|j |||||||| }ddd%t t|dttfs|gSt|| }t |tsJg}|jD]I}|j}||| <|j||||||||| | dz }||j|Iyt}g}|D])}||vs|j||j!|+|S#1swY&xYw#1swYxYw)aAccepts a list of overload signatures and attempts to match calls by destructuring the first union. Return a list of (, ) if call succeeds for every item of the desctructured union. Returns None if there is no match. Nrr)rrrcr{type_overrides_setrrrrrrcopyrrErcrr)r#rrrrrrrRrr^levelidxrrdirect first_union res_itemsr new_arg_types sub_resultseenr/pairs rrz'ExpressionChecker.union_overload_result s, J  "), HCs#  ((y9 55%!  u %((y9 88%!  !*q *Y,@+x&in5 +y111 ..0 D%NN,M!%M# 33!%  J%  ,' ,(+u $D4 d# $ I  $  sFFFFctt|}t|txrt|j dkDSr)rrrrrr#rs rr{zExpressionChecker.real_unionL s1c"#y)Kc#2D2D2F.G!.KKrc#Kt|t|k(sJt||D]\}}||j|< d|D]}|j|=y#|D]}|j|=wxYww)z5Set _temporary_ type overrides for given expressions.N)rrr)r#exprs overridesrrs rrz$ExpressionChecker.type_overrides_setP s 5zS^+++UI. ,ID#(+D   % , .  .''- . .''- .s=A2AA2A//A2c,|sJdtd|DsttjSt d|}t |dk(r|dSt |\}}tt |djDcgc]}g}}t|dj}g}d}|D]} t |t | jk7rd}ntt|| jD];\} \} } | | k(r| jr| jr t|| <9d}n|rnNt| jD]\} } || j| |j| j t#|}|rAttj}|dj%||gt&t(gddg||d Sg}|D]}t#|}|j| |dj%||||d Scc}w) aLAccepts a list of function signatures and attempts to combine them together into a new CallableType consisting of the union of all of the given arguments and return types. If there is at least one non-callable type, return Any (this can happen if there is an ambiguity because of Any in arguments). zTrying to merge no callablesc3<K|]}t|tywr)rrrs rrz@ExpressionChecker.combine_function_signatures..f s>1:a.>rlist[CallableType]rrFTN)rrrr?r r)rrr?r r)rrrr5rr#merge_typevars_in_callables_by_namerrrrrcrr2r5rr?rrr6r7)r#r callablesr rr new_kinds new_returns too_complexrtrnew_kind target_kindr  union_returnr final_args args_listrTs rrz-ExpressionChecker.combine_function_signatures^ s?444u>>>9112 2-u5 y>Q Q<  C9M 927IaL. sPYZ[P\rNFc (t||styr)arg_approximate_similarityr) rtoriginal_ccaller_typervrrjrwrrRr^rks rrTz@ExpressionChecker.erased_signature_similarity..check_arg s.k;GHr)r^rTT)rtrrrrvr=rrrjintrwrrrrR Type | Noner^rGrkrGrNone)rrrrrPrrr) r#rrrrrr^rrTs ` rrz-ExpressionChecker.erased_signature_similarity s52 y&"2"2F4D4DF\ XX # # % ,, 9i9I4      #' !         ! %  #  "   % % # & E  F  sB B, B), B87B8c^tj|||jj||S)z=Simple wrapper around mypy.applytype.apply_generic_arguments.r)rrrincompatible_typevar_value)r#rrr^rs rrz)ExpressionChecker.apply_generic_arguments s000   HH / / -   rc*|j|t|}t|tr6ttj |ttj |fSttj ttj fS)Nr)rrrrrrr5)r#rrs rrz%ExpressionChecker.check_any_type_call sq --d3 ( fg & 22vF 22vF  9112GIr*)r@r+rqrrrr`rrWrdrsr>is_clsrr;rrZ) r#r.rTr*rrurr> member_types rrz0ExpressionChecker.analyze_ordinary_member_access s 66 ((+ +!KK$..KIM66D"& $(Z 8-L&*iioo#$(Z 3-G))++?tyy/?/?/#!+HH#'#:#:#<$7 K rc Zt|||ddd||j|j S)z}Analyse member access that is external, i.e. it cannot refer to private definitions. Return the result type. Fr)rrrZ)r#r base_typer^s ranalyze_external_member_accessz0ExpressionChecker.analyze_external_member_accessB s9%   ##668  rc2t|jdSNr3)rrr's rrZz$ExpressionChecker.is_literal_contextU s#D$5$5b$9::rc|j|}|jr t||S|dur:|j"|j t|||_|jS|dur:|j "|j t|||_|j S|j t||S)azAnalyzes the given literal expression and determines if we should be inferring an Instance type, a Literal[...] type, or an Instance that remembers the original literal. We... 1. ...Infer a normal Instance in most circumstances. 2. ...Infer a Literal[...] if we're in a literal context. For example, if we were analyzing the "3" in "foo(3)" where "foo" has a signature of "def foo(Literal[3]) -> None", we'd want to infer that the "3" has a type of Literal[3] instead of Instance. 3. ...Infer an Instance that remembers the original Literal if we're declaring a Final variable with an inferred type -- for example, "bar" in "bar: Final = 3" would be assigned an Instance that remembers it originated from a '3'. See the comments in Instance's constructor for more details. )rrT)r[F)rMrZrr!rr")r#r fallback_namers rr\z)ExpressionChecker.infer_literal_expr_typeX s"oom,  " " $US9 9}%%-),):):)453)O*;*D&)))~&&.*-*;*;)453)O+<+D'***$$kX[6\$] ]rct|jrt|jrJt|j|jz|jdS)z$Concatenate two fixed length tuples.r)rr)rrrrM)r#leftrights r concat_tupleszExpressionChecker.concat_tuples{ sI' 38KEKK8XYY**u{{*T__EU5V  rc:|j|jdS)z(Type check an integer literal (trivial). builtins.intr\rr#r.s rvisit_int_exprz ExpressionChecker.visit_int_expr ++AGG^DDrc:|j|jdS)z&Type check a string literal (trivial).rrrs rvisit_str_exprz ExpressionChecker.visit_str_expr rrc:|j|jdS)z%Type check a bytes literal (trivial).rrrs rvisit_bytes_exprz"ExpressionChecker.visit_bytes_expr s++AGG5EFFrc$|jdS)z%Type check a float literal (trivial).zbuiltins.floatrMrs rvisit_float_exprz"ExpressionChecker.visit_float_expr s/00rc$|jdS)zType check a complex literal.zbuiltins.complexrrs rvisit_complex_exprz$ExpressionChecker.visit_complex_expr s122rc$|jdS)zType check '...'.zbuiltins.ellipsisrrs rvisit_ellipsisz ExpressionChecker.visit_ellipsis s233rc |jr|j|jS|jdk(s|jdk(r|j|S|jdk(r+t |j t r|j|S|jdk(rt |j tr0|jj|j |jSt |j tr0|jj|j |jS|j|j }t|}t |tr|jdk(r|jj j#d}|r|j$dk(rt|j|j}t |tre|jj j#d}|Et'|j(t'|j(|j+||St,|j.j0j2vrt |t4r|j.j7|r|j j#d}||jj j$d k(rwt'|j(b|j.j9||}|j.j;d |g}|j=|j(t?|gz St@} |jd k(rtC|d r:t|j|j}t |tDrtF} t |tDr6t|j|j}tC|d rtH} t,|j.j0j2vr|jdk(rt |t4r|j j$d k(rt|j|j}t |tra|jj j$d k(r>t'|j()|j=t?|g|j(z S|jtJjLvrtJjL|j} | tNjPus| tNjRur4|jU| ||j|| tNjPu \} } nk| tNjVurN|jUtJjX| |j|j|j |d \} } n t[|  |_. St_d|j)z(Type check a binary operator expression.andor*%+__add__zbuiltins.tuple.__add____radd__r)r|rF)rr r^ allow_reverseFzUnknown operator )0rnrqopcheck_boolean_oprrrUcheck_list_multiplyrArcheck_str_interpolationrrfrrpartial_fallbackrrrrrrrvrrenable_incomplete_featurertype_is_iterableiterable_item_typerOrrrrrr r r op_methodsrrrcheck_oprreverse_op_methodsr method_type RuntimeError) r#r. left_typeproper_left_typeleft_add_methodproper_right_typeright_radd_methodrZr use_reversemethodr/rs r visit_op_exprzExpressionChecker.visit_op_expr s ::;;qzz* * 445=ADDDL((+ + 443;:affh7++A. . 443;!&&),**BB166177SS!&&'***BB166177SSKK' *95 & 2qtts{.??DDHHSO?#;#;?W#W$3DKK4H$I!/;(9(J(J(O(O(S(ST^(_%(000@0F0FGO23D3J3JKS#'#5#56FHY#ZZ'488+;+;+U+UU"#4h?112CD):(>(>(B(B:(N%)1,==BBKKO__/0@0F0FGO$(HH$?$?@QST$U !%! #6 443; !1?C%4DKK4H$I!/?"4K*M:%4DKK4H$I!$%6H"3K $(("2"2"L"L L /:$))226FF$3DKK4H$I!0)<)::??HHL\\+,=,C,CDL,::)*:; c == d' is check as 'a < b and b > c and c == d' Nrinznot inFTsave_filtered_errors __contains__)r'rrrr^rrI)original_containerprefer_literal container)r)z==z!=equalityiszis not)identity_checkidentityzUnknown comparison operator )(roperandsrrqfind_partial_type_ref_fast_pathrrrrr bool_typerrPcheck_method_call_by_namer5ranalyze_container_item_typerrrU-analyze_iterable_item_type_without_expression add_errorsfiltered_errorsrrrM method_typesrrrunsupported_operand_typesdangerous_comparisonrr$errorsrrr r join_types)r#r.r/rroperatorr! right_type item_typesrcontainer_typesiterable_types failed_outencountered_partial_typerZcontainer_errorsrr cont_typeiterable_errorsitertype iterable_typecontainer_typer'rs rvisit_comparison_exprz'ExpressionChecker.visit_comparison_exprs #&)QZZ^Q[[%QF = !D% D)I48x#7"AA%H %!%U!3J,Z8 .8\ j)4!%j&?&?&A!BJ!^^- .0-/" +0(!+3*I//T/J TN^)-)G)G#1&/"&'.i$%*4 *H*;%)HH$H$H$S  T")[9370(779--i8"XX333NRa*.((*`*` )1+KAx+99; HH//0O0O0QR)-J*6!* !&!% $ 0 $0C D +KNN11+>*11(;-<<>9'..y9--k:++,<,L,L,NO%) g3*j0 $-$8$8$HM%i?. HH>>tYPZ\]^-6-A-A/-RN#88 ) .3=/4 9  !% = =$-~{A!"Y111"--h7!$((//27a.2mm 5!4/</+J NN))+6 7'')h,.F!%U!3J00JG$7 $B %8%D 55iZYZ[T!X%9![[/ !^^- ,,Y SW,X 3I >I!4Z!@JHH11)ZUVW%%d+"%A(#LMM~#<MF =P!!! S T T4X77s$* T 5TT T T$ ct|tsyt|jtr_|j |j|}t|t r3|j '|jj|t||Sy)zIf expression has a partial generic type, return it without additional checks. In particular, this does not generate an error about a missing annotation. Otherwise, return None. N) rr`rrsr6rrrrr)r#rr/s rr6z1ExpressionChecker.find_partial_type_ref_fast_pathsj$( dii %))$))T:F&+.6;;3J##D* 88   4 4$)j.I h ':eX+F dI &:eY+G"4(D#E*E*D%=9KD% #$67#D)  dH %*UH*E **I,,J88"==#xx778LM 0|D1%F00IIaL%**Q-J1##$45%**:M:MN^:_#xx778HI 0|D1%F00IIaL%**Q-J1c..tyy|UZZ]Wa.bcAAjT]F]00IIaL%**Q-J199j+? dK (Z{-K$**d+ 5;;0M dK (Zx-H}}!!**.>>5::CVCV$D e[ )jx.H~~""++/??DIIDVDV$E'euMMMrc |xs|}|xs|}t|}t|tr|j||||||St |||ddd|||j |j  }|j||||||S)a Type check a call to a named method on an object. Return tuple (result type, inferred method type). The 'original_type' is used for error messages. The self_type is to bind self in methods (see analyze_member_access for more details). FT)rTrrrrrr)rrrcheck_union_method_call_by_namerrrZcheck_method_call) r#r'rrrr^rrrs rr8z+ExpressionChecker.check_method_call_by_name/s &2 * #I. i +77 4G] ,   '#668  %%fidIW^__rc 4g}g}|jD]`} |jj5|j|| ||||\} } ddd|j  |j  bt |t |fS#1swYCxYw)aType check a call to a named method on an object with union type. This essentially checks the call using check_method_call_by_name() for each union item and unions the result. We do this to allow plugins to act on individual union items. N)rrrr8rr) r#r'rrrr^rrmeth_resrr meth_items rr^z1ExpressionChecker.check_union_method_call_by_nameVs!++- 'C,,. "&"@"@Cy'=#i  JJt  OOI & '%S)+@+JJJ   s BB c|j||}||nd}|j||||||}|j||||||S)zType check a call to a method with the given name and type on an object. Return tuple (result type, inferred method type). Nrr|)rrr) r#rrrrrr^rrRs rr_z#ExpressionChecker.check_method_callrsp,,Y D #0#ExpressionChecker.check_op_reversible..lookup_operators  7DOOD'') >Q. !#" $"+#'+'>'>'@  !//1tv > > >s AA>>Bc|jjD]+}|jj|s|jcSy)aReturns the name of the class that contains the actual definition of attr_name. So if class A defines foo and class B subclasses A, running 'get_class_defined_in(B, "foo")` would return the full name of A. However, if B were to override and redefine foo, that method call would return the full name of B instead. If the attr name is not present in the given class or its MRO, returns None. N)rrrdrr)rrclss rlookup_definerz=ExpressionChecker.check_op_reversible..lookup_definers:xx|| (99==+<<' (rrTr+rr)rfrrrrr)rrrrr str | None)rrrrrrrop_methods_that_shortcutrrrr alt_promoterrPr_r5rrr<rr5r8r;rr<)r#rfr! left_exprrC right_exprr^rgrjany_type rev_op_nameleft_opright_op variants_rawnarobjr variantsr@rr;r' local_errorsr/ error_anys` ` rcheck_op_reversiblez%ExpressionChecker.check_op_reversiblese >,  $I. $Z0 i )y99iPHX% % j' *y99jQHX% %  227; !'95"; ; i88 8\)U_=`%gy*EFL z9 -9h/:x0**6NN..33zFy'2nZQ\6]]h I>'9j9L'9j9h I>LBN``+=BCQSQ_RS#&``&.  "D&#s''T'B ^l//c6C57)U\] ^**, l::<=v&   y( + 0N0N z8 ,1P1Py556HX% % ''T'B l77Y wi  **, l::<=v&  F1I& w<1 1:  4 45I )FMga ^ ^,  s$. M ;M 2M#$M0#M- 0M9c |r|g}t|}t|tr"tt |j }|j |}g}g} |jj5} |D]I} |j|| t| ||||\} } |j| | j| K ddd jst|}t| }||fS||fg}t|}t|tr3t |j Dcgc]}|t||f}}g}g} |jjd5} |D]S} |D]L\}}|j|| t| ||||\} } |j| | j| NU ddd| jr|jj| j| jd}tt!}|j"|_|j$|_t'|dk\r*t'|dk\r|jj)|nYt'|dk\r|jj+d||n,t'|dk\r|jj+d ||t|}|j-t/| }||fS|j1|||gt2g| S#1swYaxYwcc}w#1swYtxYw) zType check a binary operation which maps to a method call. Return tuple (result type, inferred operator method type). r$)rfr!rnrCror^NTr+r3rLeftRight)r'rrrr^)rrrrrrrqrrPrzrirrrr;r<rr@rAr"warn_both_operands_are_from_unionswarn_operand_was_from_unionrrr8r5)r#r'rr r^r left_variantsrC all_results all_inferredrxleft_possible_typer/r results_finalinferred_finalright_variantsrright_possible_typerorrecent_contexts rrzExpressionChecker.check_op@sS &KM' 2I)Y/ $%:9;S;S;U%V W S)J KL'') 2\*7 2&'+'?'? &"4"*+=w"O#-#& ' (@($FH &&v. ''1 2 2 ..0 5k B !6|!D$n44 *3/0N(4J*i0!6j6O6O6Q R"8D':;"" KL''T'B 6l*7 6&;I 67+Z+/+C+C$*&8&./A7&S':'1$+ ,D,($**62$++H5 6 6 6**,##L$@$@$BC"224R8!)(*!5&)hh#(+ %}%*s>/Ba/GHH??O'1,HH88Tb8c(A-HH88^92+>M!==>N|>\]N .0 011#U") 2 [ 2 2@" 6 6s 3AL"0L/(AL4"L,4L>c|jd}|j|j|}t|d}|jdvsJ|j rd}i}n|j rid}}no|jdk(r)|jj|j\}}n7|jdk(r(|jj|j\}}tj|jjjvr><|j s0|jj|j|j|jjr><|j s0|jj!|j|j"|j%|j"|j'|} | t)S||J|S||J|S|jdk(rt+|}|j, } n'|jdk(rt/|}|j0 } t3t(r|S r|St5||gS)z/Type check a boolean operation ('and' or 'or').r3rY)r r Nr r )rrqrrr right_alwaysright_unreachablerfind_isinstance_checkrREDUNDANT_EXPRrenabled_error_codesrredundant_left_operand should_report_unreachable_issuesunreachable_right_operandranalyze_cond_branch_combined_contextrr can_be_truer can_be_falserr) r#r.rKr!expanded_left_typeleft_map right_maprCrestricted_left_typeresult_is_lefts rrz"ExpressionChecker.check_boolean_ops"#KK, >-1H.0I  "$diH TTU]"&(("@"@"H Ix TTT\"&(("@"@"H Hi  DHH$4$4$H$H H NN HH + +ADD!&& 9 HH 5 5 7!'' HH . .qttQWW =-- qww 6 67I J    1"$ $  ' ''   ( ((  445=#-.@#A !3!?!??N TTT\#,-?#@ !3!@!@@N *O <   (*> )KL LrcN|j|j}t||jdr+|j|j|j d}n|j|j}|j d||j|\}}||_|S)zzType check an expression of form '[...] * e'. Type inference is special-cased for this common construct. rr3r__mul__)rqrrrMrrrr)r#r.rCr!r/rs rrz%ExpressionChecker.check_list_multiplys [[) j$//."A B AFF9J9J29N OI AFF+I"mmIy!''1M #  rcj|j|j}|jj|j|j|jj |t |s&|jj|j||j|j|Sr) rqrrcheck_assignmentrt check_finalrrr6)r#r.rs rvisit_assignment_exprz'ExpressionChecker.visit_assignment_expr s{ AGG$ !!!((AGG4 Q(/ HH  % 0 ,,QXX6 rc2|j|j}|j}|dk(r8|j}|jj ||j|St j|}|j||gg|\}}||_ |S)z7Type check an unary operation ('not', '-', '+' or '~').not) rqrrr7rcheck_for_truthy_typerunary_op_methodsr8r)r#r. operand_typerr/r'rs rvisit_unary_exprz"ExpressionChecker.visit_unary_exprs{{166* TT ;>>+F HH * *< @  //3F"&"@"@WY[]_`"a FK'AM rc|j|}|j||}t|}|jr(t |t r|j |j }|S)zgType check an index expression (base[index]). It may also represent type application. )visit_index_expr_helperr,rrZrrr[)r#r.r/p_results rvisit_index_exprz"ExpressionChecker.visit_index_expr"sb --a0--a8"6*  # # %8X.))5..F rc|jr|j|jS|j|j}|j||Sr)rnrqruvisit_index_with_type)r#r.r!s rrz)ExpressionChecker.visit_index_expr_helper2sA ::;;qzz* *KK' )))Q77rc |j}|xs|}t|}|j|t|tr(t d|j Dr t|i}t|tr@|xs|}t|jDcgc]}|j|||c}dSt|tr,|jjrt|tr|j||S|j!|}|g}|D]} |j#|| } | |j%| )|jj't(j*|t d|j Dr0|j-|} |jj/d| |t1t2j4cSt|S|j7||St|t8r|j;||jdSt|t<r|j?r|jAjBr+|jE|jA|j|S|jAjFs|jAjHdk(r|jKdSt|tLr"|j|jO|||St|tPr*|jRjHd k(r|jKd S|jUd ||jgtVg||| \} } | |_,| Scc}w) a Analyze type of an index expression for a given type of base expression. The 'original_type' is used for error messages (currently used for union types). The 'self_type' is to bind self in methods (see analyze_member_access for more details). c3<K|]}t|tywrrrs rrz:ExpressionChecker.visit_index_with_type..Ls4 +-Jr: &4 rF)contract_literalsc3<K|]}t|tywrrrs rrz:ExpressionChecker.visit_index_with_type..ksRQz!Z8RrzVariadic tuple can have length rrztypes.GenericAliasrV __getitem__)rr)-rLrrqrrrrr&rrrrrr9rdvisit_tuple_slice_helpertry_getting_int_literalsvisit_tuple_index_helperrrrTUPLE_INDEX_OUT_OF_RANGEmin_tuple_lengthrOrrr<nonliteral_tuple_index_helperrvisit_typeddict_index_exprrrrrvisit_enum_index_exprrrrMrvalues_or_boundrrr8r5r)r#r!r.rrrLrnsoutrjrmin_lenr/rs rrz'ExpressionChecker.visit_index_with_type9s* #I.  E i +4 1:4 1 $Ir2I i +)6YM( )779..sA}E#(   9 -$((2N2N2P%+44YFF..u5B~ =A88AFD' 4( &6&O&OQRSR)//RR&*&;&;I&FG HHMM,KG9*UWXY&y';';<< =-S1199)UKK  = 1229aggFqI I  < 0Y5J5J5L$$&..11)2G2G2I177TUVV%%'11((*33F';<< i ---))+Q y  8 ,1H1HLa1a??#89 9"&"@"@  +##A# FK(AMMssM0c@t|j}||jS|j|}t|tsJt|j t r*|jdz |j jzS|jdz Sr)rrlengthrrrrr)r#r unpack_indexunpacks rrz"ExpressionChecker.min_tuple_lengths*4::6  ;;= L)&*--- fkk#3 4;;=1$v{{':':: :{{}q  rc t|j}|N|dkr|t|jz }d|cxkrt|jkrny|j|Sy|j|}t|tsJt |j }t|trRt |j}t|tsJ|j jdk(sJ|jd}n*4::6  1uS_$A'DJJ'zz!}$L)&*---"6;;/ h 0 1$H$8$89EeX. ..::&&*:: ::ZZ]Fh1 11==))-== ==]]1%F++D1DKKMAAE 6D))$//<zz!}$''**\A-A Oa4GXYIY0Z[\    T " "4 (( q5 {* *::a+o12 2## JJs1l+l ;vh F SWS^S^  rc dg}dg}dg}|jr1|j|j}||j||S|}|jr1|j|j}||j||S|}|jr1|j|j}||j||S|}g} t j |||D]\} } } |j| | | |jd} | E|jjtj|ttjcS| j!| t#| S)Nrr) begin_indexrr end_indexstride itertoolsproductslicerMrrr!AMBIGUOUS_SLICE_OF_VARIADIC_TUPLErrr<rr)r#r!slicbeginendr begin_rawend_raw stride_rawrbr.srs rrz*ExpressionChecker.visit_tuple_slice_helpersW'+f%)F(,v   55d6F6FGI 99)TJJE >>33DNNCG99)TJJC ;;66t{{CJ!99)TJJF ((V< GAq!??1aT__EU5V?WD| .PPRVWy3344 LL    %U++rc t|tr |jgSt|trs|jdk(r,|j }t|trd|jzgS|jdk(r)|j }t|tr |jgSt |j|}t|tr|j |j}t|tr't|jtr |jgSt|treg}t|jD]I}t|tr6t|jtr|j|jIy|Sy)aIf the given expression or type corresponds to an int literal or a union of int literals, returns a list of the underlying ints. Otherwise, returns None. Specifically, this function is guaranteed to return a list with one or more ints if one the following is true: 1. 'expr' is a IntExpr or a UnaryExpr backed by an IntExpr 2. 'typ' is a LiteralType containing an int 3. 'typ' is a UnionType containing only LiteralType of ints -r3rN)rrRrrrrrrrqrr[rrrrrr)r#rLoperandrrrs rrz*ExpressionChecker.try_getting_int_literalss/ eW %KK= y )xx3**gw/.//xx3**gw/#MM?*dkk%01 c8 $)=)=)I&&C c; 'Jsyy#,FII;  c9 %C(3 dK0Z C5PJJtzz*  Jrc|jd||gtg||j|}t|tr|j j d|gS|S)Nrr$r)r8r5union_tuple_fallback_itemrrdrrO)r#r!rLunions rrz/ExpressionChecker.nonliteral_tuple_index_helpersY &&}i%7)]b&c..y9 eY '88../?%I I rcg}|jD]}t|trt|j}t|t rt|j }t|tr8|jjdk(r|j|jdt|j|t|S)Nrr) rrrrrrrrrrrNotImplementedErrorr)r#r!rrrbs rrz+ExpressionChecker.union_tuple_fallback_itemsOO #D$ + / : m-=>$3M4M4M$NM}h7%**337GGLL!3!3A!67-- T" #%U++rct|tr|jg}n&t|j |}t|t rt |j}n|g}g}t|D]}t|tr|j |j}t|trYt|jtr?|jjjdk7r|j!|j|j"j%||t't(j*t-fcSg}|D]s} |jj/| } | C|j"j1|| ||t't(j*t-fcS|j!| ut3|t-|fS)Nr)rrfrrrqrrrrrr[rrrrrrr$typeddict_key_must_be_string_literalrrr<rcrtypeddict_key_not_foundr) r#td_typerLsetitem key_namesr key_typesr value_typeskey_namers rrz,ExpressionChecker.visit_typeddict_index_expr,s| eW % I!$++e"45C#y)(,SYY  E I,Y7 @h1h6O6O6['88Hx5"8>>37 ))..77;KK$$X^^4HHAA'5Q"9#7#78#%?? @ ! /H **84J!00(E7Sy334ce;;"":.  /%[13y>AArc|jd}|jj|j|||ddt |gS)NrzEnum index should be a stringzactual index type)rMr check_subtyperqr)r# enum_typerLr^ string_types rrz'ExpressionChecker.visit_enum_index_exprQsK!OON;   KK    +    2&&rcP|j|jttjdd}|j }|j j}|jrKt|ttjs(t||r|jj|||jr(t|r|jjd||t||j j|j j |j||S)zType check a cast expression.TrrmrzTarget type of castr$)rqrrrr5rrrwarn_redundant_castsrrredundant_castdisallow_any_unimportedrunimported_type_becomes_anyris_typeshed_stub)r#r source_type target_typers rvisit_cast_exprz!ExpressionChecker.visit_cast_expr^skk II !7!78"! " ii ((""  ( ( gi6L6L.MN[+6 HH # #K 6  * */KK/X HH 0 01F UY Z ))488+D+DdhhX\ rc|j|j|jddd}|jjr|S|j }t |}t|tjjr|j |j}t||s]|jjs&|jjd|j|jj!||||S)Nr3TrzC"assert_type" expects everything to be "Any" in unchecked functions)rqrrrr[rrrrrrr[rr9rrOassert_type_fail)r#rrrproper_source_types rvisit_assert_type_exprz(ExpressionChecker.visit_assert_type_expruskk II**2."! " 88 ) ) ii ,[9 )4::+>+> ?"33?,==KK588//1 YII HH % %k; Erc|jtk(r|jJ|j|j|jdd}|j j sw|jj||j|j js&|jjd|j|j||S|j j sj|j/|jDcic]}|j|jc}ni}|jj|||j|t!Scc}w)z$Type check a reveal_type expression.r3Trrmz9'reveal_type' always outputs 'Any' in unchecked functions)r@r<rrqrrr[r reveal_typer9rOcheck_reveal_imported local_nodesr;r reveal_localsr)r#r revealed_typevar_nodenames_to_typess rvisit_reveal_exprz#ExpressionChecker.visit_reveal_exprs- 99 #99( (( KK (9(9"(=QU(M8811$$]DII>xx335HHMMSUYU^U^**40 8811 ''3CGBRBRShX]]HMM1S &&~t<**40: Ts E&ctj|jjjvryd}|j t k(rd}n#|j tk(r|jsd}ny|jjd|d|tj|dk(rg|jjjdk\rdnd }d j|| }|jj||tjyy) NrrzName "z" is not definedr)r} typingtyping_extensionszXDid you forget to import it from "{module}"? (Suggestion: "from {module} import {name}"))moduler;) rUNIMPORTED_REVEALrrrr@r;r< is_importedrrrrO)r#rr;r hints rrz'ExpressionChecker.check_reveal_importeds  " "$((*:*:*N*N N  99 %"D YY+ %d.>.> D   tf$45t%BYBY Z =  HH,,;;wFL_ ?fFf.  HHMM$5+B+BM C !rct|jtrt|jjtr|jjj r|j St|jj|j|jj|jjj||jj}t|}t|tr=t|j |j"}|j%||j&|St|t(rq|j*j j,rQt|j*j |j"}|j%||j*j&|St|t.r|j1|S|jjt2j4|t7t8j:St|j=|j}t|t>t@frW|jCs*|jjt2j4||j%||j|St|t6rt7t8jD|St7t8jFS)a{Type check a type application (expr[type, ...]). There are two different options here, depending on whether expr refers to a type alias or directly to a generic class. In the first case we need to use a dedicated function typeanal.instantiate_type_alias(). This is due to slight differences in how type arguments are applied and checked. r)$rrr`rrpython_3_12_type_aliastype_alias_type_typerrrrrrrrrrrM apply_type_arguments_to_callablerrrrrrrONLY_CLASS_APPLICATIONrrr<rqrrrrr5)r#tapprrs rvisit_type_applicationz(ExpressionChecker.visit_type_applications dii )j.Syy~~440022)    &&  D#4(D$)%diiA<># .EEtL88TZZN N b' "955"E Ey--..rc>|j|j|dS)aRight hand side of a type alias definition. It has the same type as if the alias itself was used in a runtime context. For example, here: A = reveal_type(List[T]) reveal_type(A) both `reveal_type` instances will reveal the same type `def (...) -> builtins.list[Any]`. Note that type variables are implicitly substituted with `Any`. TrJ)rQr)r#aliass rvisit_type_alias_exprz'ExpressionChecker.visit_type_alias_exprs!11%**%Z^1__r)rLc `|jr|jSt|jtr/|jj rt tjS|jjjxr |j}tt|g|j|j |jj||j"j$}t|trKt'|j(|j*}|j,r|S|j/||j0|St|t2rKt5|j(j6dk7r)t't5|j(|j*St|t8r|j;|St|t<r"t?||j|j St|t rt tj@|St|tBrU|jDrI|jjjFdk\r&|jjId|jJS|rt tjLS|j+dS)aGet type of a type alias (could be generic) in a runtime expression. Note that this function can be called only if the alias appears _not_ as a target of type application, which is treated separately in the visit_type_application method. Some examples where this method is called are casts and instantiation: class LongName(Generic[T]): ... A = LongName[int] x = A() y = cast(A, ...) ) disallow_anyrrr@rArr|ztypes.UnionTyperV)'rrrrtrinvalidrrr<rrdisallow_any_genericsrrrr@rArrrrrMrrrrrrrrrrrrrrrOrr5)r#rrKrLrrrs rrQz/ExpressionChecker.alias_type_in_runtime_contexts  ' ',,. . ellH -%,,2F2F9//0 0 xx''==P$..     )XX]]    dH %"$))T__=B}} 88TYYL L tY ' 4 % % . .2B B#N4$8$=$=tO O m ,77= = h 'DtyyE E g &955$G G tY '''  //7:88../@$**M My5566??#89 9rc|jr%|jjj}nt |j }t |}t|j |D]\}}t|tstt|ttttfrA|jjdt!||jj"|tt$j&gt)|zcS|rt+d|Ds t |S|jsJ|j}t-|||j.|j0}t3||jjdsat5||jj|jj6d|jj"t |j8}t;dt=|D} t)|| z d z } || } t| t>sJtAtC|| | \} } }t | tEt | | jFgzt |zS) aHandle directly applying type arguments to a variadic Callable. This is needed in situations where e.g. variadic class object appears in runtime context. For example: class C(Generic[T, Unpack[Ts]]): ... x = C[int, str]() We simply group the arguments that need to go into Ts variable into a TupleType, similar to how it is done in other places using split_with_prefix_and_suffix(). zQCan only replace ParamSpec with a parameter types list or another ParamSpec, got c3<K|]}t|tywrrrrs rrz7ExpressionChecker.split_for_callable..dsM1z!-=>MrrT)empty_tuple_indexF)rrc3HK|]\}}t|ts|ywrr )rrrs rrz7ExpressionChecker.split_for_callable..tsYFQAGW9XaY""r)$rrrrrr rrrrrrrrrrr3rrr<rrrr@rArrrOrnextrcrrtuplerr)r#rrrKvarsr)r rfakeprefixsuffixtvtstartrrs rsplit_for_callablez$ExpressionChecker.split_for_callableCs ==?==?''11D $D$T*1;;- GGB"m,!#C(:}g{*[HHMM33>sDHHDTDT3U2VX $I$8$89:SYFF G3MMM: }}}}d#**E!txx}}M dhhmmTXX]]PTPXPXP`P`  ?DYioYYTV#a'6l#/0009%+vvVvsE{iV c6H6HIJJTRUYVVrc t|}t|tr|jr%|j j j }nt|j}td|D}td|D}t||kst|t|kDr |s|jr|j jdk(rttt||jjdgt gdgtt||jjd|j"d|j$|j&S|j(j+|t|t||t-t.j0S|j3||j5||||St|t6r7|j8D]}|jr%|j j j }nt|j}td|D}td|D}t||kst|t|kDs|r|j(j+|t|t||t-t.j0cSt7|j8Dcgc]&}|j3||j5||||(c}St-t.j:Scc}w) a{Apply type arguments to a generic callable type coming from a type object. This will first perform type arguments count checks, report the error as needed, and return the correct kind of Any. As a special case this returns Any for non-callable types, because if type object type is not callable, then an error should be already reported. c3>K|]}|j ywr has_defaultrs rrzEExpressionChecker.apply_type_arguments_to_callable..sGAMMO 3Gc3<K|]}t|tywrr rs rrzEExpressionChecker.apply_type_arguments_to_callable..s$XZ3C%D$Xrrr%N)r;rr!c3>K|]}|j ywrr/rs rrzEExpressionChecker.apply_type_arguments_to_callable..s#KA $7#Kr1c3<K|]}t|tywrr rs rrzEExpressionChecker.apply_type_arguments_to_callable..s(\QA7G)H(\r)rrrrrrrrr r:rrrrrrMr5rrr!rincompatible_type_applicationrrr<rr,rrr5)r#rrrKr min_arg_counthas_type_var_tuplers rrz2ExpressionChecker.apply_type_arguments_to_callable{sR  b, '~~NN,11;;  . GYGGM!$$Xi$X!X D M)SYY-G(>>#(8(A(AEU(U ("4:txx/B/B7/KLM !$t*dhh.A.A'.JK $#%==!#  66!3y>3t9cy3344//D4K4KBPTVY4Z\_` ` b* %hh 9>># " 0 5 5 ? ?I $R\\ 2I ##K#K K %((\R[(\%\"I -TS^1K,HH::%s9~s4y##9#7#788 9!hh00T5L5LRQUWZ5[]`a  y--.. s4+L?c(|j|ddS)z#Type check a list expression [...].rCzcheck_lst_exprrs rvisit_list_exprz!ExpressionChecker.visit_list_exprs""1ox@@rc(|j|ddS)Nrzr9rs rvisit_set_exprz ExpressionChecker.visit_set_exprs""1ng>>rc~|jd}|s |jsy|jjry|jj |d}|t |tr|SdSg}t}|jD]c}t |trt|j|<y|j|}||vsB|j||j|e|j|} | t|j|<y|jj|| g} | |j|<| S)a Fast path to determine the type of a list or set literal, based on the list of entries. This mostly impacts large module-level constant definitions. Limitations: - no active type context - at least one item - no star expressions - not after deferral - either exactly one distinct type inside, or the joined type of all entries is an Instance or Tuple type, r3N)rrrr[rrrrrcrerrqrr_first_or_join_fast_itemrO) r#r.container_fullnamerKrtr values_setrrvtcts rfast_container_typez%ExpressionChecker.fast_container_types'"# agg 88 ) )    # #At , >#B12 ;t ; # GG $D$)(0 ""1%++d#C*$ c"s# $ * *6 2 :$,JD  q ! XX ( ();bT B "1 rct|dk(r|jjs|dStj|}t |sy|S)Nrr)rrr[rrr)r#rrs rr?z*ExpressionChecker._first_or_join_fast_itemsD u:?488#A#A8O!!%(+C0 rc |j||}|r|Stddtddg|jt t j }t|gtjgdg|jj||g|jd||g}|j||jDcgc] }t|t r |j"n|"c}|jDcgc]2}t|t rtjntj$4c}|d}t'|Scc}wcc}w) NTr3z namespacerrrdefaultrIr;r r)rErrrRrrfrom_omitted_genericsrrr6rrOrMrrrrerr5r!) r#r.rtagrr) constructorrrs rr:z ExpressionChecker.check_lst_expr s%  $ $Q 1 H   w/((*I;;<  # D ^^  F HH ' '2$ 7 OO/ 0d oo AB IA 1h/affQ6 IUVU\U\ ]PQ 1h 7ennU]]J ]    155 J ]s %E 57E c t|j}|Jt|jDcgc]}t|tr|c}t|jkSt|jDcgc]}t|ts|c}dk7ryt dt |jD}t|jt|jk(xr||k(Scc}wcc}w)NrFc3HK|]\}}t|ts|ywr)rre)rrlvs rrz:ExpressionChecker.tuple_context_matches..6s`UQzRTV^G_q`r#)rrrrrer$rc)r#rrKctx_unpack_indexr.expr_star_indexs rtuple_context_matchesz'ExpressionChecker.tuple_context_matches,s.syy9  #4::MaZ85LMNRUVYV_V_R`` ` 4::AaAx)@A Ba G`i .C``4::#cii.0X5E5XX NBsC1C15C6 C6cRt|jd}d}t|trit |j Dcgc]6}t|t r|j||st|tr|8}}t|dk(r|d}n t|t r|j||r |j }nV|rTt|trDt|tsJ|jr&|jdgt|j z}d}| t|du}d}|xs&t|jj j"v}g} d} t%t|j D]} |j | } t| t&rh|r(|sJ|| } t| t(sJ| j*}nd}|j-| j.|}t|}t|t rjt|j |r|j1|ddcSd}| j3|j |r| dz } | t|j z } |r|st|trr|jj5|rW|jj7||}|jj9d|g}| j;t)|d}w|j1|ddcS|r| t|k\r|j-| }n|j-| || }| dz } | j;|t=t>j@}t | |jj9d|g}|r tC|i}|Scc}w) zType check a tuple expression.r3NrrFrzT)"rrrrrrrrVrrrrrrrvrrrrrerrrqrr:rErrrOrrrr5r&)r#r.rtype_context_itemsrtuples_in_contextunpack_in_contextseen_unpack_in_itemsallow_precise_tuplesrrrrctx_itemrKttrZr fallback_itemr/s rvisit_tuple_exprz"ExpressionChecker.visit_tuple_expr9sk't'8'8'<= ! lI .*,*<*<=!q),1K1KAq1Q$Q(AB! ! $%*03  lI .43M3MaQ]3^!-!3!3  / >WXlH5 55  &2&7&7&:%;c!''l%J" "  ) 34F Gt S $  b!48H8H8b8b!b   s177|$4 !A771:D$) %---1!4H%h ;;;"--CC[[C0$R(b),*2884@/$(#6#6q:JI#VV370LL*(QS]*+4H%b(38Q8QRT8U(,(C(CB(JI%)XX%@%@AQT]S^%_F!LLF);<370$ ..q2BINN)Q#6H2I-IT*BT+=a+@ABFA R i4 !l 6 67 & 488../?-Q   ,F C!s;N$c|jd}|s |jsy|jjry|jj |d}|t |tr|SdSg}g}t}t}d}|jD] \} } | t|j| } t | trP| jjdk(r7t| jdk(r| jd| jdf}t|j|<y|j| } | |vr"|j!| |j#| |j| } | |vs|j!| |j#|  |j%|}|t|j|<y|j%|}|t|j|<y|r(|d|k7s|d|k7rt|j|<y|jj'd||g}||j|<|S)a Fast path to determine the type of a dict literal, based on the list of entries. This mostly impacts large module-level constant definitions. Limitations: - no active type context - at least one item - only supported star expressions are other dict instances - either exactly one distinct type (keys and values separately) inside, or the joined type of all entries is an Instance or Tuple type r3NrFrrr)rrrr[rrrrrcrrqrrrrrrrr?rO)r#r.rKrArrkeys_setrBstargsrrstkey_tvalue_tktrCdts rfast_dict_typez ExpressionChecker.fast_dict_types# agg 88 ) )    # #At , >#B12 ;t ;!e # +/'' ,JC{$T[[%78r8,((O;BGG ) ggaj"''!*5F,4JD&&q) C((KK&LL'++e,*,MM'*NN7+) ,, * *4 0 :$,JD  q !  * *6 2 :$,JD  q ! vayB&)r/$,JD  q ! XX ( (2r( C "1 rc|j||j|d}t|}t|tr|j S|j S)N)rrr^r)rrrrrr)r#r.typeddict_contextr8r?s r"check_typeddict_literal_in_contextz4ExpressionChecker.check_typeddict_literal_in_contextsZ;;$QWWaT< #=1 h .))+ + ..00rc |j|jd|\}}|rt|dk(r|r|j||dS|D]}|jj 5}|j j5}|j||}ddddddjrh|j jcS|r|jj|||j|}|r|Stddtddg|jtt j"} td d td dg|jtt j"} g} g} |j$D]\} }| ?| j'|| j'|j j)d | | gHt+| |g}| j,dk\r#| j,|_| j.|_n"|j,|_|j.|_|j0|_|j2|_| j'|| j't5| | g|j7d  t9| t:j<gt| zdgt| z|j j)d | | g|j7dd| | g}|j?|| t:j<gt| z|dS#1swYxYw#1swYxYw)zoType check a dict expression. Translate it into a call to dict(), with provisions for **expr. r3rrNKTrIrKVTrRrrFrIrM) find_typeddict_contextrrrlrrPrr1rrtypeddict_context_ambiguousrirrrRrrrNrrrOrjr@rAend_line end_columnrrMrrr5r)r#r.typeddict_contexts exhaustiverkrtmapr?rhrgrCrexpected_typesrrtuprPs rvisit_dict_exprz!ExpressionChecker.visit_dict_exprs*.)D)DTEVEVWYEZ\])^&J %&!+ >>qBTUVBWXX%7 !XX++-]dhh6M6M]QU#FFqJ[\H]]%%'$$T*  445GK  # I  x0((*I;;<    x0((*I;;<  "$%''' ^JC{ E"%%HH//0RUWY[T\] e -88q="xxCH!$CJ$zzCH!&CJ$~~ !&!1!1 C %%iR$//JZ:[&\]# ^*#  ]]Oc.1 1 FS( ( HH ' '"b B OO/ 02h {D5==/CI2MqQRSTTE]]]]s$)M L=M =M M  M c>t|}t|tr|gdfSt|trjg}d}|jD]S}|j ||\}}|D]1}|j ||j|s!|j|3|xr|}U||fSgdfS)zExtract `TypedDict` members of the enclosing context. Returns: a 2-tuple, (found_candidates, is_exhaustive) TF)rrrrrrrrr) r#r^ dict_exprrrwr item_contextsitem_exhaustive item_contexts rrrz(ExpressionChecker.find_typeddict_contextGs"'* g} -9d? "  +EJ  <151L1LTS\1]. $13L::$iooy \2 3 (;O  <*$ $5yrc|j}d|_|jj|d|j|\}}|s=|jjj t tj|jjjdd5|jjj|5|jjddD]}|j|j|j|jd}dddddd|j!d }|jjj#||_t%||S|jjj |j&|jj(j+|5|jj-|| ddd|jj/|jsQ|jjjdd5|j|jdddd|jj1|j}|jjj#||_t3||S#1swYxYw#1swYxYw#1swYxYw#1swYxYw) zType check lambda expression.TF)body_is_trivialrcan_skip fall_throughNr3rlrI) type_override)r rcheck_default_argsinfer_lambda_type_using_contextrrrrr5r frame_contextr? push_functionbodyrqrrMpoprr?tscopefunction_scopecheck_func_itemrrreplace_callable_return_type)r#r. old_in_lambdar(rstmtr?rs rvisit_lambda_exprz#ExpressionChecker.visit_lambda_exprasa++ " ##Au#='+'K'KA'N$ } HH ! ! ( (1G1G)H I--t!-L I,,Q/ IFFKK,*DKK)* ;;qvvx4;H I I':;H HH ! ! % % '"/D  Hh7 7 HH ! ! ( ()?)? @//2 I((-(H I88$$QVVX.XX__22Dq2QBKKDKABxx++AFFH5H HH ! ! % % '"/D / xH H9 I I I I& I IBBs=+&K&AK,K&K3"K?K# K&&K03K<?Lct|jd}t|trJt |j Dcgc]}t|t s|}}t|dk(r|d}|rt|t sy|jjjsg}|jD]Y}t|Dcgc]}|jjs|!}}|j|Dcgc] }||vs| c}[|j!t#|j$t't)|j*|z} n8t#|t'} t| t,rt| t sJ| } | j!|j/d} | j0 | j2y|j4Dcgc]}|j6} }| j8s|j;Q| j!d t=t>j@gt| z| |jBjE } tF| vstH| vr| dfS| jJ| k7r+|jjMtNjP|y| j!|jB | fScc}wcc}wcc}wcc}w) zTry to infer lambda expression type using context. Return None if could not infer type. The second item in the return type is the type_override parameter for check_func_item. r3rrNN)r?r rIrNF)is_ellipsis_argsrrr)r))rrrrrrrrrrrrrr is_meta_varrErr"r?rrr rrMrr argumentsr@rrrrr5rrr6r7rrrCANNOT_INFER_LAMBDA_TYPE) r#r.rKrr extra_varsr r) meta_vars callable_ctxrrs rrz1ExpressionChecker.infer_lambda_type_using_contextsd//34 c9 %+C,>,>,@AZPQS_E`I9~"l*S,7xx22J}} T*;C*@XBBEEDUDUDWRX X!! "R"Rz=Q2"RS T,,*3<<Fs}}- :-L +3 =Jj*5*ZQ]:^ ^^%L$114??K^;_1`  " " .,2F2F2R)*5#SXX5 5  ( (CNN,<,H'55!&"9#9#9:;c)nL#++**, 6L y I$:% %  ! !Y . HHMM*CCQ G))AKK)@,NN(Y"R(6s*KKK $K 9 K K Kc|j|}t|tr|\}}n|St|}|C|jj t j|ttjSt|}|C|jj t j|ttjS|j}d}||vr|j|}n|jjj} | bt!|| j"rK|j$r?||j$jvr'|j$j}|j|}|c|j&r||k7r|j&sd}nC|jj t j(|ttjSt+||dzk(rC|jj t j,|ttjS||dzdD]} |j.| j0vs | |dk(s$|j$r9|j$j2r#| |dk(rttj4cSt7|j.|ddd|| ||j|j9 cSJd) z+Type check a super expression (non-lvalue).N)is_classmethodr3rFT) r;rrTrrr override_infor^rrr)_super_arg_typesrr%type_info_from_typerrrUNSUPPORTED_ARG_1_FOR_SUPERrrr<UNSUPPORTED_ARG_2_FOR_SUPERrrLr?current_functionris_classrr!SUPER_ARG_2_NOT_INSTANCE_OF_ARG_1rTARGET_CLASS_HAS_NO_BASE_CLASSr;rdrr5rrZ) r#r.r type_type instance_type type_info instance_inforrLr'rus rvisit_super_exprz"ExpressionChecker.visit_super_exprsd %%a( eU #', $I}L( 2   HHMM*FF J9//0 0+M:  HHMM*FF J9//0 0  IIi(EXX^^446F !&7foo'66i166::5&&**CIIi0E =))!Y.!--  .PPRSTy3344 s8uqy HHMM*II1 M9//0 0 $ Dvv#ts2w66aff44R#9#9#9::,%#! %"/"&'+'>'>'@   ( $m#urc" |jjsttjSt |j jdk(rL|jsttjS|jjjrC|jjtj|ttjSt|j}t!|}|jjj#}|J|j$r)|j$dj&j(xs|}n0|jjtj*|ttjSt,|j j.vrC|jjtj0|ttjSt3|j j.t4hk7rC|jjtj6|ttjSt |j jdk(rC|jjtj8|ttjSt |j jdk(rZt;|j=|j jd}|j=|j jd}nC|jjtj>|ttjStA|trF|jrt!t|j}nttjB|StA|t rb|jD}tA|trF|jrt!t|j}nttjB|StA|t sUtA|tFr|jIs5|jJjM||ttjSt;|}tA|tr@|jrt|j}||fSttjB|StA|t re|jD}tA|trI|jr"t!t|j}||fSttjB|S||fS)a* Computes the types of the type and instance expressions in super(T, instance), or the implicit ones for zero-argument super() expressions. Returns a single type for the whole super expression when possible (for errors, anys), otherwise the pair of computed types. rrrr)'rr9rrrrcallrrr<r? active_classrr%SUPER_OUTSIDE_OF_METHOD_NOT_SUPPORTEDrrrrvariabler(SUPER_ENCLOSING_POSITIONAL_ARGS_REQUIREDr6rSUPER_VARARGS_NOT_SUPPORTEDrcr5SUPER_POSITIONAL_ARGS_REQUIRED#SUPER_WITH_SINGLE_ARG_NOT_SUPPORTEDrrqTOO_MANY_ARGS_FOR_SUPERrrrrrr%first_argument_for_super_must_be_type)r#r. current_typerr'r type_item instance_items rrz"ExpressionChecker._super_arg_types)sxx++-9001 1   "66y3344,,. .TTVWXy3344)0L$,\$:IXX^^446F% %%&,&6&6q&9&B&B&G&G&W<  .WWYZ[y3344 )) ) HHMM*FF J9//0 0 !! "wi / HHMM*II1 M9//0 0   " HHMM*NNPQ R9//0 0   "' AFFKKN(CDI KK A7M HHMM*BBA F9//0 0 i )vv$]166%:; y99iPP  8 ,!I)W-66 (qvv)> ?I"9#=#=)TT)X. y, /I4I4I4K HH : :9a H9//0 0( 6 mW -vv -aff 5 -''y99mTT  x 0)..M-166$,]166-B$CM-''#9#=#=-XX-''rc |jjd}t|}g}|j|j |j fD]l}|rO|j|}|jj|||tj|j|T|jtn|jjd|S#t$r|jjd}YwxYw)Nztyping_extensions.SupportsIndexrzbuiltins.slice)rrMrbrrrrrqrrINVALID_SLICE_INDEXrrrO)r#r.supports_indexexpected type_argsrLrs rvisit_slice_exprz"ExpressionChecker.visit_slice_expr{s A!XX001RSN&n5 mmQ[[!((; -EKK&&&q(E;K;_;_`  #  ,  -xx**+;YGG A!XX00@N AsC$C?>C?c<|j|jddS)NrCz check_generator_or_comprehension generatorrs rvisit_list_comprehensionz*ExpressionChecker.visit_list_comprehensions!44 KK*@  rc<|j|jddS)Nrzrrs rvisit_set_comprehensionz)ExpressionChecker.visit_set_comprehensions!44 KK)>  rc>t|jsPt|js;td|jddDstd|j Drd}t g}nd}t t g}|j||d|S)Nc32K|]}t|ywrr)rsequences rrz9ExpressionChecker.visit_generator_expr..sRh'1Rrrc3@K|]}|D]}t|ywrr)rcondlistconds rrz9ExpressionChecker.visit_generator_expr..s$_(V^_d'-_-_sztyping.AsyncGeneratortyping.Generatorz )additional_args)ris_asyncrrn sequences condlistsrr)r#r.rrs rvisit_generator_exprz&ExpressionChecker.visit_generator_exprs  O#AKK0R!++ab/RR_akk__)C+3:,O$C'z8:6O44 sM?5  rc F|xsg}|jjjdd5|j|t ddt ddg|j ttj}|g}t|tjgd g|jj|||z|jjd ||g }|j||j gtjg|dcd d d S#1swYy xYw) z:Type check a generator expression or a list comprehension.TrrrHr3zrIrKNrIrM)rrrcheck_for_comprrrRrrrNrrr5rOrMrrn)r#genrid_for_messagesrr)tv_listrPs rrz2ExpressionChecker.check_generator_or_comprehensions*/R XX__ * *Dq * I Z    $R:6 ,,. ? ?@ B$&$G&++Iw7PQ##$78$$K??;%--RUVWXY/ Z Z Zs CDD c |jjjdd5|j|t ddt ddg|j ttj}t d d t d dg|j ttj}t||gtjtjgd d g|jjd ||g|jjd d||g}|j||j |j"gtjtjg|dcd d d S#1swYy xYw)z&Type check a dictionary comprehension.Trrrnr3rorIrKrprqNrFrIzrM)rrrrrrrRrrrNrrr5rOrMrrr)r#r.ktdefvtdefrPs rvisit_dictionary_comprehensionz0ExpressionChecker.visit_dictionary_comprehensionsJ XX__ * *Dq * I     " R84 ,,. ? ?@ E R84 ,,. ? ?@ E' .t ++OeU^L##$781 %.K??aeeQWW- u}}/Mq=   s E E;;Fcht|j|j|j|jD]x\}}}}|r|j j |\}}no|j j|\}}tt|tr8t|tr(|jdk(rttj}|j j!||d||D]}|j#||j j%|\} } | r|j j'| t(j*|j j,j.vs| |j0j3d|| |j0j3d|{y)zCheck the for_comp part of comprehensions. That is the part from 'for': ... for x in y if z Note: This adds the type information derived from the condlists to the current binder. rTNF)rindicesrrrr analyze_async_iterable_item_typeanalyze_iterable_item_typerrrrYr;rrr5analyze_index_variablesrqr push_type_maprrrrr$redundant_condition_in_comprehension) r#r.rLr conditionsrr sequence_type conditiontrue_map false_maps rrz ExpressionChecker.check_for_compsa 69 IIq{{AKK6  W 1E8Z#'88#L#LX#V =#'88#F#Fx#P =}=O"5(3 c)%,I,B,B$CM HH , ,UM4 K' W  I&'+hh&D&DY&O#)HH**84''488+;+;+O+OO'EEeYW"*EEdIV W! Wrc|j|j|jd}|jj |j\}}t j |jjjvrQ|'|jjd|jn(|&|jjd|j|j||j||}tt|xs|}|j||j||}t j"j%||jjsH|} tt| xs| } | t'| |sG|j||j| |}n'||k(r|} n|j||j||} t)|r t)| s|} t+|| g} t-| rrt/t|jdt0sLt3j4|| } t| } t/| t6r| j8j:dk7r| } | S)Nr3FT)r^rmra)rqrrrrrrrrrredundant_condition_in_ifrif_exprrr else_exprrrrNrrrrrrrrArrr)r#r.rmrKif_mapelse_mapif_typeif_type_fallbackfull_context_else_type else_typeelse_type_fallbackr alternativep_alts rvisit_conditional_exprz(ExpressionChecker.visit_conditional_exprs5 AFF# 8899!&&A   488#3#3#G#G G~225!&&A!224@** AIIs>O+ /w/GHSG"&!9!9 akk3BS":" ||227DHH? $S )* D--b1 2I3 //'9=K#K0EeX.%**2E2EIZ2Z! rc|jjjdd5|L|jj |5|j |||dddt cdddS|jj||j |||cdddS#1swYTxYw#1swYyxYw)NTrr)rPr)rrrrrPrqrr)r#rrr^rmsuppress_unreachable_errorss rrz%ExpressionChecker.analyze_cond_branchesXX__ * *Dq * I `{XX++:U+VaKK7N_K`a&( ` ` HH " "3 ';;t'M^;_ ` ` aa ` `s)B;B/B;7.B;/B8 4B;;Ccg}|t|r|S|j||jr-|jd|j|jd|r t|Syr)rrrr)r#ty ctx_itemss rrz#ExpressionChecker._combined_contextxsl >B   R   !2!22!6!B   T..r2 3 (3 3rc&||jvr|j|Sd}|jr)|jstj}d|_d}|j j ||j}||_ |r%t|tr|j|d} n|r%t|tr|j|d} nn|r%t|tr|j|d} nG|r%t|tr|j!|d} n t|tt"t$t&t(fr|j*s|j,j.s|j,j0j2s||f|j4vr|j4||f\} } } } | |j,j6j8k(r7|j,j;| |j<j?| n9|jA||} n%|jA||} n|jC|} ||_|j jO J|j,jQ|| |j,j0jRro|sm|j,jTsW|j,jWr=tY| r2|j,j.s|j<j[| ||j,jWr|j,j.rt]t^j`}n| }|r=|jb|jLxxtjz z cc<d|_|S#tD$rj} tG| |j,jHjJ|jL|j,jH|j,j0Yd} ~ d} ~ wwxYw)zType check a node in the given type context. If allow_none_return is True and this expression is a call, allow it to return None. This applies only to this expression and not any subexpressions. FTrlrN)2rrrtimeperf_counter_nsrrrrrBrrruvisit_yield_from_exprrFrr@visit_await_exprrUrjrIr[r rr[rdisable_expression_cacherrversionrrr;accept_maybe_cacherq Exceptionr%r@filer@rrdisallow_any_expris_stubr9rdisallowed_any_typerrrr)r#rrrmrr record_timet0 old_is_calleerbinder_versionmessagestype_maprr/s rrqzExpressionChecker.accepts/ 4&& &&&t, ,  + +D4F4F%%'B!%D K   . ""  Zh%?**44*H"z$ 'F000N"z$'H11$$1O"z$ 'B++DD+I4(Hi6!RS,,0N0N((AA,'4??:>BootUaNb>c;NC8%)@)@@,,X6++H5"55d5V11$\1RCkk$' '  D#& HH   . .$HH$$,,.S!HH22 HH ( (d 3xx++-1O1O"9#8#89FF   * *499 59M9M9ORT9T T 5!&D  5  !TXX__))499dhhootxxGWGW   sFt ||jjdttjgS)z$Is a type valid as a *args argument?r) rrrrrrrrrOrr5rs rrUz"ExpressionChecker.is_valid_var_argsWc"# 7M:NO S] ,,->I_I_A`@abT  rc 6t||jjd|jdt t j gxsJt||jjdttgxst|tS)z'Is a type valid as a **kwargs argument?rRr) rrrOrMrrr5rrrrs rrWz*ExpressionChecker.is_valid_keyword_var_args ++6__^4gi>T>T6UV  .++69JOL]8^ .#}- rc<|jj||y)zCalled when we can't infer the type of a variable because it's not ready yet. Either defer type checking of the enclosing function to the next pass or report an error. N)rr:)r#r;r^s rnot_ready_callbackz$ExpressionChecker.not_ready_callbacks --dG>{ER 66>/ABXwDWXHH002 .CCQG#{{1663EF  HH " " " <<  xx22;FFrc|jd}||jjd|g}t|j |j |}t |trttj|S|j||tj}|s?t t|tr&|jjjd||S)Nr3typing.Awaitabler)rrrOrrqrrrrrcheck_awaitable_exprrINCOMPATIBLE_TYPES_IN_AWAITrrr)r#r.rm expected_typerKrPs rrz"ExpressionChecker.visit_await_expr,s))"-  $ HH778J]O\M%dkk!&&-&HI k7 +955+N N'' ,HH !Z0Dh%O HHLL . .tQ 7 rc|jj||jd||ddsttj S|j d|gg|d}|jj|d}t|}|s@t|tr0|js$|jjj|S)zyCheck the argument to `await` and extract the type of value. Also used by `async for` and `async with`. r#rr __await__rF)rrrMrrr5r8get_generator_return_typerrrrrr)r#rrKr ignore_binderrr?s rr$z&ExpressionChecker.check_awaitable_expr:sxx%% t12Cm_ 9112 266{Ar2sSTUVIxx99)UKH&x0H!x9 **++-Orc|jjd}t|j|j}t |t rt tj|}n1|jj|rt|r1t|s&|jjj||t tj}|jjd|||g}|j!||j#d|gg|\}}nwt|r t|s@|jjj||t tj$}n!|j'||t(j*}|jj-|d} |jj-|d} |jj/| | |t(j*ddt|}|jj1|d } |s?t t| t2r&|jjj5d|| S) Nr3rr__iter__r$Frr) is_coroutine)rrrrqrrrrrr is_async_defhas_coroutine_decoratorryield_from_invalid_operand_typer5rOrr8r<r$r INCOMPATIBLE_TYPES_IN_YIELD_FROMrrr)rr) r#r.rmr subexpr_type iter_typerpgeneric_generator_typerrr  expr_types rrz'ExpressionChecker.visit_yield_from_exprQs hh++B/ 't{{166':;  lG ,%i&@&@\ZI XX & &| 4L)2I+2V <<\1My556H%)XX%@%@"Xx$B& " # + +A .99L"b:P:LIq!.3J;3W <<\1M#I$8$89  55 !%5%V%V "XX>>{ER88<.s#YuLE$B#Yz3TypeVar default must be one of the constraint types)rrLrr type_of_anyrrNrrrrrrr5)r#r.r=s @rvisit_type_var_exprz%ExpressionChecker.visit_type_var_exprs#AII. y' *%%)H)HHi7 SUVWxx#YPQPXPX#Y Y SUVWy--..rc4ttjSrrrr5rs rvisit_paramspec_exprz&ExpressionChecker.visit_paramspec_expry--..rc4ttjSrrBrs rvisit_type_var_tuple_exprz+ExpressionChecker.visit_type_var_tuple_exprrDrc4ttjSrrBrs rvisit_newtype_exprz$ExpressionChecker.visit_newtype_exprrDrcx|jj}|r|jjjr(t |r|j jd||t||jj|jj|j |ttjS)NzNamedTuple typer$) r tuple_typerrrrrrrrrrr5)r#r.rJs rvisit_namedtuple_exprz'ExpressionChecker.visit_namedtuple_exprsVV&& xx77.s5"FF&&v'>PV@WXs14)rrrrrr_r#rtrs` rrnz(ExpressionChecker.has_abstract_type_partsX k9 -*[)2T&)+*;*;[=N=N&O %%k;??rct|txrt|txr|jxr|j j xs|j j xrwt|jtxr[|jjj xs |jjj xr|jj Sr) rrrrrrrrrrrallow_abstract_callras rr_z#ExpressionChecker.has_abstract_types {L 1 1;1 1'') 1((*66_+:Q:Q:S:_:_ 1;++X6  1 !!&&22Wk6F6F6K6K6W6W  1 HH000 r) rr rr2rr{rdict[int, int]rrrr)r.rYrrF)r.r`rDrrr) rrhrKrGrTrrFrrGrrr)r8rsr^rGrr)rrWrr)r.rBrmrrr)rurMrr)r.rBrr)rRrrrrrkrrMrr)rzSymbolNode | Nonerr)rrr list[ArgKind]rzSequence[str | None]rlist[Expression]r^rGrrrr)rz.Iterable[tuple[Expression | None, Expression]]rrrz3tuple[dict[str, list[Expression]], set[str]] | None) rrMrrr/dict[str, list[Expression]]rset[str]rrrrrr)rrr*list[tuple[Expression | None, Expression]]r^rGrr) rrrrmr^rGrrrr)rrnrrr)rrr z Sequence[TypeVarLikeType] | Nonerr) rrrrjr^rGrrrrkrr)rrVrz Var | None)rWr`rz%tuple[Var, dict[Var, Context]] | None)r.rBr\rr8rsrzInstance | None)rrrrhr list[Type]rSequence[str | None] | Nonerlist[list[int]]rrirrrRrr^rGrr) rrrrirrhrrorwz>Callable[[list[list[Expression]], CallableType], FunctionLike]rr)rrrrirrhr^rGrror|z,Callable[[FunctionSigContext], FunctionLike]rr)rrrrirrhr^rGrrorRrr|z*Callable[[MethodSigContext], FunctionLike]rrr)rrkrrrrirrhr^rGrrorRrrr)rrrrirzOverloaded | None)rrrrrKrGrtuple[Type, Type] | None) rrr.rBrrkrRrrrkrr)r.rBrRrrrrr)NNNNN)rrrrirrhr^rGrrorExpression | NonerrkrRrrrrtuple[Type, Type])rrrrirrhr^rGrrorrrrrkrRrrrs)rrnrrrr)rrr^rGrr)rrirrn)rrrr) rrrrirrhrrprrn)rrrrGrr)rrrrirrhrrorrprrr^rGrr)rrrrirrhrrorrprSequence[Type | None]rrr^rGrz&tuple[CallableType, list[Type | None]])rr*) rrrrirrnrrpr!rr list[int])rrrrtr^rGrr)rrr/rnr;rhr<rorrpr^zContext | NonerRrrrkrr)rrr/rnr;rhr<ror=rdr^rGrztuple[bool, bool])rRrrrr^rGrr)rrnrrhrrirrrrpr^rGrTzArgChecker | NonerRrrr)rtrrurrvr=rrrjrrwrrrrRrr^rGrkrGrr)rrrrirrhrrorrkrRrr^rGrrs) rrnrrhrrorrrr)rrrrirrnrrhrrorrkrRrr^rGrrq)rrrrnrrhrrorrir^rGrr)rrnrrrr)r)rrrrirrnrrhrrorrkrRrrrr^rGrrrzlist[tuple[Type, Type]] | Noner)rzSequence[Expression]rSequence[Type]rzIterator[None])rzlist[ProperType]rzAnyType | CallableType)rrnrrhrrorrirrr^rGrr) rrrrtr^rGrrrr)rrirrrrs) rrrrirrhrror^rGrrs)r.rVrTrrr)r.rVrTrr*rrrr)rrrrr^rGrr)rr)rrrrrr)rrrrrr)r.rRrr)r.rfrr)r.rArr)r.rNrr)r.rErr)r.rKrr)r.r[rr)r.rDrr)rrMrr)rrrrr.rrQzset[tuple[Type, Type]] | Noner/rr3rrr)r'rrrrrirrhr^rGrrrrrrs)r'rrrrrirrhr^rGrrrrs)rrrrrrrrirrhr^rGrrs)rfrr!rrnrMrCrrorMr^rGrrs) r'rrrr rMr^rGrrrrs)r.r?rr)r.rrrr)r.rQrr) r!rr.rQrzProperType | Nonerrrr)rrrr)rrrjrrr)r!rrrdrr)rLrMrzlist[int] | None)r!rrLrMrr)r!rrr)rrrLrMrrrztuple[Type, set[str]])rrnrLrMr^rGrr)rrCrr)rr>rr)rrarr)rrarr)rrlrr)rrkrr)rrrKrGrLrrr)rrrrvrKrGrrn)rrrrvrKrGrr)r.rUrr)r.rcrr)r.ListExpr | SetExpr | TupleExprr@rrr)rrnrr)r.rwrrrOrrr)rrjrKrrr)r.rjrr)r.rIrr)r.rIrkrrr)r.rIrr)r^rr}rIrz tuple[list[TypedDictType], bool])r.rSrr)r.rSrz/tuple[CallableType | None, CallableType | None])r.rgrr)r.rgrzType | tuple[Type, Type])r.rdrr)r.rTrr)r.rbrr)r.rPrr) rrPrrrrrzlist[Type] | Nonerr)r.rJrr)r.z'GeneratorExpr | DictionaryComprehensionrr)r.rFrmrrr)FT) rzdict[Expression, Type] | NonerrMr^rrmrrrrr)rrrr)NFFF) rrMrrrmrrrrrrr)rrMrrrr)r;rrr)rr)r;rr^rGrr)r.rtrr)r.r@rmrrr) rrrKrGrzstr | ErrorMessager*rrr)r.rurmrrr)r.rirr)r.rorr)r.r]rr)r.rqrr)r.rZrr)r.rXrr)r.rLrr)r.rmrr)r.r_rr)r.rerr)rrMrXrrr)rrMrXrrrrr)rtrrrrr)rrrr__annotations__r$r(r1r+r=r6rSrrrvrprrrrrrrrrrrrrOrrrArDrGrrIrJrprvr}rrrrrrrr2rrrrrrr+r r r rrr0r4rrTrr}rrr~rr{rrrrrrrrrrrZr\rrrrrrr r(rOr6r?r8r^r_rzrrrrrrrrrrrrrrrrrrrrrrrQr,rr;r=rEr?r:rVr`rirlr{rrrrrrrrrrrrrrrrrqrrMrrUrWrr!rr$rr8r@rCrFrHrKrNrPrRrTrRr7rr,rnr_rrrr r +s "! ##0/** N99*4 %*4*4 *4 $2 *4  *4X  +f!% %.-.-.- .-  .-.- .-`3$4 R VpG.8,, M_(-(-!(-( (-  (-  (-!(- (-T0+D0+N[0+ <0+d666, 6 & 6  6pR  ;    11;1 1 ! 1  1( QTX # 0P  ]],] ] ! ] & ] ]~0# *1I- #_$56"_$56$,.?#@!NO#DE AN=%PN "))'*)14) )VGG!G G / G * GGG!GG GR%%%! % / % M % %@   !    /  E   $   !    /   C   >26#''!'' ' ! '  '/'!' 'R'/? &='=5?=FM= !=H" 00 0" 0 ! 0  0 0d*D26+/$(#'%)xYxYxY! xY  xY / xY)xY"xY!xY#xY xYts's's'! s'  s' / s')s'"s'!s' s'j0,-\  #%#%#%! #% * #%  #%JS $S 5<S S jIR!IRIR! IR / IR * IRIRIR IRV;*!;*;*! ;* / ;* * ;*1;*;*;* 0;*z---- - * -  - -^Q'Q8MQX_Q Q8$($(NN!N$ N 2 N * N N!N"N N`;+;+!;+$ ;+ 2 ;+ $ ;+;+ ;+z  03 >E   ,(,#'KK!K K  K * KK%K!K KZ++#+ +  +  + ++!+++ +ZMMM! M / M " M!MM M^9&9&!9&/ 9&  9&  9&vR6-R6R6 R6 ! R6 / R6"R6!R6R6 "R6h-!  /    *$#$8J$ $bd-dd d ! d / d"d!d $ddd (dLL .) .6D .  . .P d33!3/ 3  3  33 3t"'   %       TLLL! L / L  L L KO(((,(6G( (T  &* 5<  &;!^F EEG134k;ZSj*+/48#$ANANAN ( AN 2 ANANAN ANT&*!%%`%`%` %` ! %`  %`#%`%` %`\&*KKK K ! K  K#K K8       !     D.)/V `KPC:C:(/C:CGC: C:J6W6W%36W:A6W 6WpJ/J/,J/3:J/ J/XA?./.EH. .` !6F YgREN 1 1.; 1  1QUf"/7 )4&IPKOKO 8KOZQ$fP(dH    2.2 Z  Z Z Z + Z  ZD"H#WJOl#(,0 ` *`` `  ` &* ` `& *%)"'!& QQ"Q Q  Q  Q Qf ) B   &=G* UZ#*<MQ .:x //// / //#20VV ,0HL  PU,0HL <@  rr c6|jt|S)zWhether t contains an Any type)rq HasAnyType)rignore_in_type_objs rrr s 88J12 33rcLeZdZdfd ZddZd fd Zd dZd dZd dZxZ S) rzcNt|tj||_yr)superr$r ANY_STRATEGYr{)r#r{ __class__s rr$zHasAnyType.__init__s ++,"4rc<|jtjk7Sr)r?rr5r#rs r visit_anyzHasAnyType.visit_anys}} 6 666rc\|jr|jryt| |S)NF)r{rr~visit_callable_type)r#rrs rrzHasAnyType.visit_callable_types'  " "q}}w*1--rc|jr |jgng}|j|jg||jzSr)r0rL query_typesrrr#rrLs rvisit_type_varzHasAnyType.visit_type_vars=!"199+b 9 9AHH DEErc||jr |jgng}|j|jg|Srr0rLrrrs rvisit_param_speczHasAnyType.visit_param_spec#4!"199+b 9 9::rc||jr |jgng}|j|jg|Srrrs rvisit_type_var_tuplezHasAnyType.visit_type_var_tuple'rr)r{rrr)rrrrrrrr)rrrr)rrrr)rrrr) rrrr$rrrrr __classcell__rs@rrzrzs"57. F;;rrzcnt|}t|txr|jjdk(S)z;Whether t came from a function decorated with `@coroutine`.typing.AwaitableGenerator)rrrrrrs rr/r/,s,A a " Uqvv:U'UUrc t|}t|trI|jjdk(r0t |j dk\rt|j d}t|txr|jjdk(S)z9Whether t came from a function defined using `async def`.rr}ztyping.Coroutine)rrrrrrrrs rr.r.2sk A1h FFOO: : K1  AFF1I & a " Lqvv:L'LLrcft|}t|txrt|jSr)rrrrrrs rrErEJs&A a # 5QWW 5rct|dkDxr]t|dk(xr4|dtjk(xr|dtjk( xrt fd|D S)Nrrrc3K|]9}|tjk(xrtt|t ;ywr)rr7rrr)rrwr;r/s rrz'is_duplicate_mapping..`sJ  Ou . P|A?OO P s?A)rrr6r7r)mappingr/r;s ``rr6r6Os G q LA  <WQZ(ENN: <WQZ(EOO;      rc&|j|S)z>Return a copy of a callable type with a different return type.r)r)rrs rrrhs ??L? 11rc,eZdZdZdfd ZddZxZS)r zQuery whether an argument type should be inferred in the second pass. The result is True if the type has a type variable in a callable return type anywhere. For example, the result for Callable[[], T] is True if t is a type variable. c@t|tjyrr~r$rrr#rs rr$z ArgInferSecondPassQuery.__init__u ++,rcR|j|jxs t|Sr)rrrrs rrz+ArgInferSecondPassQuery.visit_callable_typexs! ,@ a0@@rrer)rrrrr$rrrs@rr r ms-Arr c@|duxr|jtSr)rqHasErasedComponentsQueryrs rrr}s D= AQXX&>&@AArc,eZdZdZdfd ZddZxZS)rz.is_typetype_likesQ sH % T3 -C#//2C T3)Rchh.?.??.R rTc36K|]}t|ywrr)rrrks rrz-arg_approximate_similarity..s`-dF;`r>c36K|]}t|ywrr)rrrms rrz-arg_approximate_similarity..s`-fd;`r>rrl)rrrrrrrrrrrrrrrrrrrrrr )rmrkrs`` rrrsV $F V $F&+&(0&+&(0 &,' f|ZB C$4V$<&)$`H]H]H_```&)$`H]H]H_```&-( fm ,)&//6BB&(# fl +__F fj )\\!_--F fi (#F+F fh 'FKK6;;??,J i**62I4H4H4P QQrc t|ry|Dcgc](}t|||j|jfd*}}t D]\}}t |dst |D cgc]\} } | |r| | |f} } } g} g} | D]J\} }|| }| j |j|D] }| j |j|"Lt| rt| ryycc}wcc} } w)aMay an argument containing 'Any' cause ambiguous result type on call to overloaded function? Note that this sometimes returns True even if there is no ambiguity, since a correct implementation would be complex (and the call would be imprecisely typed due to Any types anyway). Args: items: Overload items matching the actual arguments arg_types: Actual argument types arg_kinds: Actual argument kinds arg_names: Actual argument names Fc|Srrrs rrz/any_causes_overload_ambiguity..s IVWLrT)r{) rrrrrcrrr?r)rrrrrractual_to_formalarg_idxr]item_idxlookupmatching_formals_unfilteredmatching_returnsmatching_formalsformalsmatched_callablerks ` rrrsB&l#     y$..$..BX 'y1 T :)22B(C+$Hf'?6'?++ '+ " ! %@ P!'#(?  ''(8(A(AB &PF$++,<,F,Fv,NOP P""23NK[<\34 C+s -C6.C;c8sytfdddDS)NTc3<K|]}t|dyw)rNr<)rrrs rrz!all_same_types..s T" and "f(x: List[Tuple[T, S]]) -> Tuple[T, S]". Both callables use typevars named "T" and "S", but we treat them as distinct, unrelated typevars. (E.g. they could both have distinct ids.) If we pass in both callables into this function, it returns a list containing two new callables that are identical in signature, but use the same underlying TypeVarType for T and S. This is useful if we want to take the output lists and "merge" them into one callable in some way -- for example, when unioning together overloads. Returns both the new list of callables and a list of all distinct TypeVarType objects used. ) rr)r rrrrrrrr&)rrunique_typevarsr rtrenamer)r;s rrrs&"$F.0O#%I    /7FF&& 6{{.!"}6F&GH %b+666,.OD)$$R( / 5ruu  6!0F f#& 9 rclt|}t|tr|j |jS|S)z>If possible, get a more precise literal type for a given type.)rrrr[rs rrrEs2 # C#x S%9%9%E### Jrc&t|tr0|j}t|txr|jt vSt|t rA|j}t|txr#tt|jtSy)z-Returns 'true' if the given node is a LiteralF) rrQrur`rrrYrrrrtr)rru underlyings rrrMst$ "yy$(PT]]>P-PP$!YY *i0 Z J-- . 6   rct|}ddh}t|trtd|jDSt|t r|j j|vryy)z?Is this one of builtin byte types, or a union that contains it?rrc32K|]}t|ywr)rXrs rrz&has_bytes_component.._s=a&q)=rTF)rrrrrrrr)r byte_typess rrXrXZsW # C"$89J#y!=399===#x SXX%6%6*%D rcjt|}t|tr |jr|j St|t r |j }t|trt|j}t|tr t|}t|tr |jSy)zXGets the TypeInfo for a type, indirecting through things like type variables and tuples.N) rrrrrrrrrrrrrrs rrres # C#|$):  #x hh#{#coo.#y!S!#x xx rc|sy|jdd}|tjjvxsB|tjjvxs |tj jvS)NFrr3)splitrrrrr)r short_names rrrxso $R(Ji**1133 = 55<<> > = 33::< <rcD|t|tr |jy|Sr)rrrrs rrMrMs y 1k2affn Hrct|}t|tryt|trt d|j DSy)NTc32K|]}t|ywr)rB)rrs rrz'is_type_type_context..sH$'-HrF)rrrrrrr$s rrBrBs;g&G'8$'9%H'--HHH r)rrrr)rr`rrkrrrf)rrr{rrr)rrur/rnr;rhrr)rrrrrr)rrrr)rmrrkrrr) rrrrnrrnrrhrrorr)rrnrr)rzSequence[CallableType]rz,tuple[list[CallableType], list[TypeVarType]])rrrrrgr)rrrzTypeInfo | None)rrkrr)rrrzPartialType | None)r^rrr(#r __future__renumrr collectionsrcollections.abcrrr contextlibrr r r r r r rrr rrr mypy.checkerrmypy.errorcodes errorcodesrrrrrrrr mypy.argmaprrrmypy.checker_sharedrmypy.checkmemberrrmypy.checkstrformatrmypy.erasetyper r!r" mypy.errorsr#r$r%mypy.expandtyper&r'r(r) mypy.inferr*r+r, mypy.literalsr- mypy.maptyper. mypy.meetr/r0mypy.message_registryr1 mypy.messagesr2r3 mypy.nodesr4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhrirjrkrlrmrnrorprqrrrsrtru mypy.optionsrv mypy.pluginrwrxryrzr{mypy.semanal_enumr| mypy.stater} mypy.subtypesr~rrrrmypy.traverserr mypy.typeanalrrrrrrr mypy.typeopsrrrrrrrrrrrrrrrrr mypy.typesrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmypy.types_utilsrrrrmypy.typestater mypy.typevarsr mypy.utilr mypy.visitorrrrrxrrrrrrrruniqueEnumrrrrr rr r r BoolTypeQueryrzr/r.rEr6rr rrrrrrrrrrrXrrrMrBrrrrsM"  #882FFCVVVWW:@6[[FF a`!2@.5DDDDDDDDDDDDDDDDDDJ-)0&***********V &'(*" 4$S,QXY[__ J E &U &UI L<OyO (//U/&--E-%++5+__ )$/1K__ D4 ;$$;4V M06  &0@M 22 Ae11 A Bu22GE$7$7<R~7 777 7 + 7  7t= *%*1*Z & r