
    mi۟                      U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
mZ ddlmZmZ ddlmZmZmZmZmZmZ ddlmZmZ ddlZddlmZ dd	lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% dd
l&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6 ddl7m8Z8m9Z9m:Z: ddl;m<Z<m=Z=m>Z>m?Z? ddl@mAZAmBZB ddlCmDZDmEZEmFZF ddlGmHZH ddlImJZJ ddlKmLZLmMZM ddlNmOZO ddlPmQZQmRZR ddlSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZmZmZ ddlmZmZmZ dd lmZ dd!lmZmZmZmZmZmZmZmZ dd"lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dd#lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dd$lmZmZmZmZ dd%lmZ dd&l mZ dd'lmZ eeee^eeeeee         ehehg
df         Zd(ed)<   d*Zd+ed,<   g d-Zd+ed.<   h d/Z	d+ed0<    G d1 d2e
          Zd~d7Z G d8 d9e
          Zej         G d: d;ej                              Zej        Zd+ed<<   ej        Zd+ed=<   ej        Zd+ed><    G d? d@ee         e+          ZdddCZ G dD dEe%j                  Zd~dFZd~dGZd~dHZddOZddSZ G dT dUe%j                  Z ddWZ! G dX dYe%j                  Z"ddZZ# G d[ d\e%j                  Z$dd_Z%ddgZ&ddiZ'ddmZ(ddpZ)ddsZ*ddtZ+ddvZ,ddyZ-dd{Z.dd}Z/dS )zGExpression type checker. This file is conceptually part of TypeChecker.    )annotationsN)defaultdict)IterableIteratorSequence)contextmanagernullcontext)CallableClassVarFinalOptionalcastoverload)	TypeAliasassert_never)	applytype	erasetypejoinmessage_registrynodes	operatorstypes)ArgTypeExpandermap_actuals_to_formalsmap_formals_to_actuals)ExpressionCheckerSharedApi)analyze_member_accesshas_operator)StringFormatterChecker)constant_fold_expr)
erase_type!remove_instance_last_known_valuesreplace_meta_vars)	ErrorInfoErrorWatcherreport_internal_error)expand_typeexpand_type_by_instancefreshen_all_functions_type_varsfreshen_function_type_vars)TypeTranslationErrorexpr_to_unanalyzed_type)ArgumentInferContextinfer_function_type_argumentsinfer_type_arguments)literal)map_instance_to_supertype)is_overlapping_typesnarrow_declared_type)ErrorMessage)MessageBuilderformat_type)I	ARG_NAMEDARG_POSARG_STAR	ARG_STAR2IMPLICITLY_ABSTRACTLAMBDA_NAMELITERAL_TYPEREVEAL_LOCALSREVEAL_TYPEUNBOUND_IMPORTEDArgKindAssertTypeExprAssignmentExpr	AwaitExpr	BytesExprCallExprCastExprComparisonExprComplexExprConditionalExprContext	DecoratorDictExprDictionaryComprehensionEllipsisExprEnumCallExpr
Expression	FloatExprFuncDefGeneratorExpr	IndexExprIntExpr
LambdaExprListComprehensionListExprMaybeTypeExpression
MemberExprMypyFileNamedTupleExprNameExprNewTypeExpr	NotParsedOpExprOverloadedFuncDefParamSpecExprPlaceholderNodePromoteExprRefExpr
RevealExprSetComprehensionSetExpr	SliceExprStarExprStrExpr	SuperExpr
SymbolNodeSymbolTableNodeTempNode	TupleExprr   TypeAliasExprTypeApplicationTypedDictExprTypeFormExprTypeInfoTypeVarExprTypeVarLikeExprTypeVarTupleExpr	UnaryExprVar	YieldExprYieldFromExprget_member_expr_fullname)PRECISE_TUPLE_TYPES)FunctionContextFunctionSigContextMethodContextMethodSigContextPlugin)
ENUM_BASES)state)find_memberis_equivalentis_same_type
is_subtypenon_method_protocol_members)all_name_and_member_expressionshas_await_expressionhas_str_expression)TypeVarLikeScope)TypeAnalysercheck_for_explicit_anyfix_instancehas_any_from_unimported_typeinstantiate_type_aliasmake_optional_typeset_any_tvarsvalidate_instance)callable_typecustom_special_methoderase_to_union_or_bound
false_onlyfixup_partial_typefreeze_all_type_varsfunction_typeget_all_type_varsget_type_varsis_literal_type_likemake_simplified_unionsimple_literal_type	true_onlytry_expanding_sum_type_to_uniontry_getting_str_literalstuple_fallbacktype_object_type))LITERAL_TYPE_NAMESTUPLE_LIKE_INSTANCE_NAMESAnyTypeCallableTypeDeletedType
ErasedType
ExtraAttrsFunctionLikeInstanceLiteralTypeLiteralValueNoneType
Overloaded
ParametersParamSpecFlavorParamSpecTypePartialType
ProperType	TupleTypeTypeTypeAliasTypeTypedDictType	TypeOfAnyTypeType	TypeVarIdTypeVarLikeTypeTypeVarTupleTypeTypeVarTypeUnboundTypeUninhabitedType	UnionType
UnpackTypefind_unpack_in_listflatten_nested_tuplesflatten_nested_unionsget_proper_typeget_proper_typeshas_recursive_typeshas_type_varsis_named_instancesplit_with_prefix_and_suffix)is_generic_instanceis_overlapping_noneis_self_type_likeremove_optional)
type_state)fill_typevars)ExpressionVisitor
_TypeAlias
ArgChecker   r   
MAX_UNIONS)builtins.setzbuiltins.frozensetztyping.KeysViewztyping.ItemsViewzbuiltins._dict_keyszbuiltins._dict_itemsz_collections_abc.dict_keysz_collections_abc.dict_itemsOVERLAPPING_TYPES_ALLOWLIST>   builtins.memoryviewbuiltins.bytesbuiltins.bytearrayOVERLAPPING_BYTES_ALLOWLISTc                      e Zd ZdZdS )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__     f/var/www/html/bestrading.cuttalo.com/scripts/kaggle-env/lib/python3.11/site-packages/mypy/checkexpr.pyr   r      s           r   r   tr   returnboolc                    t          | t                    r	| j        rdS t          |           } t          | t                    p2t          | t
                    ot          d | j        D                       S )NFc              3  4   K   | ]}t          |          V  d S N)allow_fast_container_literal.0its     r   	<genexpr>z/allow_fast_container_literal.<locals>.<genexpr>  s+      (\(\b)Eb)I)I(\(\(\(\(\(\r   )
isinstancer   is_recursiver   r   r   allitemsr   s    r   r   r      ss    !]##  uAa"" 1i  \S(\(\TUT[(\(\(\%\%\r   c                      e Zd ZdZdS )FinishedzDRaised if we can terminate overload argument check early (no match).Nr   r   r   r   r   r     s        NNNNr   r   c                      e Zd ZdZdZdZdZdS )
UseReversezCUsed in `visit_op_expr` to enable or disable reverse method checks.r         N)r   r   r   r   DEFAULTALWAYSNEVERr   r   r   r   r     s#        MMGFEEEr   r   USE_REVERSE_DEFAULTUSE_REVERSE_ALWAYSUSE_REVERSE_NEVERc                     e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ddZddZddZdddZddd dd(Z	dd,Z
dd/Zddd2Zdd5Zddd6Zdd7Zdd<Zdd=Zdd@ZddAZddBZddMZddQZddWZddZZdd\Zdd]ZddaZ	 dҐddeZddfZddjZdkgdldmgdnZdoedp<   dqdrgidsdtgidsdtgidsdudrgidvZ dwedx<   ddyZ!dd|Z"ddZ#ddZ$ddZ%ddZ&ddZ'	 	 dܐddZ(ddZ)ddZ*	 dҐddZ+ddZ,	 	 	 	 	 dddZ-ddZ.ddZ/ddZ0ddZ1ddZ2ddZ3ddZ4ddZ5ddZ6ddZ7ddZ8ddZ9	 	 dܐddZ:ddÄZ;ddĄZ<	 	 dܐddǄZ=ddτZ>ddЄZ?ddӄZ@ddՄZAddքZBddׄZC	 ddd܄ZDdd݄ZEeFdd            ZGddZHddZI	 dd dZJddZKddZLdddZM	 dҐddZNddZOddZPddZQddZRd	dZSd
dZTdd ZUddZVddZWddZXddZYdd
ZZddZ[dbdbdddddZ\	 	 dܐddZ]	 dҐddZ^ddZ_ddZ`	 ddd!Zadd"Zbdd#Zcdd%Zddd'Zedd)Zfdd*Zg	 	 dܐdd,Zhdd-Zidd.Zjdd1Zkdd4Zld d5Zmd!d6Zn	 dd"d:Zod#d<Zpd$d>Zqd%d@Zrd&dBZsd'dDZtd(dEZud)dHZvd*dKZwddLd+dOZxd,dQZyd-dSZzd.dUZ{d/dWZ|d0dZZ}d1d\Z~d2d^Zd3d`Zd4daZd5dcZd6deZd7dfZd8diZd9dkZd:dmZd;doZd<dqZd=drZd>dtZd?dvZd@dxZ	 dҐdAd~ZdBdZdCdZddDdZ	 	 dEdFdZdGdZ	 	 	 	 dHdIdZdҐdJdZdKdZdLdZddZddZdMdZdNdZddOdZ	 ddPdZddQdZdRdZdSdZdTdZdUdZdVdZdWdZdXdZdYdZdZdZd[dZdLdZdLdZed\d            Zed]d            Z	 dd]dZd^dZd^dZd_dZdbS (`  ExpressionCheckerz^Expression type checker.

    This class works closely together with checker.TypeChecker.
    mypy.checker.TypeCheckerchkr5   msgzlist[Type | None]type_contextzdict[Expression, ProperType]resolved_typer   strfrm_checkerr   pluginzArgumentInferContext | None_arg_infer_context_cacheper_line_checking_time_nsdict[int, int]r   Nonec                h   || _         || _        || _        || _        |j        j        du| _        d| _        dg| _        i | _	        t          | j         | j                  | _        i | _        d| _        | j         j        j         t          _        d| _        i | _        d| _        d| _        d| _        dS )z%Construct an expression type checker.NF)r  r  r  r  optionsline_checking_statscollect_line_checking_statsin_expressionr  type_overridesr   r  r  	is_calleeold_type_inferencer   infer_polymorphicr  
expr_cachein_lambda_expr_literal_true_literal_false)selfr  r  r  r  s        r   __init__zExpressionChecker.__init__/  s     )B&+.;+JRV+V( #!F 794TXtxHH +/8+;+N'N
$(,%  	 $.2/3r   c                F    i | _         | j                                         d S r   )r  r  clearr#  s    r   resetzExpressionChecker.reset[  s$    r   er^   r   c                    |                      |          }|                     ||          }| j                            |j        |           |S )z_Type check a name expression.

        It can be of any kind: local, member or global.
        )analyze_ref_exprnarrow_type_from_binderr  check_deprecatednode)r#  r)  resultnarroweds       r   visit_name_exprz!ExpressionChecker.visit_name_expr_  sK    
 &&q))//6::!!!&!,,,r   Frf   lvaluer   c                   d }|j         }t          |t                    r |j        rt	          t
          j                  S t          |t                    rJ|                     ||          }t          |t                    r| j
                            ||||          }n>t          |t                    r|                     |j        |          }nt          |t                    ri|j        Z| j
                                        r'|j        r | j
                            |j        |           t	          t
          j                  }n|j        }nt          |t*          t,          t.          t0          t2          f          r|                     |||j        p|          }nAt          |t8                    rJ d|j        d            t	          t
          j                  }t          |t,                    rt          |t<                    r<t          |j        t@                    r"|j!        |j        _!        |j"        |j        _"        tG          | j$        d                   rtK          j&        |          }|J |S )NFzPlaceholderNode z leaked to checker)'r.  r   r^   is_special_formr   r   special_formr{   analyze_var_refr   r  handle_partial_var_typerL   varrb   typein_checked_functionr   handle_cannot_determine_typename
from_errorrS   rv   r   r\   rx   analyze_static_referenceis_alias_rvaluerd   fullnamer   ret_typer   linecolumnis_type_type_contextr  r   erase_typevars)r#  r)  r2  r/  r.  s        r   r+  z"ExpressionChecker.analyze_ref_expri  s?   "va"" 	3q'8 	391222dC   	3))$22F&+.. S99&&$PQRRi(( 	3))$(A66FF/00 	3y 8//11 Hdj HH99$)QGGG !566w)XWXX 	3224A<M<WQWXXFF$00 UTTTTTTTT Y122FdH%% 	:&,// 2J5 5 2
 ()v$)*&#D$5b$9:: : #1&99!!!r   Tinclude_modulessuppress_errorsr.  rn   ctxrK   	is_lvaluerH  rI  c                  t          |t          t          t          f          r |j        pt          t          j                  S t          |t                    r#t          || 
                    d                    S t          |t                    rW|j        r|                     |          S |j        dk    rt          t!                                S t#          || j
                  S t          |t$                    rZ|r| j                                        nt+                      5  |                     |||          cddd           S # 1 swxY w Y   nt          |t.                    r| 
                    d          S t          |t0          t2          f          r|                                 S t          |t6                    r0|r|                     |          nt          t          j                  S t          t          j                  S )a  
        This is the version of analyze_ref_expr() that doesn't do any deferrals.

        This function can be used by member access to "static" attributes. For example,
        when accessing module attributes in protocol checks, or accessing attributes of
        special kinds (like TypeAlias, TypeInfo, etc.) on an instance or class object.
        # TODO: merge with analyze_ref_expr() when we are confident about performance.
        builtins.functionztypes.NoneTyperJ  alias_definitionNztyping.TypeVar)r   r{   rL   rb   r:  r   r   r6  rS   r   
named_typerv   typeddict_typetypeddict_callablerA  r   r   r   r   r  filter_errorsr	   alias_type_in_runtime_contextrw   rc   ry   object_typer\   module_typer>  )r#  r.  rJ  rK  rH  rI  s         r   r?  z*ExpressionChecker.analyze_static_reference  s    " dS)->?@@ 	b9?	(> ? ??g&& 	b t7J'K'KLLLh'' 	b" ?..t444"222

+++'do>>>i(( 	b .=O'')))+--  99cI :                   k** 	b??#3444}.>?@@ 	b##%%%h'' 	b-<a4##D)))')J`BaBaay+,,,s   %E

EEr9  r{   contextc                   |j         rt          |j                   }t          |t                    rj|j        dk    r|                     d          S |                                 r|j        |j        S |j        dv r| 	                    |j        dk    d          S |j         S |j
        s9| j                                        r | j                            |j        |           t          t          j                  S )Nz
typing.Anytyping._SpecialForm>   TrueFalserZ  builtins.bool)r:  r   r   r   rA  rP  is_literal_contextlast_known_valuer=  infer_literal_expr_typeis_readyr  r;  r<  r   r   r6  )r#  r9  rW  var_types       r   r7  z!ExpressionChecker.analyze_var_ref  s    8 	3&sx00H(H-- ]<<//??+@AAA**,, 51J1V#44800077F8JO\\\8O< IDH$@$@$B$B I55chHHH91222r   r\   r   c                R   	 |                      d          }n7# t          $ r* |                      d                                          }Y nw xY wi }t                      }|j                                        D ]\  }}|j        st          |j        t                    r!|j        j
        r|                    |           |j        t          t          j                  ||<   l|                     |j        |j        ddd          ||<   t!          |||j                  |_        |S )Nztypes.ModuleTypebuiltins.objectFTrG  )rP  KeyErrorcopy_modifiedsetnamesr   module_publicr   r.  r{   is_finaladdr   r   r>  r?  r   rA  extra_attrs)r#  r.  r/  module_attrs	immutabler=  ns          r   rV  zExpressionChecker.module_type  s?   	H__%788FF 	H 	H 	H
 __%677EEGGFFF	H )+EE	z'')) 	 	GD!? !&#&& $16? $d###v~%,Y-A%B%BT"" &*%B%BFAFE5RV &C & &T"" (iOOs    1AArF   allow_none_returnc                    |j         rat          |j         t                    r!|j         j        s|                     |           |                     |j         | j        d                   S |                     ||          S )zType check a call expression.r4  ro  )analyzedr   r]   is_typedvisit_call_expr_inneracceptr  )r#  r)  ro  s      r   visit_call_exprz!ExpressionChecker.visit_call_expr  s{    : 	B!*n55 .aj>Q . **1---;;qz4+<R+@AAA))!?P)QQQr   baserQ   c                   t          |t                    sdS t          |j        t                    r|j        j        dS t          |j        t
                    o+t          t          |j        j                  t                    S )NFT)	r   rf   r.  rv   rQ  r   r   targetr   )r#  rw  s     r   refers_to_typeddictz%ExpressionChecker.refers_to_typeddict  ss    $(( 	5di** 	ty/G/S4$)Y// 
JDI,--}5
 5
 	
r   c           	                               j                  s9t          j        t                    r                      j        j                  rt                               j        d                    }t          |t                    rTt          |j                  }t          |t                    sJ  
                    |j        j        j        |          S t          j        t                    rɉj        j        dv rt!          j                  dk    rt"          j                            j        d                   D ]u}d }t          |t                    r1	  j                            |j                  }n# t,          $ r Y nw xY wt/          |          r' j                            j        j        d           |rt          |j        t6                    rlt          |j        j                  }t          |t:                    r' j                            j        j        d           t          |t<                    r	t          |t                    r!t          |j        t@          tB          f          st          |t                    r|rt          |j        t6                    rp|j        j"        sdt          t          |j        j                  x}tF                    r|j$        s/ j        j%        j&        dk    s j        '                               t          |tP                    rt          |j        tR                    rf|j        j*        r( j                            j        j        d	           C|j        j+        r& j                            j        j        d
           w ,                               d }	t          j        tZ                    rt]          j        j        j        j        j        j         fd           fdt_          t!          j        j                            D             }
t          |
j        j        j        j         0                                 1                    d                    }	t                               j        |	dd                    }d }d }d t          j        tP                    r܉j        j2        pd t          j        j        t6                    r?t          j        j        j                  }t          |tf                    r|j4        j2        snt          j        tj                    rT j        6                    j        j7                  r0j        j        } j        8                    j        j7                  } j        j%        j9        r j        :                                rt          |t                    r||j;        ru|j        tx          k    re||J  =                    ||          r*t}          fd j        j%        j?        D                       s j        @                    |            A                    |||          }t          j        tP                    r`t!          j                  dk    rHj        j2        dv r B                               j        j2        dk    r C                               t          j        tj                    r%j        j        dk    r D                               t          |          }t          |tF                    rt          |jF                  }t          |t                    r%|jH        s j        jI        J                                 |sht          |t<                    rS K                    j                  r9 j        j        L                    |           t;          t          jN                  S |S )NTr  )r   
issubclassr  r  LiteralAny   
   	TypedDictNewTypec                D                         j        |                    S r   ru  args)ir)  r#  s    r   <lambda>z9ExpressionChecker.visit_call_expr_inner.<locals>.<lambda>J  s    $++afQi00 r   c                ^    g | ])}t          j        fd |         D                       *S )c                P    g | ]"}                     j        |                   #S r   r  )r   jr)  r#  s     r   
<listcomp>zFExpressionChecker.visit_call_expr_inner.<locals>.<listcomp>.<listcomp>N  s+    $Y$Y$YT[[%;%;$Y$Y$Yr   )r   join_type_list)r   r  r)  formal_to_actualr#  s     r   r  z;ExpressionChecker.visit_call_expr_inner.<locals>.<listcomp>M  sS        #$Y$Y$Y$Y$YEUVWEX$Y$Y$YZZ  r   rM  )rB  fallback)always_allow_anyr  c              3  T   K   | ]"}|k    p                     | d           V  #dS ).N)
startswith)r   prA  s     r   r   z:ExpressionChecker.visit_call_expr_inner.<locals>.<genexpr>  sT       ' ' A=!4!4WWW!=!=' ' ' ' ' 'r   )zbuiltins.isinstancebuiltins.issubclassr  format)Orz  calleer   rU   rw  r   ru  r   rB  r   check_typeddict_call	arg_kinds	arg_namesr  r^   r=  lenmypycheckerflattenr  lookup_qualifiedrd  is_expr_literal_typer  cannot_use_function_with_typer.  r   ry  r   r   rr  rs   rr   no_argsr   uses_pep604_syntaxr  python_versiontype_arguments_not_allowedrf   rv   rQ  
is_newtypetry_infer_partial_typerW   r   rangerU  rP  rA  r   r:  r[   has_typeexprlookup_typedisallow_untyped_callsr;  implicitr<   method_fullnameanyuntyped_calls_excludeuntyped_function_call check_call_expr_with_callee_typecheck_runtime_protocol_testcheck_protocol_issubclasscheck_str_format_callr   r   r   	ambiguousbinderunreachablealways_returns_nonedoes_not_return_valuer   r>  )r#  r)  ro  rR  rQ  typr.  ry  union_targetr  	arg_typescallee_typerU  memberrB  r  rA  s   ``             @@r   rt  z'ExpressionChecker.visit_call_expr_inner  s   $$QX..	!(I..	 ((77	
 "1QXQU1V1V!W!W,l;; !01C1L!M!M!.-@@@@@00"AKafaI[   qx**,	\!===AFq  |++AF1I66 '\ '\c8,, #x88BB#    (,, H::18=)UVWWW !Jty)<< !,TY-=>>F!&'22 !>>qx}eUVWWW !&(33 ! sI..;"3</=1QRR; sH--	;
 ; #49i88; !I-; #?49CS3T3T#T<V_``; );;  $x/>'II H77:::c7++ \
38X0N0N \x. \>>qx}k[\]]]], \>>qx}iYZ[[[##A&&&ah
++ 	5""00000        s18#56677  I (""))++)<==  L &KK,QUKVV
 

 ah(( 	B x(0DH!(-33 4()=>>fh// 4%{3H Bqx44B H%%ahm44B
 "h2218=AA H3	?,,..	? ;55	? $		?
  K//F$6"...//VDD ?3 ' ' ' ')?' ' ' $ $ ? ..{A>>>88Hk6
 
 ah(( 	2S[[A-=-=x $RRR00333x $999..q111ah
++ 	*0I0I&&q)))"8,,h	** 	=,X^<<Hh00 	*9K 	*HO'')))
 "	18X..	1 ((22	1
 HL..{A>>>9/000s   2F
FFc                Z   t          |j        t                    sJ d}t          |j        j        d          }t          |t
                    r|}n:| j                            |j        j                  rt          | j        	                    |j        j                            }t          |t                    r|j        j        r~t          |j        t                    rdt          |j        j        t
                    rE|j        j        |j        j                 j        }t          |t"                    rt          |          }t%          |          }t          |t                    r!t          |j        t
                    r|j        }|| j                            ||           dS dS )zSMore precise type checking for str.format() calls on literals and folded constants.Nz<unused>)r   r  r[   r    r  strr  r  r   r  r   r:  is_enumr^  r   valuerg  r   try_getting_literalr  r  )r#  r)  format_valuefolded_callee_exprr  
value_typebase_typs          r   r  z'ExpressionChecker.check_str_format_call  sy   !(J//////zJJ(#.. 	.-LLXqx}-- 	.!$("6"6qx}"E"EFFC3))6H$6 s3[AA6 s393??	6 !X^C,@,FGL
j$// 6)*55C*3//H(K00 .ZPS5T5T .'~#55aFFFFF $#r   rU  method_namer  
str | Nonec                   t          |          }t          |t                    r)|                                rt          |j                  }nt          |t
                    r|j        }d}t          |t                    r|j        j	        }nut          |t          t          f          r+|j        j                            |          }||j	        nd}n.t          |t                    rt          |          j        j	        }|r| d| S dS )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  )r   r   r   is_type_objrB  r   itemr   r:  rA  r   r   r  get_containing_type_infor   r   )r#  rU  r  	type_nameinfos        r   r  z!ExpressionChecker.method_fullname  s    &k22k<00 	+[5L5L5N5N 	+ *+*>??KKX.. 	+%*K	k8,, 	B#(1IIm[%ABB 	B',EEkRRD)-)9tIIY// 	B&{338AI 	//+///4r   c                ^   t          |t                    r|                     |j                  rdS t          |t                    r|j        t          | j                            |j                            }t          |t                    r|j
        }n^t          |t                    rG|                                r3t          |j                  }t          |t                    r|j
        }ndS dS |                    |j                  }|r|                     |j                  rdS dS )zPCheck if `node` refers to something explicitly annotated as only returning None.TNF)r   rf   defn_returns_noner.  r[   r   r  r  r  r   r:  r   r  rB  getr=  )r#  r.  r  r  rB  syms         r   r  z%ExpressionChecker.always_returns_none  s   dG$$ 	%%di00 tdJ'' 	DI,=!$("6"6ty"A"ABBC#x(( 	xC.. 3??3D3D *3<88h11 !#=DD 5u((49%%C t--ch77 tur   defnSymbolNode | Nonec                    t          |t                    rFt          |j        t                    o+t          t	          |j        j                  t                    S t          |t                    r t           fd|j	        D                       S t          |t                    rt	          |j                  }|j        s>t          |t                    r)t          t	          |j                  t                    rdS t          |t                    r8|j                            d          }|r                     |j                  rdS dS )z'Check if `defn` can _only_ return None.c              3  B   K   | ]}                     |          V  d S r   )r  )r   r  r#  s     r   r   z6ExpressionChecker.defn_returns_none.<locals>.<genexpr>  s1      KKt--d33KKKKKKr   T__call__F)r   rS   r:  r   r   rB  r   rb   r   r   r{   is_inferredr   r  r  r.  )r#  r  r  r  s   `   r   r  z#ExpressionChecker.defn_returns_none  s8   dG$$ 	di66 :	 233X< <  d-.. 	LKKKK
KKKKKKdC   	 !$),,C$sL11 s|<<hGG
 t#x((  hll:..  411#(;;  4ur   c                   t           j                            |j        d                   D ]}t	          | j                            |                    }t          |t                    rk|	                                rW|
                                j        r>|
                                j        s%| j                            t          j        |           d S Nr  )r  r  r  r  r   r  r  r   r   r  type_objectis_protocolruntime_protocolfailr   RUNTIME_PROTOCOL_EXPECTED)r#  r)  r  tps       r   r  z-ExpressionChecker.check_runtime_protocol_test   s    L((33 	M 	MD !5!5d!;!;<<B2|,,MNN$$M NN$$0M ((9	M .H!LLL	M 	Mr   c                   t           j                            |j        d                   D ]}t	          | j                            |                    }t          |t                    r|	                                ro|
                                j        rVt          |
                                          }|r3| j        j                            |
                                ||           d S r  )r  r  r  r  r   r  r  r   r   r  r  r  r   r  report_non_method_protocol)r#  r)  r  r  attr_memberss        r   r  z+ExpressionChecker.check_protocol_issubclass  s    L((33 	_ 	_D !5!5d!;!;<<B"l++ _0@0@ _R^^EUEUEa _:2>>;K;KLL _HL;;BNN<L<Ll\]^^^	_ 	_r   r  r   r  list[ArgKind]r  Sequence[str | None]r  list[Expression]orig_calleeType | Nonec                4   |rt          d |D                       rjt          d |D             |          }|                     ||          }||\  }	}
|                     ||	|||
          S t	          t
          j                  S t          |          dk    r|d         t          k    r|d         }t          |t                    r|                     ||j        ||          S t          |t                    r<t          |j        t                    r"|                     ||j        j        ||          S |s%|                     |i ||t                                S | j                            t$          j        |           t	          t
          j                  S )Nc              3  6   K   | ]}|t           t          fv V  d S r   )r7   r:   )r   aks     r   r   z9ExpressionChecker.check_typeddict_call.<locals>.<genexpr>  s,      IIy)44IIIIIIr   c                4    g | ]}|t          |          nd S r   )rl   )r   rn  s     r   r  z:ExpressionChecker.check_typeddict_call.<locals>.<listcomp>   s&    SSSA'!***4SSSr   kwargsr  r  r   )r   zipvalidate_typeddict_kwargs check_typeddict_call_with_kwargsr   r   r>  r  r8   r   rM   check_typeddict_call_with_dictr   rF   rr  rf  r  r  r   INVALID_TYPEDDICT_ARGS)r#  r  r  r  r  rW  r  r  r/  validated_kwargsalways_present_keys
unique_args               r   r  z&ExpressionChecker.check_typeddict_call  s     	1CIIyIIIII 	1 SSSSSUYZZF336&3QQF!8>5 "5<<,g{DW   9/000t99>>ilg55aJ*h// ::J,g{   *h// Jz?RT\4]4] ::J/5w    	b88Wk[^[`[`aaa&=wGGGy+,,,r   r  .Iterable[tuple[Expression | None, Expression]]3tuple[dict[str, list[Expression]], set[str]] | Nonec                   t          t                    }t                      }d }|D ]\  }}|r|                     |          }t	          ||          }	d }
|	rt          |	          dk    r|	d         }
|
8|p|}| j                            t          j	        |t          j                    d S |g||
<   |                    |
           |}|                     ||||          s d S | j        j        j        rM|Kg }|j        D ]$}||j        vr||vr|                    |           %|r| j                            ||           ||fS )Nr  r   code)r   listrf  ru  r   r  r  r  r   $TYPEDDICT_KEY_MUST_BE_STRING_LITERALcodesLITERAL_REQrj  validate_star_typeddict_itemr  extra_checksr   required_keysappendr  "non_required_keys_absent_with_star)r#  r  r  r/  r  last_star_founditem_name_expritem_argkey_typevaluesliteral_valuekey_contextabsent_keyskeys                 r   r  z+ExpressionChecker.validate_typeddict_kwargs=  s    T""!ee(. 	  	 $NH  ;;~661.(KK $ .c&kkQ..$*1IM ("0"<HKHMM(M#". "   
  44
 .6JF=)'++M::::"*88ff.A     44  8( 
	Z_-HK| , ,f222s&7H7H&&s+++ Z
 ;;KYYY***r   r
  r/  dict[str, list[Expression]]r  set[str]c                   t          |                     ||                    }g }t          |t                    r|g}nt          |t                    rt          |                                          D ]`}t          |t                    r|                    |           -|                     |          s| j	        
                    ||            dS an2|                     |          s| j	        
                    ||           dS t                      }|D ]}	||	j                                        z  }|D ]Њt          t	          j        fd|D                                 }
|
                    |           t#          fd|D                       rV|                               |         r2|         d         }t          |t                    s||
g|<   |
g|<   |
g|<   |                             |
           dS )zUpdate keys/expressions from a ** expression in TypedDict constructor.

        Note `result` and `always_present_keys` are updated in place. Return true if the
        expression `item_arg` may valid in `callee` TypedDict context.
        r  Fc                <    g | ]}|j         v |j                  S r   r   r   tdr  s     r   r  zBExpressionChecker.validate_star_typeddict_item.<locals>.<listcomp>  s(    %^%^%^cUWU]oobhsmooor   c              3  *   K   | ]}|j         v V  d S r   r  r  s     r   r   zAExpressionChecker.validate_star_typeddict_item.<locals>.<genexpr>  s+      BBr3"**BBBBBBr   r   T)r   ru  r   r   r   r   relevant_itemsr  valid_unpack_fallback_itemr  %unsupported_target_for_star_typeddictrf  r   keysrp   
make_unionset_liner   rj  )r#  r
  r  r/  r  inferredpossible_tdsr  all_keysr  argfirstr  s               @r   r  z.ExpressionChecker.validate_star_typeddict_itemo  sJ    #4;;xf;#M#MNNh.. 	$:LL),, 		()@)@)B)BCC ! !dM22 ! ''----88>> !HBB4RRR 55!! 00:: 	H::8XNNN5 UU 	( 	(B'HH 	( 	(C$%^%^%^%^l%^%^%^__ C LL"""BBBB\BBBBB (#'',,,
 #; 	("3KNE%eX66 , (-cls'*es#&%F3KK s""3''''tr   r  r   c                8   t          |t                    rdS t          |t                    r|j                            d          sdS t          || j                            d                    }t          d t          |j
                  D                       S )NTtyping.MappingFc              3  @   K   | ]}t          |t                    V  d S r   )r   r   r   as     r   r   z?ExpressionChecker.valid_unpack_fallback_item.<locals>.<genexpr>  s,      QQa:a))QQQQQQr   )r   r   r   r:  has_baser1   r  lookup_typeinfor   r   r  )r#  r  mappeds      r   r  z,ExpressionChecker.valid_unpack_fallback_item  s    c7## 	4#x(( 	0A0ABR0S0S 	5*30H0HIY0Z0Z[[QQ3CFK3P3PQQQQQQr   *list[tuple[Expression | None, Expression]]c                    |                      ||          }|]|\  }}|j        t          |                                          cxk    o)t          |j                                                  k    nc S dS )Nr  F)r  r  rf  r  r   )r#  r  r  rW  r/  r  _s          r   match_typeddict_call_with_dictz0ExpressionChecker.match_typeddict_call_with_dict  s     //vf/MM"(a'3/?/D/D/F/F+G+Gcccc3v|O`O`ObObKcKcccccc5r   c                    |                      ||          }||\  }}|                     |||||          S t          t          j                  S )Nr  )r  rW  r  r  )r  r  r   r   r>  )r#  r  r  rW  r  r/  r  r  s           r   r  z0ExpressionChecker.check_typeddict_call_with_dict  sm     //vf/MM4:1188''$7 9    9/000r   r  rv   r   c                    |j         J |j         j        }t          |t                    rt          |t                    sJ |                     ||j        j                  S )a  Construct 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_aliasry  r   r   r   typeddict_callable_from_contextr  	type_vars)r#  r  ry  s      r   rR  z$ExpressionChecker.typeddict_callable  s^     !---#*&*--S*V]2S2SSSS33FDI<OPPPr   N	variables Sequence[TypeVarLikeType] | Nonec           	        t          t          j                                                  fdj        D             t          j                                                  |                     d          |d          S )Nc                R    g | ]#}|j         v rt          j        nt          j        $S r   )r  rA   r7   ARG_NAMED_OPT)r   r=  r  s     r   r  zEExpressionChecker.typeddict_callable_from_context.<locals>.<listcomp>  sA        &*V-A%A%A!!wG\  r   builtins.typeT)r7  is_bound)r   r  r   r  r  rP  )r#  r  r7  s    ` r   r5  z1ExpressionChecker.typeddict_callable_from_context  s     $$&&''   "L   ""$$%%OOO,,
 
 
 	
r   c                b   |                                 j        r(j        z  }|r| j                            ||           j        |k    rj                                         k    sj                                         k    sO| j                            fdj                                         D             t                    |           j        |k    sM| j                            fdj                                         D             fd|D             |           j        k    rt          t          j                  S t          |          }t          |t                    r|}nFj        j        j         |                     j        j                  }n|                               }| j                                        5  | j        j        5  |                     |d |                                D             t2          j        gt7          |          z  |t          |                                           d d d           \  }}	d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          |          }
t          |
t8                    s}
|
j                                        D ]b\  }}||v rY||         }|D ]N}| j                            |||t=          t>          j         j!        tD          j#                  d| d	d
           Oc|S )NrW  c                .    g | ]}|j         v s|v |S r   r  )r   r  actual_keysr  s     r   r  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s;     # # #&"666#:L:L :L:L:Lr   )expected_keysrA  rW  c                &    g | ]}|j         v |S r   r  r   r  r  s     r   r  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s-     # # # #cVEY>Y>Y>Y>Y>Yr   c                &    g | ]}|j         v |S r   r  rD  s     r   r  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s-     ! ! ! #cVEY>Y>Y>Y>Y>Yr   c                    g | ]
}|d          S r   r   )r   r  s     r   r  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>-  s    555Ta555r   r  zTypedDict item ""
expression)lvalue_typervaluerW  r  lvalue_namervalue_name)$r  to_be_mutatedreadonly_keysr  readonly_keys_mutatedr  r   unexpected_typeddict_keysr  r   r   r>  r   r   r   r  r:  r4  rR  r5  rS  r  local_type_mapcheck_callable_callr  rA   r7   r  r   check_simple_assignmentr4   r   INCOMPATIBLE_TYPESr  r  TYPEDDICT_ITEM)r#  r  r  rW  r  r  assigned_readonly_keysinfer_calleeorig_ret_typer0  rB  	item_nameitem_expected_typeitem_values
item_valuerA  s    `             @r   r  z2ExpressionChecker.check_typeddict_call_with_kwargs  s&    kkmm 	X%063G%G"% X../Ew.WWW $777K6<K\K\K^K^<^<^6<#4#4#6#66622# # # # ##)<#4#4#6#6# # #
 !%[ 1 1# 3 	 	 	 (,???22# # # #'-|'8'8':':# # #! ! ! !':! ! ! $ 3 	 	 	 #k11 y3444%k22k<00 	L&LL #1=#66v7KLL  $CCFKK X##%% 	 	tx'> 	 	#77 65V]]__555"#c&kk1V[[]]##   M1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 #=11(M22 	 H-5^-A-A-C-C 	 	)I)F""$Y/"- 
 
JH44$6) *(,?EEL`   %Dy$C$C$C$0 5 	 	 	 	 s7   J)A6I+J+I/	/J2I/	3JJ	Jr  r[   
Var | Nonec                   t          |j        t                    r0t          |j        j        t                    r|j        j        j        sdS | j        j                                        }|r|j	        |j
        vrdS |j
        |j	                 }t          |j        t                    r&t          |j        j        t                    r|j        S dS )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)r   r  r^   r.  r{   is_selfr  scopeenclosing_classr=  rg  r:  r   )r#  r  r  r  s       r   get_partial_self_varz&ExpressionChecker.get_partial_self_varM  s     ty(++	49>3//	 	&	 4x~--// 	ty
224j#ch$$ 	CHM;)O)O 	8Otr   r  rj  discard)builtins.listr   zClassVar[dict[str, list[str]]]	item_argsextendre  updatebuiltins.dictr   )re  ri  zcollections.OrderedDictr   z)ClassVar[dict[str, dict[str, list[str]]]]container_argsc                   t          |j        t                    sdS |j        }t          |j        t                    rg|                     |j                  }|dS |\  }}|                     ||j        |          }|"||v r | j        	                    |||           dS dS dS t          |j        t                    r0t          |j        j        t                    r|j        j        dS |j        j        }|j        j        }|                     |          }|dS |\  }}t          |j                  }	|	|	j        dS |                     ||j        |          }
|
|                     |          }t$          j                            || j        j                  rV|	j        J |	j        j        }| j                            |||
g          }| j        	                    |||           dS dS dS dS dS )z-Try to make partial type precise from a call.N)r   r  r[   r  rf   get_partial_var&try_infer_partial_value_type_from_callr=  r  replace_partial_typerU   rw  rr  indexget_partial_instance_typer:  r  ru  r  r  is_valid_inferred_typer  rA  named_generic_type)r#  r)  r  retr9  partial_typesr  rw  ro  partial_typer  r  typenamenew_types                 r   r  z(ExpressionChecker.try_infer_partial_typeo  s#   !(J// 	Ffk7++  	P&&v{33C{!$C==acRRC3-#7#7--c3FFFFF #7#7Y// 	PJv{?OQX4Y4Y 	P{#/;#DK%E&&t,,C{!$C4SX>>L#|'>'FDDQUXYYJ%;;u--<66xAQRR P',888+09H#x::8hPZE[\\HH11#xOOOOO-	P 	P 	P 	P &%P Pr   ref%tuple[Var, dict[Var, Context]] | Nonec                    |j         }|*t          |t                    r|                     |          }t          |t                    sd S | j                            |          }|d S ||fS r   )r.  r   r[   rc  r{   r  find_partial_types)r#  rx  r9  rt  s       r   rl  z!ExpressionChecker.get_partial_var  sq    h;:c:66;++C00C#s## 	433C88 4M!!r   
methodnameInstance | Nonec                     j         j        rdS t          |j                  }|dS |j        r|j        j        j        }n|j        J |j        j        }| j        v r| j        |         v ry|j        t          gk    rh 	                    |j
        d                   }t          j                            | j         j                  r j                             ||g          S n
| j        v r | j        |         v r|j        t          gk    rt#           	                    |j
        d                             }t%          |t&                    ro|j        j        }| j        |         |         v rMt)           fd|j
        D                       r- j                             |t+          |j
                            S n/t%          |t,                    r j                             |          S dS )zCTry to make partial type precise from a call such as 'x.append(y)'.Nr   c              3  l   K   | ].}t           j                            |j        j                  V  /d S r   )r  r  rq  r  r  )r   	item_typer#  s     r   r   zKExpressionChecker.try_infer_partial_value_type_from_call.<locals>.<genexpr>  sN        % ;;ItxGWXX     r   )r  current_node_deferredrp  r:  r  rA  rf  r  r8   ru  r  r  r  rq  r  rr  rj  r   r   r   r   r  r   rP  )	r#  r)  r|  r9  ru  rv  r  arg_typearg_typenames	   `        r   rm  z8ExpressionChecker.try_infer_partial_value_type_from_call  s    8) 	40::4" 	2#.3<HH$000#(1H &&dnX666y((AF1I..I|229dh>NOO Jx228i[IIIJ +++d1(;;;y((&t{{16!9'='=>>H(H-- 	5'}54#6x#@#LLL    )1     Z  $x::8T(-EXEXYYYHg.. 5x**8444tr   r  
list[Type]Sequence[str | None] | Noner  list[list[int]]rA  c
                   t          |j                  }
d t          |
          D             }d t          |
          D             }d t          |
          D             }d t          |
          D             }t          |          D ]\  }}|D ]}||                             ||                    ||                             ||                    |r"||                             ||                    n||                             d           ||                             ||                    |M| j                            |          }|J  |t          |||j        ||j	        ||	| j
                            S | j                            |          }|J t          |          } |t          ||||j        ||j	        ||	| j
        	  	                  S )a  Use 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.
        c                    g | ]}g S r   r   r   r0  s     r   r  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>  s    -M-M-MQb-M-M-Mr   c                    g | ]}g S r   r   r  s     r   r  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>      3S3S3S1B3S3S3Sr   c                    g | ]}g S r   r   r  s     r   r  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>  r  r   c                    g | ]}g S r   r   r  s     r   r  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>  s    0P0P0P0P0P0Pr   N)r  r  callee_arg_namesr  default_return_typer  rW  api)	r:  r  r  r  r  r  r  rW  r  )r  r  r  	enumerater  r  get_function_hookr   r  rB  r  get_method_hookr   r   )r#  r  r  r  r  r  r  rA  rU  rW  num_formalsformal_arg_typesformal_arg_exprsformal_arg_namesformal_arg_kindsformalactualsactualcallbackmethod_callbacks                       r   apply_function_pluginz'ExpressionChecker.apply_function_plugin  s=   . &*++-M-M%:L:L-M-M-M3S3Sk@R@R3S3S3S3S3Sk@R@R3S3S3S0P0PU;=O=O0P0P0P()9:: 	C 	COFG! C C (//	&0ABBB (//V=== :$V,33If4EFFFF$V,33D999 (//	&0ABBBBC {44X>>H'''8..%+%5.(.)#	 	 	   #k99(CCO"...)+66K"?$..%+%5.(.)#
 
 
  r   r   hook>Callable[[list[list[Expression]], CallableType], FunctionLike]c                H    t          |t                    rt          |j                  }t	          |||j        |j         fd          }d t          |          D             }t          |          D ]+\  }	}
|
D ]#}||	                             |                    $, |||          S t          |t                    sJ g }|j
        D ]G}                     ||||          }t          |t                    sJ |                    |           Ht          |          S )z@Helper to apply a signature hook for either a function or methodc                :                         |                    S r   ru  r  r  r#  s    r   r  z8ExpressionChecker.apply_signature_hook.<locals>.<lambda>%      $++d1g.. r   c                    g | ]}g S r   r   r  s     r   r  z:ExpressionChecker.apply_signature_hook.<locals>.<listcomp>'  s    7W7W7Wq7W7W7Wr   )r   r   r  r  r   r  r  r  r  r   r   apply_signature_hook)r#  r  r  r  r  r  r  r  r  r  r  r  r   r  adjusteds   ` `            r   r  z&ExpressionChecker.apply_signature_hook  sa    fl++ 	%f.//K5  .....    8X7WE+DVDV7W7W7W#,-=#>#> B B% B BF$V,33DLAAAAB4(&111fj11111E ' '44T4IW[\\!(L99999X&&&&e$$$r   signature_hook,Callable[[FunctionSigContext], FunctionLike]c           	     D                           |||| fd          S )zKApply a plugin hook that may infer a more precise signature for a function.c                D     t          | |j                            S r   )r   r  )r  sigrW  r#  r  s     r   r  zAExpressionChecker.apply_function_signature_hook.<locals>.<lambda>D  s$    ~~.@sGUYU].^.^__ r   )r  )r#  r  r  r  rW  r  r  s   `   ` `r   apply_function_signature_hookz/ExpressionChecker.apply_function_signature_hook5  s=     ((______
 
 	
r   *Callable[[MethodSigContext], FunctionLike]c           
     f     t          |                               |||| fd          S )zIApply a plugin hook that may infer a more precise signature for a method.c           	     F     t          | |j                            S r   )r   r  )r  r  rW  pobject_typer#  r  s     r   r  z?ExpressionChecker.apply_method_signature_hook.<locals>.<lambda>Y  s(    ..$\4gtxPP# # r   )r   r  )	r#  r  r  r  rW  r  rU  r  r  s	   `   `  `@r   apply_method_signature_hookz-ExpressionChecker.apply_method_signature_hookG  s\     '{33((      

 

 
	
r   callable_namec           	     2   t          |          }|t          |t                    rp|8| j                            |          }|r|                     |||||||          S n6| j                            |          }	|	r|                     ||||||	          S |S )a6  Attempt 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.
        )r   r   r   r  get_method_signature_hookr  get_function_signature_hookr  )
r#  r  r  r  r  rW  r  rU  method_sig_hookfunction_sig_hooks
             r   transform_callee_typez'ExpressionChecker.transform_callee_type_  s    0 !(($FL)I)I$&"&+"G"G"V"V" ;;i)[Ra  
 %)K$K$KM$Z$Z!$ ==i)EV   r   r  Overloaded | Nonec                N   |j         sJ t          |j                  dk    st          |          dk    rdS t          t	          |j        d                   t
                    sdS t          t	          |j                  t
                    sdS | j        j        5  | j	        
                                5  t	          |                     |d         d                    }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          |t                    r|S dS )zSCheck if this looks like an application of a generic function to overload argument.r  Nr   r  )r7  r  r  r   r   r   rB  r  rR  r  rS  ru  r   )r#  r  r  r  s       r   "is_generic_decorator_overload_callz4ExpressionChecker.is_generic_decorator_overload_call  s    $$$${$%%**c$ii1nn4/+*?*BCC\RR 	4/+*>??NN 	4X$ 	T 	T'')) T T*4;;tAwT;+R+RSST T T T T T T T T T T T T T T	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T h
++ 	Ots6   D5+C, D,C0	0D3C0	4DD
D
overloadedr   tuple[Type, Type] | Nonec                >   g }g }|j         D ]}t          |          }| j                                        5 }|                     ||gt
          g|          \  }	}
ddd           n# 1 swxY w Y   |                                rzt          |	          }t          |t                    st          |
          }t          |t                    s|
                    |           |
                    |           |r|sdS t          |          t          |          fS )a  Type-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.
        r  N)r   rp   r  rS  
check_callr8   has_new_errorsr   r   r   r  r   )r#  r  r  rJ  r/  inferred_argsr  r$  erritem_resultinferred_argp_item_resultp_inferred_args                r   handle_decorator_overload_callz0ExpressionChecker.handle_decorator_overload_call  s|    $ 	) 	)Dt$$$C'')) `S,0OOK#QXPY[^,_,_)\` ` ` ` ` ` ` ` ` ` ` ` ` ` `!!## +K88Mm\:: ,\::Nnl;;   000MM-(((( 	] 	4&!!:m#<#<<<s   #A&&A*	-A*	r  c           
     Z   |||J |                      ||          }t          |          }|r+|                     |||j        |j        ||j        |          }n.|,t          |t                    r|                     |||          S | 	                    ||j        |j        ||j        |j
        ||          \  }}t          |          }t          |j
        t                    rEt          |t                    r0|j        |j        |j
        _        |j        |j        |j
        _        |S )a?  Type check call expression.

        The callee_type should be used as the type of callee expression. In particular,
        in case of a union type this can be a particular item of the union, so that we can
        apply plugin hooks to each item.

        The 'member', 'callable_name' and 'object_type' are only used to call plugin hooks.
        If 'callable_name' is None but 'member' is not None (member call), try constructing
        'callable_name' using 'object_type' (the base type on which the method is called),
        for example 'typing.Mapping.get'.
        N)callable_noder  rU  )r  r   r  r  r  r  r   r   check_union_call_exprr  r  rf   r   
type_guardtype_is)r#  r  r)  r  rU  r  rB  proper_callees           r   r  z2ExpressionChecker.check_call_expr_with_callee_type  sD   &  V%7*** 00fEEM%k22 	F44{AFAKAKQ\ KK J{I$F$F--afEEE $FKK('# !0 	!
 	!
+ (44ah(( 	9Z|-T-T 	9'3&3&>#$0#0#8 r   r   c                   g }t          |                                          D ]}| j                                        5  t	          |||ddd|| j        |                                 |
  
        }ddd           n# 1 swxY w Y   |                     |j        |d          }|| 	                    ||          }|r|nd}	|
                    |                     ||||	                     t          |          S )zFType check calling a member expression where the base type is a union.F)rK  is_superis_operatororiginal_typer  in_literal_context	self_typeNT)skip_non_overlapping)r   r  r  rS  r   r  r]  r,  r  r  r  r  r   )
r#  r)  rU  r  resr  r  r0  r  item_object_types
             r   r  z'ExpressionChecker.check_union_call_expr  sb   ()C)C)E)EFF 	 	C''))  ,#" %"-'+'>'>'@'@!                 33AHdY]3^^H 00f==M&3=ssJJ55h=Rbcc    %S)))s   1A<<B 	B 	r  Expression | Noner  tuple[Type, Type]c
                   t          |          }t          |t                    rV|j        r3|                     ||          }
|
|                     ||
|          }||S |                     ||||||||          S t          |t                    r|                     |||||||          S t          |t                    s| j
                                        s|                     ||          S t          |t                    r|                     |||||          S t          |t                    rt!          d||ddd|	p|| j
        |                                 	  	        }|j        j        dz   }|                     |||||||          }|                     ||||||||          }|r| j
                            ||           |S t          |t.                    r|                     |j        |||||          S t          |t2                    r5|                     |j        |          }|                     ||||||          S t          |t8                    r+|                     t;          |          ||||||||	  	        S t          |t<                    rt=                      }|j        |_        ||fS | j         !                    ||          t          tD          j#                  fS )a  Type 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
        Nr  FTrK  r  r  r  r  r  z	.__call__)r  )$r   r   r   r7  r  r  rS  r   check_overload_callr   r  r;  check_any_type_callr   check_union_callr   r   r]  r:  rA  r  r  
store_typer   upper_boundr   analyze_type_type_calleer  r   r   r   r  r  not_callabler   r>  )r#  r  r  r  rW  r  r  r  rU  r  r  overloaded_resultcall_functionr/  r  rs  s                   r   r  zExpressionChecker.check_call  sf   @ !((fl++ V	Y 	1!DDVTRR
) )-(K(K
G) )% )400++	 	 	 
++ @	Y++iM;PW   (( <	Y0L0L0N0N <	Y++D&999	** :	Y((y)WUUU)) 8	Y1 +5vH#'#:#:#<#<
 
 
M #K0;>M 66}dIw	SY M __	 	F  ; ##M6:::M,, 	Y??"D)Wi   )) 	Y00gFFD??4y'9m\\\	** 	Y??v&&$ # 
 
 
 00 	Y!##C",CM3;8((9979CW;X;XXXr   c	                    |                                                                 }||j        r|j        }t          |j                  }	|                                r!t          |	t                    r|	j        j	        }t          |t                    r|j	        t          v r	|j        |fS |                                rp|                                j        rW|j        sP j                            t"          j                            |                                j                  |           n|                                r|                                j        r|j        s|                                j        s|                                }
i }|
j        D ]/\  }}|t.          k    r                     |
|          ||<   *d||<   0 j                            |                                j        ||           |                                }|rt          |j        t:                    rd}t=          |          D ]\  }}|t>          k    rt                                |                    }t          |tB                    rtE          d |j#        D                       rH|rD j                            d|tH          j%                   tM          tN          j(                  |fc S d}t          |j                  }	t          |	tR                    r@|	j*        r9tW          |j                  }tY          |           |-                    |          }|.                                r%t_          |          } 0                    ||          }tc          |||j2        |j3         fd          }|.                                r\tE          d	 |j*        D                       } 4                    ||||||          }|r!tc          |||j2        |j3         fd
          }|5                                }||t>          tl          gk    rto          |          dk    r                      d                   }                      d                   }t          |tp                    rgt          |tp                    rR|j9        tt          j;        k    r=|j9        tt          j<        k    r(|j=        |j=        cxk    r|j=        k    rn n	|j        |fS  >                    |||          } ?                    ||||||||            @                    ||||||           |                                rito          |          dk    rVt          |j         B                    d                    r.|-                    t          jD        |d                             }|r j        E                    ||           |rk| jF        G                    |          s|M jF        H                    |          r3 I                    ||||||||	  	        }|-                    |          }|j        |fS )zxType check a call that targets a callable value.

        See the docstring of check_call for more information.
        NFc              3  @   K   | ]}t          |t                    V  d S r   r   r   r   r   s     r   r   z8ExpressionChecker.check_callable_call.<locals>.<genexpr>  s=       > >23Jq*--> > > > > >r   z<Passing multiple variadic unpacks in a call is not supportedr  TrB  c                :                         |                    S r   r  r  s    r   r  z7ExpressionChecker.check_callable_call.<locals>.<lambda>  s    dkk$q'** r   c              3  N   K   | ] }t          |t          t          f          V  !d S r   )r   r   r   r   vs     r   r   z8ExpressionChecker.check_callable_call.<locals>.<genexpr>  sC        EF
1}.>?@@     r   c                :                         |                    S r   r  r  s    r   r  z7ExpressionChecker.check_callable_call.<locals>.<lambda>  s    dkk$q'22 r   r  r   r  rU  r<  )Jwith_unpacked_kwargswith_normalized_var_argsr=  r   rB  r  r   r   r:  rA  rf   r   r  r  from_type_typer  r  r   CANNOT_INSTANTIATE_PROTOCOLr  is_abstractfallback_to_anyabstract_attributesr;   can_return_noner  !cannot_instantiate_abstract_classvar_argr  r   r  r9   ru  r   r  r   r  CALL_ARGr   r   r>  r   r7  r)   r   re  
is_genericr*   +infer_function_type_arguments_using_contextr   r  r  r.   
param_specr:   r  r   flavorr   ARGSKWARGSidinfer_arg_types_in_contextcheck_argument_countcheck_argument_typesr   rP  r   make_normalizedr  r  r  r  r  )r#  r  r  r  rW  r  r  r  rU  rB  r:  r  	attr_nameabstract_statusr  seen_unpackr$  arg_kindr  fresh_ret_typer  need_refreshr  arg1arg2r  new_ret_types   ` `                        r   rS  z%ExpressionChecker.check_callable_call  s     ,,..GGII V[ "KM"6?33 	3Jx$B$B 	3$M2MmW-- 	+-2HJ2V2V?F**   	""$$0	 )		 HMM <CCFDVDVDXDXD]^^   
   	""$$0	 )		
 &&((8	 %%''D 46.2.F ; ;*	?"&999595I5I$PY5Z5Z'	225:'	22H66""$$)+>   .."" 	'z'+z:: 	'  K!$T9!5!5 ' 'Xx''*4;;s+;+;<<!(I66 
'# > >7?~> > > ; ; 
' # EZ#!& &   
  'y';<<fDDDD"&K #6?33h-- 	C(2D 	C<V_MMN 000))>)BBF 	W/77FEEfgVVF1*****
 
  	  JPJZ    L 77i4DlT[ F  
 $:$$22222$ $  &&((
"h	222$%%**;;tAw''D;;tAw''D4///t]33/ K?#777K?#999Gtw7777*-77777..33FD)M]^^	!!		
 		
 		
 	!!y$0@'Wb 	" 	
 	
 	

   	[Y1$$fot/O/OPP % ))83KIVWL3Y3Y)ZZF 	7Hv666 	A T[%B%B=%Q%Q 'DK,G,G,V,V'55 
 
L ))<)@@F&&r   r:  r  c                   t           j        sdS |j        D ]}|j                            |          }||j        }t          |t                    r|j        }t          |t                    r|j
        }t          |t                    rK|j        Dt          |j        t                    sJ t          t                      |j        j                  c S dS )zIs the given attribute a method with a None-compatible return type?

        Overloads are only checked if there is an implementation.
        F)r   strict_optionalmrorg  r  r.  r   rb   implrL   funcrS   r:  r   r   r   rB  )r#  r:  r  rw  symnoder.  s         r   r  z!ExpressionChecker.can_return_none6  s    
 $ 	 5H 	F 	FDjnnY//G<D$ 122 !y$	** !y$(( F9(%di>>>>>%hjj$)2DEEEEEur   r  c                    t          t                    rt          t          j                  S t          t                    rt          j         j                  }t          |t                    r|	                    d          }t          |          }t          |t                    r|	                    g           }|S t          t                    r4t           fd                                D             j                  S t          t                    r                     t!          j                            }t!          |          }t          |t                    r|	                              }n5t          |t$                    r t%          fd|j        D                       }|S t          t(                    r@t+                    j        j        dk    r#                     t+                              S t          t.                    r                               S  j                                       t          t          j                  S )	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  )r7  c                V    g | ]%}                     t          |                    &S r   )r  r   )r   r  rW  r#  s     r   r  z>ExpressionChecker.analyze_type_type_callee.<locals>.<listcomp>a  sA        11/"2E2EwOO  r   r  c                <    g | ]}|                                S )r  re  )r   cr  s     r   r  z>ExpressionChecker.analyze_type_type_callee.<locals>.<listcomp>q  s'    $Z$Z$ZQ__d_%C%C$Z$Z$Zr   builtins.tuple)r   r   r   from_another_anyr   r   r:  rP  r   re  r(   r   r  rC  r   r  r   r  r   r   r   r   rA  r   r5  r  unsupported_type_typer>  )r#  r  rW  r  expandedr  s   ```   r   r  z*ExpressionChecker.analyze_type_type_calleeN  sb   
 dG$$ 	H95$GGGGdH%% 		"49do>>C#|,, =''t'<<.sD99H(L11 @ $11B1??OdI&& 	    "1133   	   dK(( 	
 22?4CS3T3TV]^^F$V,,F&,// \--t-<<FJ// \#$Z$Z$Z$ZV\$Z$Z$Z[[MdI&& 	P>$+?+?+D+MQa+a+a001E1EwOOOdM** 	>77===&&tW555y+,,,r   c                    g }|D ]]}|                      |          }t          |          r"|                    t                                 H|                    |           ^|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.
        )ru  has_erased_componentr  r   )r#  r  r  r$  r  s        r    infer_arg_types_in_empty_contextz2ExpressionChecker.infer_arg_types_in_empty_context|  sl      	% 	%C{{3''H#H-- %

8::&&&&

8$$$$
r   c                T    t           j        }t          |          rdt           _        |S )ax  Adjust 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#  r  olds      r   $infer_more_unions_for_recursive_typez6ExpressionChecker.infer_more_unions_for_recursive_type  s)     %|,, 	+&*J#
r   c                
   dgt          |          z  }t          |          D ]q\  }}|D ]i}||                                         sM|j        |         }	|                     |	          }
|                     ||         |	          ||<   |
t          _        jrt          |          D ]%\  }}|s|                     ||                   ||<   &t          d |D                       sJ t          t          t                   |          S )a  Infer 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*.
        Nc              3     K   | ]}|d uV  	d S r   r   )r   r  s     r   r   z?ExpressionChecker.infer_arg_types_in_context.<locals>.<genexpr>  s&      00b2T>000000r   )r  r  is_starr  r(  ru  r   r&  r   r   r  r   )r#  r  r  r  r  r  r  r  air  r'  r   s               r   r  z,ExpressionChecker.infer_arg_types_in_context  s    #'#d))!3#$455 	2 	2JAw 2 2 },,.. 
2%/2H CCHMMC"kk$r(H==CG.1J+2 cNN 	. 	.DAq .T!W--A00C00000000DJ$$$r   callableerror_contextc                   | j         d         }|s|S t          |t                                }|j        }t	          |          r-t	          |          rt          |          }t          |          }t          |          }t          |t                    s3t          |t                    rPt          d |j        D                       r2t          |          s#t          |          s|                                S t          |j        ||d          }g }|D ]K}	t#          |	          st%          |	          r|                    d           6|                    |	           L|                     |||d          S )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'.
        r4  c              3  Z   K   | ]&}t          t          |          t                    V  'd S r   )r   r   r   r   us     r   r   zPExpressionChecker.infer_function_type_arguments_using_context.<locals>.<genexpr>  s4      ZZAJq11;??ZZZZZZr   Tskip_unsatisfiedN)r  r#   r   rB  r   r   r   r   r   r   r   r   r   r   re  r/   r7  has_uninhabited_componentr#  r  apply_generic_arguments)
r#  r-  r.  rJ  
erased_ctxrB  
proper_retr  new_argsr$  s
             r   r  z=ExpressionChecker.infer_function_type_arguments_using_context  s    # 	O 'sJLL99
$x(( 	5-@-E-E 	5 'x00H(44J %X..
z;//	0*i00	0 ZZIYZZZZZ	08 's++ 04H4M4M 0--///#*t
 
 
 ') 	% 	%C(-- %1Ec1J1J %%%%%$$$$ ++h , 
 
 	
r   r  c           
          j                                         r j                                        5                       ||          }ddd           n# 1 swxY w Y                        ||t                              }	g }
t          |          D ]<\  }}|	|         dk    r|
                    d           '|
                    |           =t          |
||| 
                                 j                                                   \  }}d|	v r                     ||||||          \  }j        dk    rt          |          dk    rt          |v s	t          |v rt          |d                   }t!          |t"          t$          f          r                     d          |d<   nJ|r#t)                               d          |          s% j                             t,          j        |            j         j        j        st5          fd|D                       r|r!t7          ||j        j         fd	          }t          |||| 
                                 j                                         d
          \  }                     ||          }t?          j         |          }|*tC          d |D                       rtE          |           |S t%                      d
_#        fd|D             }n/tI          tJ          j&                  gt          j'                  z  } (                    ||          S )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  )rW  strictr  dictr   builtins.strc              3     K   | ][}|d u pRt          t          |          t                    p0t          t	          |                    t          j                  z  V  \d S r   )r   r   r   rf  r   r7  )r   r*  r  s     r   r   zBExpressionChecker.infer_function_type_arguments.<locals>.<genexpr>c  s       ? ?  T	 Foa00/BBF}Q''((3{/D+E+EE? ? ? ? ? ?r   c                :                         |                    S r   r  r*  r  r#  s    r   r  zAExpressionChecker.infer_function_type_arguments.<locals>.<lambda>r  s    $++d1g"6"6 r   T)rW  r;  allow_polymorphicc              3  d   K   | ]+}|d uo"t          t          |          t                     V  ,d S r   )r   r   r   r)  s     r   r   zBExpressionChecker.infer_function_type_arguments.<locals>.<genexpr>  sT       / / TMY*_Q5G5G*Y*Y&Y/ / / / / /r   c           	     z    g | ]7}|1t          |fdt          j                  z   D                       nd 8S )Nc                     i | ]
}|j         S r   )r  )r   r  unknowns     r   
<dictcomp>zNExpressionChecker.infer_function_type_arguments.<locals>.<listcomp>.<dictcomp>  s    ___!g___r   )r'   r  r7  )r   r*  r  	free_varsrE  s     r   r  zCExpressionChecker.infer_function_type_arguments.<locals>.<listcomp>  sq     	! 	! 	!  = $____tK<Q7R7RU^7^___   "	! 	! 	!r   ))r  r;  r  rS  r  get_arg_infer_passesr  r  r  r.   argument_infer_context#infer_function_type_arguments_pass2special_sigr7   r:   r   r   r   r   rP  r   r  r   &KEYWORD_ARGUMENT_REQUIRES_STR_KEY_TYPEr  r  r  r   r  r  r6  r   
apply_polyr   r   r  r   r   unannotatedr7  apply_inferred_arguments)r#  r  r  r  r  r  r  rW  r  arg_pass_nums
pass1_argsr  r$  r  r0  	first_argpoly_inferred_argspoly_callee_typeappliedrG  rE  s   ```                @@r   r.   z/ExpressionChecker.infer_function_type_arguments  sP     8'')) x	Z
 ''))   ;;y2B 	              
 !55T9.>D		 M -/J#I.. + +3 #a''%%d++++%%c****< 3355x3355     M1 M!!/3/W/W$! 	0 	0,m '611&&!++)++yI/E/E ,M!,<==	i(O)DEE d'+~'F'FM!$$" d*T__^5T5TV_*`*` dHMM"2"Y[bccc8#6 73 ? ? ? ? '	? ? ? < < 7   
 (>!!#-#-66666( ($ 1N$ 779987799&*	1 	1 	1-"I $(#?#?!3W$ $ 
 $./?KK&3 / /// / / , ,& )111"N)++$(!	! 	! 	! 	! 	! 	! 0	! 	! 	! %Y%:;;<s;CX?Y?YYM,,[-QQQs   AA"%A"old_inferred_argsSequence[Type | None]&tuple[CallableType, list[Type | None]]c	           	     Z    t          |          }	t          t          |	                    D ]5\  }
}t          |t          t
          f          st          |          rd|	|
<   6                     ||	|          }|                                s|g fS |r!t          |||j
        |j         fd          } j                                        5                       |||          }ddd           n# 1 swxY w Y   t          |||||                                           \  }	}||	fS )a^  Perform second pass of generic function type argument inference.

        The second pass is needed for arguments with types such as Callable[[T], S],
        where both T and S are type variables, when the actual argument is a
        lambda with inferred types.  The idea is to infer the type variable T
        in the first pass (based on the types of other arguments).  This lets
        us infer the argument and return type of the lambda expression and
        thus also the type variable S in this second pass.

        Return (the callee with type vars applied, inferred actual arg types).
        Nc                :                         |                    S r   r  r@  s    r   r  zGExpressionChecker.infer_function_type_arguments_pass2.<locals>.<lambda>  r  r   r?  )r  r  r   r   r   r   r#  r6  r  r   r  r  r  rS  r  r.   rI  )r#  r  r  r  r  r  rV  r  rW  r  r  r$  r  r0  s   ` `           r   rJ  z5ExpressionChecker.infer_function_type_arguments_pass2  s   2 .// 0 ? ?@@ 	( 	(FAs#/:;; (?STW?X?X (#'a 22;wWW%%'' 	#?" 	5%%.....    X##%% 	 	77T9.> I	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 9//11
 
 
q M))s   C44C8;C8r-   c                    | j         Et          | j                            d          | j                            d                    | _         | j         S )Nr'  typing.Iterable)r  r-   r  rP  r'  s    r   rI  z(ExpressionChecker.argument_infer_context  sO    (0,@##$455tx7J7JK\7]7]- -D) ,,r   num_actualsint	list[int]c                b   dg|z  }t          |j                  D ]\  }}d}	t          |j        |                   }
t          |
t                    r|
                                r||         D ]}t          ||                   }t          |t                    r$t          d||d          }|t          |          }t          |t                    r&|j        st          ||         t                    sd}	 n|	s1|
                    t                                r||         D ]}d||<   |S )a  Return 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.
        r  Fr  T)r  Nr  )r  r  r   r   r   r  r   r   r7  rW   ru  ArgInferSecondPassQuery)r#  r  r  r  r  r]  r  r  r$  skip_param_specp_formalr  p_actualcall_methods                 r   rH  z&ExpressionChecker.get_arg_infer_passes  sZ     cK 011 	 	FAs#O&v'7':;;H(L11 h6I6I6K6K )!,  A.y|<<H "(H55 D&1*h^b&c&c&c&2'6{'C'CH"8\:: ( 2 !+47J ? ?
 +/" szz2I2K2K'L'L )!,  ACFF
r   r  c                   t          ||j                  D ]\\  }}|rt          |          rF| j                            |||           t          t          j                  gt          |          z  }]| 	                    |||          S )zApply inferred values of type arguments to a generic function.

        Inferred_args contains the values of function type arguments.
        )
r  r7  r#  r  could_not_infer_type_argumentsr   r   r>  r  r6  )r#  r  r  rW  inferred_typetvs         r   rO  z*ExpressionChecker.apply_inferred_arguments	  s     "%]K4I!J!J 	U 	UM2  U$8$G$G U77RQQQ!()=!>!> ?#mBTBT T ++KPPPr   actual_typesactual_kindsactual_namesContext | Nonec	                   |&t          t          t          j                            }i }	|D ]#}
|
D ]}|	                    |d          dz   |	|<   $|                     ||||	|          \  }}t          |j                  D ]x\  }}||         }|                                r|s|s~|	                                r<| j
                            |||           |r|rd|v r|                     |||           n+|j        |         pd}| j
                            |||           d}|                                sxt!          ||          rg| j                                        s.t'          t)          |d                            t*                    r| j
                            |||           d}0|                                rG|rE||d                  t0          j        t0          j        fvr| j
                            ||           d}|                                |s+|j        dk    r | j
                            |||           d}t=          |          dk    rt?          fd|D                       }||d                  t0          j         k    r#|dk    r| j
        !                    d	|           d}||d                  t0          j        k    r#|dk    r| j
        !                    d
|           d}z|S )aO  Check 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
        Nr   r  r  ?Fpartialc              3  h   K   | ],}t          t          |                   t                    V  -d S r   )r   r   r   )r   krj  s     r   r   z9ExpressionChecker.check_argument_count.<locals>.<genexpr>l	  sM       , , #?<?#C#C]SS, , , , , ,r   z)ParamSpec.args should only be passed oncez+ParamSpec.kwargs should only be passed once)"rp   r   r   r6  r   check_for_extra_actual_argumentsr  r  is_requiredis_positionalr  too_few_argumentsmissing_classvar_callable_noter  missing_named_argumentr+  is_duplicate_mappingr  r;  r   r   r   duplicate_argument_valueis_namedr   r7   r:   too_many_positional_argumentsr  rK  r  sumr9   r  )r#  r  rj  rk  rl  r  rW  rU  r  all_actualsr  r*  okis_unexpected_arg_errorr  kindmapped_argsargnameparamspec_entriess     `                r   r  z&ExpressionChecker.check_argument_count(	  sq   $ ?wy'=>>??G
 ')' 	; 	;G ; ;!,A!6!6!:A; '+&K&KL,k7'
 '
##
 !!122 *	# *	#GAt*1-K!! (#+ (#>U (#%%'' NH..vwMMM" a} a9M9M;;KX_```$.q18SGH33FGWMMM\\^^ #(<\<) ) # 8//11 Z#LQ$@AA96 6  H55faIIIB## !Q0%/8ZZZ 66vwGGG""$$0" #v'9Y'F'FH..vwMMMBB%%))(+ , , , ,!,, , , ) )% $KN3u~EEJ[^_J_J_&QSZ[[["#KN3uFFK\_`K`K`&SU\]]]"	r   r~  tuple[bool, bool]c                p   d}d}t          |          D ]\  }	}
|	|vr|
t          j        k    st          ||	                   r~|
t          j        k    rnd}|
t          j        k    r| j                            ||           m|s
J d            ||	         }|J ||	         }| j                            ||||           d}|
t          j        k    rt          j        |j	        vs|
t          j        k    rt          ||	                   }t          |t          t          f          r|                    |	d          t          |j                  k     ra|
t          j        k    st          |t                    s| j                            ||           n| j                            |||           d}d}||fS )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 givenNr   )r  r   r9   is_non_empty_tupler:   r7   r  too_many_argumentsunexpected_keyword_argumentr  r   r   r   r   r  r  r   "too_many_arguments_from_typed_dict)r#  r  rj  rk  rl  r~  rW  r  r  r  r  act_nameact_typeactual_types                 r   rs  z2ExpressionChecker.check_for_extra_actual_argumentsx	  s    #( .. %	# %	#GAt$$ ''+=l1o+N+N' '' 5?**H//@@@@'ZZ)ZZZZ+AH#///+AHH888U\]]].2++&&5>AQ+Q+Q((-l1o>>kI}+EFF 
#"q!,,s;3D/E/EEE5?22*[R_:`:`2 H77HHHH HGG &W   7;3" ***r   c                   t          |t                    rt          |t                    r|                    dd          \  }}|j                            |          }|Wt          |j        t                    r?|j        j        s5|j        j	        s+| j
                            d| d|           d S d S d S d S d S d S d S )Nr  r  )maxsplitrH  zN" is considered instance variable, to make it class variable use ClassVar[...])r   r   r   rsplitr:  r  r.  r{   r  is_classvarr  note)r#  rU  r  rW  r0  var_namer.  s          r   rw  z0ExpressionChecker.missing_classvar_callable_note	  s     k:.. 		:k83T3T 		'..sQ.??KAx#''11DJty#$>$>y, TY5J HMMGH G G G    		 		 		 		     r   	check_argArgChecker | Nonec	                    |p| j         }t          |                                           }	t                    D ]\  }
}t	          |
          }
|t
          j        k    r0|                     |
          s| j        	                    |
|           |t
          j
        k    rY|                     |
          sDt          |
| j                            d                    }| j                            |
||           t!          |          D ]S\  }}t	          |j        |                   }d}fd|D             }t%          |          dk    rCt	          |d                            }t'          |t(                    rt%          |j                  dk    rt'          |j        d         t,                    r|t
          j        gt
          j        gt%          |          dz
  z  z   k    r|j        d         gfd|dd         D             z   }t'          |t,                    rnt	          |j                  }t'          |t(                    rE|j        sJ |j        }t
          j        gt
          j        gt%          |j                  dz
  z  z   }d}|sUfd	|D             }t'          |t,                    r t	          |j                  }t'          |t(                    rUt3          |j                    !|j        }t.          gt%          |          z  }n|j                  }t'          |t,                    sJ t	          |j                  }t'          |t4                    r6|j        } fd
t7          t%          |j                            D             }nMt'          |t8                    sJ |j        j        dk    sJ |j        d          |j        d         gt%          |          t%          |j                  z
  dz   z  z   |j         dz   d         z   }t.          gt%          |          z  }nt'          |t4                    r|g}t          g}nt'          |t8                    sJ |j        j        dk    sJ |j        d         gt%          |          z  }t.          gt%          |          z  }n1|gt%          |          z  }|j        |         gt%          |          z  }t%          |          t%          |          cxk    rt%          |          k    sn J t%          |          t%          |          k    rdt%          |          t%          |          k    r!| j        j                             ||           n!| j        j        !                    ||d           t%          |          t%          |          k    sJ t%          |          t%          |          k    sJ t          |||||          D ]`\  }}}}}|	"                    |||j#        |         |t'          |t,                              } ||||||dz   |dz   ||||         |
  
         aUdS )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.SupportsKeysAndGetItemFc                     g | ]
}|         S r   r   )r   r*  r  s     r   r  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>	  s    :::QIaL:::r   r  r   c                     g | ]
}|         S r   r   r   r*  r  s     r   r  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>	  s    >a>a>aPQy|>a>a>ar   NTc                     g | ]
}|         S r   r   r  s     r   r  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>
  s    >>>	!>>>r   c                8    g | ]}|k    rt           nt          S r   )r8   r9   )r   r  inner_unpack_indexs     r   r  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>
  s8     4" 4" 4"() 014F/F/FGGH4" 4" 4"r   r  )allow_unpack)$r  r   rI  r  r   r   r9   is_valid_var_argr  invalid_var_argr:   is_valid_keyword_var_argr   r  rP  invalid_keyword_var_argr  r  r  r   r   r   r   r8   r:  r   r   r  r   rA  r  r  r  rv  expand_actual_typer  )!r#  r  r  r  r  r  rW  r  rU  mapperr  r  
is_mappingr  r  orig_callee_arg_typeexpanded_tuplerk  p_actual_typerj  p_callee_typecallee_arg_typescallee_arg_kindsunpacked_typeinner_unpackinner_unpacked_typer  r  actual_kindcallee_arg_typecallee_arg_kindexpanded_actualr  s!    ``                             @r   r  z&ExpressionChecker.check_argument_types	  s   " /	 !<!<!>!>??"%i";"; 	P 	PHh&x00H5>))$2G2G2Q2Q)((7;;;5?**43P3PQY3Z3Z*'dh112TUU 
 00:wOOO#$455 l	 l	JAw#263CA3F#G#G  #N::::':::L7||a /	'!*0E F F}i882M/00A55"=#6q#9:FF 6$(8EM?cRYll]^N^;_(___$1$7$:#;>a>a>a>aU\]^]_]_U`>a>a>a#aL!"6
CC 2(78L8Q(R(R%mY?? 2#0#6666/</B,05/?5=/ #M$7 8 81 <C 0, .2N! *L>>>>g>>>2J?? (L$34H4M$N$NM!-;; #D-@AT-U-U*-5/</B,07y3w<</G,,+8+>?Q+RL#-lJ#G#GGGG2A,BS2T2T/)*=?OPP L 4A3F 04" 4" 4" 4"-23}7J3K3K-L-L4" 4" 4" 0 0 (22Ex'P'P P P P':'?'HL\'\'\'\'\$1$78K9K8K$L':'?'B&C'*7||c-:M6N6N'NQR'R'T%T '4&9:Lq:P:R:R&S%T !1 5<9s7||3K 0 0#M3CDD D,@+A(,4:(()-BBBBB,1:>NNNNN,9,>q,A+BS\\+Q(,39s7||+C(((<'=G'L$(.(8(;'<s7||'K$|$$GIIIIL8I8IIIIIII#$$L(9(999|$$s+;'<'<<<HL33FGDDDDHL2267DIII'((C,=,====='((C0@,A,AAAAAVY|5EGWW W  R[/? #)";";$Q'#!+OZ!H!H #< # # 	##QJEL   ml	 l	r   caller_typeoriginal_caller_typecaller_kindrA   rn  mouter_contextc           
        t          |          }t          |          }t          |          }t          |t                    r| j                            ||	           dS |                     ||          r| j                            ||	           dS t          ||| j        j	                  s| j        
                    |||||||	|
          }|                                s| j                            |||	|           | j                                        s&| j                            |||	|j                   dS dS dS )z.Check the type of a single argument in a call.)r  )rU  rW  r  )parent_errorN)r   r   r   r  deleted_as_rvaluehas_abstract_type_partconcrete_only_callr   r  r  incompatible_argumentr+  incompatible_argument_noteprefer_simple_messagescheck_possible_missing_awaitr  )r#  r  r  r  r  rn  r  r  rU  rW  r  errors               r   r  zExpressionChecker.check_argP
  s~    &k22./CDD%k22k;// 	H&&{G<<<<<((kBB 	H''W=====Kdh>NOOO 	H22$'+ 3 	 	E &&((  33(+wU 4    82244 55guz    %	 	" r   c                    |                                 }                     |          }                     ||||          }	d}
d}d}                     ||	          }d}t	           fd|D                       r	  j                                        5                       |	||||||||	  	        }ddd           n# 1 swxY w Y   |rUd |D             }d |D             }t          ||j	        |j
                                       t          |                    f}n# t          $ r d}Y nw xY w                     |	|||||||          }|M|Kt          |d         |d                   r-t!          t#          |d                   t$                    s|sd}nd}|M|I|D ]F}t!          t#          |          x}t&                    r  j                            |j        |           G|S |Lt!          t#          |d                   x}t&                    r  j                            |j        |           |S                      |	|||||          }
t1          |
          dk    r	|
d         }nUt%          t2          j                  }t7          |          sd}nt8          j        } j                            ||||	                                |||||||
          }|r'|s% j                             tB          j"        |           |S )z(Checks a call to an overloaded function.NFc              3  B   K   | ]}                     |          V  d S r   )
real_union)r   r$  r#  s     r   r   z8ExpressionChecker.check_overload_call.<locals>.<genexpr>
  s/      99ts##999999r   c                    g | ]
}|d          S rG  r   r1  s     r   r  z9ExpressionChecker.check_overload_call.<locals>.<listcomp>
  s    <<<qt<<<r   c                    g | ]
}|d          S )r  r   r1  s     r   r  z9ExpressionChecker.check_overload_call.<locals>.<listcomp>
  s    %C%C%Cqad%C%C%Cr   Tr   r  r  r  rU  )#r  r$  plausible_overload_call_targetspossible_none_type_var_overlapr  r  rS  union_overload_resultr   rC  rD  combine_function_signaturesr   r   infer_overload_return_typer   r   r   r   r   r  warn_deprecated
definitionoverload_erased_call_targetsr  r   r>  is_operator_methodr  OPERATORno_variant_matches_argumentsr  r  r   TOO_MANY_UNION_COMBINATIONS)r#  r  r  r  r  r  rU  rW  r  plausible_targetserased_targetsinferred_typesunioned_resultnone_type_var_overlapunion_interruptedunioned_returnreturnsinferred_resultrh  r  ry  r  r/  s   `                      r   r  z%ExpressionChecker.check_overload_call}
  s    ,,..99$??	 @@y)V
 
 59,037
 !% C CIO` a a!9999y99999 	X++--  %)%?%?)!!!%#-
& 
&N              " " 
<<^<<<G%C%CN%C%C%CN .gw|W^TT889I.9Y9YZZ&N ! ) ) )$(!!!)$ 99	
 	
 &>+E ?1-~a/@AA'"??13E#F#FPP' .'
 "&"&%)%3 H HM!}'E'E"E!|TT H00wGGG!!&q/ABBB!LQQ @((w???"" ::y)Yg
 
 ~"" *!,FF Y122F%m44 &~H11&)WSW1XXX'# ! 
 
  	Q%: 	QHMM*FPPPs6   =D# C 4D#  CD# CD# #D21D2r   list[CallableType]c           
        d
d}g }g }d}d}	t          |          D ]5\  }
}|
t          k    r ||          sd}|
t          k    r ||          sd}	6|j        D ]}t	          |||j        |j        fd          }| j                                        5  |	                                |
                    |           nm|                     ||||d	          rS|r|j        r|
                    |           n4|	r|j        r|
                    |           n|
                    |           d	d	d	           n# 1 swxY w Y   ||z   S )aE  Returns 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.r  r   r   r   c                    t          |           } t          | t          t          f          p t          | t                    o| j        j        S r   )r   r   r   r   r   r:  is_named_tupler  s    r   	has_shapezDExpressionChecker.plausible_overload_call_targets.<locals>.has_shape  sB    !#&&CcI}#=>> 3))Ech.Er   FTc                    |          S r   r   r  r  s    r   r  zCExpressionChecker.plausible_overload_call_targets.<locals>.<lambda>1  s    iXYl r   Nr  r   r   r   )r  r9   r:   r   r   r  r  r  rS  r  r  r  
is_var_arg	is_kw_arg)r#  r  r  r  r   r  matchesstar_matchesargs_have_var_argargs_have_kw_argr  r  r  s    `           r   r  z1ExpressionChecker.plausible_overload_call_targets  s   $	 	 	 	 ')+-! Y	22 	( 	(ID#x		#$(!y  3 #' > 	, 	,C59cmS]DZDZDZDZ    '')) , ,>>##/ NN3''''..Iy:JD  , ) ,S^ ,$++C0000) ,cm ,$++C0000s+++!, , , , , , , , , , , , , , ,$ g%%s   BD::D>	D>	r  c	                <   g }	g }
g }t          t          t          |                    }g }|D ]S}| j        | j        j        u sJ | j                                        5 }| j        j        5 }|                     |||||||          \  }}ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                                 }|r|s | j        	                    |           ||fc S t          |          }t          |t                    r|	                    |           n|	                    |           |
                    |           |                    |           |                    |           U|	sdS t          |	|
|||          rt          |
          r0| j        	                    |d                    |
d         |d         fS t          d |
D                       rJ| j        	                    |d                    t!          |
d                   t!          |d                   fS |                     t#          t$          j                  ||||||          S | j        	                    |d                    |
d         |d         fS )a  Attempts 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.
        )r  r  r  r  rW  r  rU  Nr   c                ,    g | ]}t          |          S r   )r!   )r   r  s     r   r  z@ExpressionChecker.infer_overload_return_type.<locals>.<listcomp>  s     I I ISC I I Ir   )r  maphas_any_typer  r  rS  rR  r  r  store_typesr   r   r   r  any_causes_overload_ambiguityall_same_typesr!   r   r   r6  )r#  r  r  r  r  r  r  rU  rW  r  return_typesr  args_contain_any	type_mapsr  wr  rB  
infer_typeis_matchp_infer_types                        r   r  z,ExpressionChecker.infer_overload_return_typeG  sM   * ')#%%'s<;;<<24	$ 	$ 	$C8tx|++++'')) 
QX, 	+/??"!"+"+ '&3$/ ,; , ,(Hj	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ++---H $ ( 0H((+++#Z////.z::lL99 ( NN<0000NN3'''##H---%%j111  ### 	64*7L)YXabb 	6 l++ $$Yq\222#Aq(999 I IL I I IJJ $$Yq\222!,q/22J~a?P4Q4QQQ"9#9::''#"/ + '    H  1...?N1$555s6   B.+ BB.BB.BB..B2	5B2	c           	     r    g }|D ]1}|                      ||||||          r|                    |           2|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#  r  r  r  r  r  rW  r  r  s	            r   r  z.ExpressionChecker.overload_erased_call_targets  sW     ')$ 	$ 	$C//9isG  $ s###r   c                   |r|sdS d}t          |          D ]H}t          |t                    st          |j                  D ]}t          |t                    rd} nI|sdS t          d |D                       }t          |          D ];t          fd|D                       rt          fd|D                       r dS <dS )a  Heuristic 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].
        FTc              3  >   K   | ]}t          |j                  V  d S r   )r  r  r   r  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>  s,      EEaQ[))EEEEEEr   c              3  r   K   | ]1}t          t          |j                           t                    V  2d S r   )r   r   r  r   r   r  r  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>  sL        JK
?1;q>::HEE     r   c              3  r   K   | ]1}t          t          |j                           t                    V  2d S r   )r   r   r  r   r  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>  sL        MN
?1;q>::KHH     r   )r   r   r   r   r   minr  r  )r#  r  r  has_optional_argr  r  
min_prefixr  s          @r   r  z0ExpressionChecker.possible_none_type_var_overlap  sI    ! 		 	5 (33 	 	Hh	22 (88  dH-- '+$E   	5EE3DEEEEE
z"" 	 	A    O`         Rc    
 ttur   r   r  levellist[tuple[Type, Type]] | Nonec                   |
t           k    rt          t          |          D ]\  }}|                     |          r nR|                     ||          5  |                     ||||||||	          }ddd           n# 1 swxY w Y   ||gS dS |s~|                     ||          5  |                     ||||||||	          }ddd           n# 1 swxY w Y   |2t          t          |d                   t          t          f          s|gS t          ||                   }t          |t                    sJ g }|
                                D ]V}|                                }|||<   |                     |||||||||	|
dz   
  
        }||                    |           T dS t                      }g }|D ]0}||vr*|                    |           |                    |           1|S )a  Accepts a list of overload signatures and attempts to match calls by destructuring
        the first union.

        Return a list of (<return type>, <inferred variant type>) if call succeeds for every
        item of the desctructured union. Returns None if there is no match.
        Nr   r  )r   r   r  r  type_overrides_setr  r   r   r   r   r  copyr  rg  rf  rj  r  )r#  r  r  r  r  r  r  rU  r  rW  r  idxr  r  directfirst_union	res_itemsr  new_arg_types
sub_resultseenr/  pairs                          r   r  z'ExpressionChecker.union_overload_result  s   , J "),, 	 	HCs##  ((y99 
 
55%!	 	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 u4 % 	 ((y99 
 
88%!	 	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 !*q	**Y,@+ +! x &in55+y11111	..00 	 	D%NN,,M!%M#33!%	 J %  ,,,, tt (+uu 	$ 	$D4d###s$   A>>BB(CCCc                    t          |          }t          |t                    o$t          |                                          dk    S r  )r   r   r   r  r  r#  r  s     r   r  zExpressionChecker.real_union<  s=    c""#y))Kc#2D2D2F2F.G.G!.KKr   exprsSequence[Expression]	overridesSequence[Type]Iterator[None]c              #     K   t          |          t          |          k    sJ t          ||          D ]\  }}|| j        |<   	 dV  |D ]
}| j        |= dS # |D ]
}| j        |= w xY w)z5Set _temporary_ type overrides for given expressions.N)r  r  r  )r#  r  r  r  r  s        r   r  z$ExpressionChecker.type_overrides_set@  s      
 5zzS^^++++UI.. 	, 	,ID#(+D%%	.EEE . .'--. . . .'--.s   A A(r   list[ProperType]AnyType | CallableTypec                   |s
J d            t          d |D                       st          t          j                  S t	          d|          }t          |          dk    r|d         S t          |          \  }}d t          t          |d         j                            D             }t          |d         j
                  }g }d}|D ]}t          |          t          |j
                  k    rd} nt          t          ||j
                            D ]D\  }	\  }
}|
|k    r|
                                r|                                rt          ||	<   Bd} |r nPt          |j                  D ] \  }	}||	                             |           !|                    |j                   t#          |          }|rJt          t          j                  }|d                             ||gt&          t(          gd	d	g||d
          S g }|D ]&}t#          |          }|                    |           '|d                             ||||d          S )aL  Accepts 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).
        zTrying to merge no callablesc              3  @   K   | ]}t          |t                    V  d S r   r   r   r  s     r   r   z@ExpressionChecker.combine_function_signatures.<locals>.<genexpr>V  s,      >>1:a..>>>>>>r   r  r  r   c                    g | ]}g S r   r   r  s     r   r  zAExpressionChecker.combine_function_signatures.<locals>.<listcomp>i  s    %U%U%UQb%U%U%Ur   FTN)r  r  r  rB  r7  r  )r  r  rB  r7  r  )r   r   r   r6  r   r  #merge_typevars_in_callables_by_namer  r  r  r  r  r  ru  r8   r  rB  r   re  r9   r:   )r#  r   	callablesr7  r9  	new_kindsnew_returnstoo_complexry  r  new_kindtarget_kindr$  union_returnr  
final_args	args_listrw  s                     r   r  z-ExpressionChecker.combine_function_signaturesN  s    444444>>>>>>> 	391222-u55	y>>QQ<  C9MM	9%U%U%IaL<R8S8S2T2T%U%U%U1/00	"$ 	0 	0F 9~~V%5!6!666".7IvGW8X8X.Y.Y  **Hk{**++-- +2K2K2M2M #*IaLL"&K #F$455 ( (3""3''''v////,[99 		)011CQ<--*#Y/,%# .    
! 	( 	(I,Y77Hh''''|)) ! * 
 
 	
r   c           	     `   t          |||j        |j        fd          }| j                                        5  |                     ||||d          s	 ddd           dS 	 ddd           n# 1 swxY w Y   dd}	 |                     ||||||           dS # t          $ r Y dS w xY w)z^Determine whether arguments could match the signature at runtime, after
        erasing types.c                    |          S r   r   r  s    r   r  z?ExpressionChecker.erased_signature_similarity.<locals>.<lambda>  s    PYZ[P\ r   NFr  r   original_ccaller_typer  rA   r  rn  r^  r  r  r   rU  r  rW  rK   r  r   r  c
                4    t          | |          st          d S r   )arg_approximate_similarityr   )
r  r+  r  r  rn  r  r  rU  rW  r  s
             r   r  z@ExpressionChecker.erased_signature_similarity.<locals>.check_arg  s'     .k;GG   r   )rW  r  T)r  r   r+  r   r  rA   r  r   rn  r^  r  r^  r  r   rU  r  rW  rK   r  rK   r   r  )r   r  r  r  rS  r  r  r   )	r#  r  r  r  r  r  rW  r  r  s	    `       r   r  z-ExpressionChecker.erased_signature_similarity  sg    2y&"2F4DF\F\F\F\
 
 X##%% 	 	,,	9i9I4   	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 		 	 	 	"	%% # &    4 	 	 	55	s#   A11A58A5B 
B-,B-r4  c                H    t          j        ||| j        j        ||          S )z=Simple wrapper around mypy.applytype.apply_generic_arguments.r3  )r   r6  r  incompatible_typevar_value)r#  r-  r   rW  r4  s        r   r6  z)ExpressionChecker.apply_generic_arguments  s2     0H/-
 
 
 	
r   c                D   |                      |           t          |          }t          |t                    r6t          t          j        |          t          t          j        |          fS t          t          j                  t          t          j                  fS )Nr  )r$  r   r   r   r   r  r6  )r#  r  r  s      r   r  z%ExpressionChecker.check_any_type_call  s    --d333 ((fg&& 	T	2vFFF	2vFFF 
 9122GI<R4S4SSSr   c                      j                                         5   fd|                                D             }d d d            n# 1 swxY w Y   t          d |D                       |fS )Nc           	     B    g | ]}                     |          S r   )r  )r   subtyper  r  r  rW  r#  s     r   r  z6ExpressionChecker.check_union_call.<locals>.<listcomp>  s=        y'9MM  r   c                    g | ]
}|d          S rG  r   )r   r  s     r   r  z6ExpressionChecker.check_union_call.<locals>.<listcomp>  s    &A&A&A#s1v&A&A&Ar   )r  disable_type_namesr  r   )r#  r  r  r  r  rW  resultss   ` ```` r   r  z"ExpressionChecker.check_union_call  s     X((** 	 	       %4466  G	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 &&A&A&A&A&ABBFKKs   %AAAc                    |                      ||          }|                     ||          }| j                            |j        |           |S )z'Visit member expression (of form e.id).)analyze_ordinary_member_accessr,  r  r  r.  )r#  r)  rK  r/  r0  s        r   visit_member_exprz#ExpressionChecker.visit_member_expr   sK    44Q	BB//6::  +++r   rK  c                
   |j         |                     |          S |                     |j        | j                  }|j        }d}t          |t                    r&t          |j        t                    r|j        j	        }t          |t                    r3t          |j        t                    r|j        j        p|j        j        }nd}t          |j        |||dd|| j        |                                 |||          }|S )zAnalyse member expression or member lvalue.

        An rvalue can be provided optionally to infer better setter type when is_lvalue is True.
        Nr|  F)	rK  r  r  r  r  r  module_symbol_tabler`  rK  )r  r+  ru  r  r  r   rf   r.  r\   rg  r{   r`  is_clsr   r=  r  r]  )	r#  r)  rK  rK  r  rw  r;  r`  member_types	            r   r8  z0ExpressionChecker.analyze_ordinary_member_access  s	    6((+++ !KK$.KIIM6D"&$(( 6Z	8-L-L 6&*io#$((  Z	3-G-G   )+?ty/?/#!+H#'#:#:#<#<$7  K r   	base_typec                `    t          |||ddd|| j        |                                 	  	        S )z}Analyse member access that is external, i.e. it cannot
        refer to private definitions. Return the result type.
        Fr  )r   r  r]  )r#  r  r>  rW  s       r   analyze_external_member_accessz0ExpressionChecker.analyze_external_member_access1  sD     %##6688

 

 

 
	
r   c                6    t          | j        d                   S Nr4  )r   r  r'  s    r   r]  z$ExpressionChecker.is_literal_contextD  s    #D$5b$9:::r   r  r   fallback_namec                   |                      |          }|                                 rt          ||          S |du r8| j        *|                    t          ||                    | _        | j        S |du r8| j        *|                    t          ||                    | _        | j        S |                    t          ||                    S )az  Analyzes 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.
        )r  r  TN)r^  F)rP  r]  r   r!  re  r"  )r#  r  rC  r  s       r   r_  z)ExpressionChecker.infer_literal_expr_typeG  s    " oom,,""$$ 	^US9999}}%-),):):)453)O)O)O *; * *D& ))~~&.*-*;*;)453)O)O)O +< + +D' **$$kX[6\6\6\$]]]r   leftr   rightc                    t          |j                  rt          |j                  rJ t          |j        |j        z   |                     d                    S )z$Concatenate two fixed length tuples.r  )r   r  )r   r   r   rP  )r#  rE  rF  s      r   concat_tupleszExpressionChecker.concat_tuplesj  sZ    '
33Y8KEK8X8XYYY*u{*T__EU5V5V
 
 
 	
r   rV   c                8    |                      |j        d          S )z(Type check an integer literal (trivial).builtins.intr_  r  r#  r)  s     r   visit_int_exprz ExpressionChecker.visit_int_exprq      ++AG^DDDr   rl   c                8    |                      |j        d          S )z&Type check a string literal (trivial).r=  rK  rL  s     r   visit_str_exprz ExpressionChecker.visit_str_expru  rN  r   rE   c                8    |                      |j        d          S )z%Type check a bytes literal (trivial).r   rK  rL  s     r   visit_bytes_exprz"ExpressionChecker.visit_bytes_expry  s    ++AG5EFFFr   rR   c                ,    |                      d          S )z%Type check a float literal (trivial).zbuiltins.floatrP  rL  s     r   visit_float_exprz"ExpressionChecker.visit_float_expr}  s    /000r   rI   c                ,    |                      d          S )zType check a complex literal.zbuiltins.complexrT  rL  s     r   visit_complex_exprz$ExpressionChecker.visit_complex_expr  s    1222r   rO   c                ,    |                      d          S )zType check '...'.zbuiltins.ellipsisrT  rL  s     r   visit_ellipsisz ExpressionChecker.visit_ellipsis  s    2333r   ra   c                D   |j         r|                     |j                   S |j        dk    s|j        dk    r|                     |          S |j        dk    r/t	          |j        t                    r|                     |          S |j        dk    r~t	          |j        t                    r%| j	        
                    |j        |j                  S t	          |j        t                    r%| j	        
                    |j        |j                  S |                     |j                  }t          |          }t	          |t                    r|j        dk    r|j        j                            d          }|r|j        dk    rt          |                     |j                            }t	          |t                    r`|j        j                            d          }|>t'          |j                  t'          |j                  |                     ||          S nt,          | j        j        j        v rt	          |t4                    r| j                            |          r|j                            d          }||j        j        j        d
k    rwt'          |j                  c| j                            ||          }| j                            d
|g          }|                    |j        t?          |          gz             S t@          }	|j        dk    rtC          |d          rCt          |                     |j                            }t	          |tD                    rtF          }	t	          |tD                    r>t          |                     |j                            }tC          |d          rtH          }	t,          | j        j        j        v r|j        dk    rt	          |t4                    r|j        j        d
k    rt          |                     |j                            }t	          |t                    rU|j        j        j        d
k    r@t'          |j                  ,|                    t?          |          g|j        z             S |j        tJ          j&        v rtJ          j&        |j                 }
|	tN          j(        u s|	tN          j)        u r/| *                    |
||j        ||	tN          j(        u           \  }}nh|	tN          j+        u rK| *                    tJ          j,        |
         |                     |j                  |j        |d          \  }}nt[          |	           ||_.        |S t_          d|j                   )z(Type check a binary operator expression.andor*%+__add__zbuiltins.tuple.__add____radd__Nr  r  |ri  )r>  r$  rW  allow_reverseFzUnknown operator )0rr  ru  opcheck_boolean_opr   rE  rY   check_list_multiplyrE   r  check_str_interpolationrF  rl   r   r   partial_fallbackr:  r  rA  r   r   rH  r   r  r  enable_incomplete_featurer   type_is_iterableiterable_item_typerr  re  r   r  r   r   r  r  r   
op_methodsr   r  r  check_opr  reverse_op_methodsr   method_typeRuntimeError)r#  r)  	left_typeproper_left_typeleft_add_methodproper_right_typeright_radd_methodr  r-  use_reversemethodr/  ro  s                r   visit_op_exprzExpressionChecker.visit_op_expr  sD   : 	+;;qz***45==ADDLL((+++43;;:afh77;++A...43;;!&),, T*BB1617SSS!&'** T*BB1617SSSKK''	*955&	22 	qts{{.?DHHSSO ?#;?W#W#W$3DKK4H4H$I$I!/;; (9(J(O(S(ST^(_(_%(0 00@0FGGO23D3JKKS#'#5#56FHY#Z#ZZ'48+;+UUU"#4h?? V112CDD V
 ):(>(B(B:(N(N%)1,=BKO___/0@0FGGO$(H$?$?@QST$U$U	!%!<!<=MPY{![![/=="2"8Jv<N<N;O"O  >      #643;; !1?CC 5 %4DKK4H4H$I$I!/?? 5"4K*M:: 4 %4DKK4H4H$I$I!$%6HH 4"3K$("2"LLL /:: $)26FFF$3DKK4H4H$I$I!0)<<):?HL\\\+,=,CDDL,::)*:;;<?P?VV ;    49''')!$/Fj000K:CS4S4S&*mm'"-1C"C '4 ' '# 
 111&*mm08"kk!'22"' '4 ' '# [)))'AMM91499:::r   rH   c                (   d}t          |j        |j        dd         |j                  D ]a\  }}}|                     |          }|dk    s|dk    ra|                     |          }||                     |          }t          |          }|g}t          |t                    r!t          |	                                          }| 
                                }	g }
g }d}d}|D ]8}| j                            d          5 }|                     d||gt          g||	          \  }}| j                            |          }ddd           n# 1 swxY w Y   t          |t"                    rd}|                                r!|                     |          r| j                            d          5 }| j                            ||          \  }}ddd           n# 1 swxY w Y   |                                r0| j                            |                                           d}Mt/          |gt0          j        gdg| 
                                |                     d
                    }|j                            |           |                    |           |                                s3|r1|
                    |           |j                            |           
| j                            |                                           d}:|s|st          j        |          }t;          ||          sk|
s| j                            d|||           nt          j        |
          }|                     |||d          r| j                            ||d|           n|t          j         v rt          j         |         }tC          | j        j"                  5 }| #                    ||||d          \  }	}|j                            |           ddd           n# 1 swxY w Y   |                                sj|dv rf|                     |          }|                     ||          r;tI          |          }tI          |          }| j                            ||d|           n|dk    s|dk    r|                     |          }| 
                                }	|                     ||d          r;tI          |          }tI          |          }| j                            ||d|           |j                            d           ntK          d|           ||	}LtM          j'        ||	          }c|J |S )zType check a comparison expression.

        Comparison expressions are type checked consecutive-pair-wise
        That is, 'a < b > c == d' is check as 'a < b and b > c and c == d'
        Nr  inznot inFTsave_filtered_errors__contains__)rw  r>  r  r  rW  r  rM  )original_containerprefer_literal	container)rc  )z==z!=equalityiszis not)identity_checkidentityzUnknown comparison operator )(r  operandsr   ru  find_partial_type_ref_fast_pathr   r   r   r  r  	bool_typer  rS  check_method_call_by_namer8   r  analyze_container_item_typer   r  r  -analyze_iterable_item_type_without_expression
add_errorsfiltered_errorsr   r   rP  method_typesr  r  r   unsupported_operand_typesdangerous_comparisonrl  r%   errorsrm  r  rp  r   
join_types)r#  r)  r/  rE  rF  operatorrq  
right_type
item_typesr  container_typesiterable_types
failed_outencountered_partial_typer  container_errorsr0  ro  	cont_typeiterable_errorsitertypeiterable_typecontainer_typerw  r  s                            r   visit_comparison_exprz'ExpressionChecker.visit_comparison_expr  s    # &)QZ^Q[%Q%Q F	= F	=!D%D))I48x#7#7 "AA%HH
%!%U!3!3J,Z88
.8\
j)44 C!%j&?&?&A&A!B!BJ!^^--
.0-/"
+0(!+ 3* 3*I //T/JJ TN^)-)G)G#1&/"&'.i$%*4 *H * *; %)H$H$H$S$S	T T T T T T T T T T T T T T T ")[99 !*370(7799* --i88	* "X333NN Ra*.(*`*` )1+ +KAx               +99;; < H//0O0O0Q0QRRR)-JJ*6!*!&!% $ 0 0 $0C D D+ +K N11+>>>*11(;;;;-<<>> *9 *'..y999--k::::++,<,L,L,N,NOOO%)

/ "
 "$-$8$H$HM%i?? ". " H>>tYPZ\]^^^^-6-A/-R-RN#88 ) .3=/4	  9     " !% = =$-~{A!" !" !" Y111"-h7!$(/22 7a.2mm	5!4 /< / /+J N))+666	7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 '')) \h,.F.F!%U!3!3J00JGG \$7	$B$B	%8%D%D
55iZYZ[[[T!!X%9%9![[//
!^^--
,,Y
SW,XX X 3I > >I!4Z!@!@JH11)ZUVWWW%%d++++"#L(#L#LMMM ~#<<!!!s7   A EEE9G$$G(+G(.8P22P6	9P6	c                *   t          |t                    sdS t          |j        t                    ra|                     |j        |          }t          |t
                    r1|j        *| j                            |t          |                     |S dS )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)
r   rf   r.  r{   r7  r   r:  r  r  r   )r#  r  r/  s      r   r  z1ExpressionChecker.find_partial_type_ref_fast_path  s     $(( 	4di%% 	))$)T::F&+.. 6;3J##D*<V*D*DEEEtr   )r~  
seen_typesr  r  r~  r  set[tuple[Type, Type]] | Noner  r  c               @	   | j         j        j        sdS |t                      }||f|v rdS |                    ||f           t          ||f          \  }}t          |d          st          |d          r|sdS |rt          |          }t          |          }| j         j        	                                rdS | j         j        j
        r-t          |t                    rt          |t                    rdS n,t          |t                    st          |t                    rdS t          |t                    rGt          |t                    r2t          |          }t          |          }t          ||f          \  }}|r t          |          rt          |          rdS t          |t                     rt          |t                     r|j        j        }|j        j        }|t&          v rq|t&          v rh| j                             d          }	t+          ||	          }t+          ||	          }|                     |j        d         |j        d         |          S |j                            d          r|j                            d          r| j                             d          }
t+          ||
          }t+          ||
          }|                     |j        d         |j        d         |          p-|                     |j        d         |j        d         |          S |d	v r4||k    r.|                     |j        d         |j        d         |          S |t2          v r|t2          v rdS t          |t4                    rKt          |t4                    r6t          |j        t8                    rt          |j        t8                    rdS t          |t4                    rFt          |t                     r1|j        j        j        d
k    r|j                            d          rdS t          |t4                    rFt          |t                     r1|j        j        j        d
k    r|j                            d          rdS t=          ||d           S )a  Check for dangerous non-overlapping comparisons like 42 == 'no'.

        The original_container is the original container type for 'in' checks
        (and None for equality checks).

        Rules:
            * X and None are overlapping even in strict-optional mode. This is to allow
            'assert x is not None' for x defined as 'x = None  # type: str' in class body
            (otherwise mypy itself would have couple dozen errors because of this).
            * Optional[X] and Optional[Y] are non-overlapping if X and Y are
            non-overlapping, although technically None is overlap, it is most
            likely an error.
            * Any overlaps with everything, i.e. always safe.
            * Special case: b'abc' in b'cde' is safe.
        FN__eq__ztyping.AbstractSetr   )r  r'  r  )re  r  r   r   )ignore_promotions)r  r  strict_equalityrf  rj  r   r   r  r  !is_unreachable_warning_suppressedstrict_equality_for_noner   r   r   r   has_bytes_componentr   r:  rA  r   r,  r1   r  r  r+  r   r   r  r   r  r2   )r#  rE  rF  r~  r  r  r  	left_name
right_nameabstract_setabstract_maps              r   r  z&ExpressionChecker.dangerous_comparison  s   2 x/ 	5J%=J&&5e}%%%&e}55e "$11	5J5RZ5[5[	 	 5 	/
 't,,D'..E8?<<>> 	 584 	$)) j.I.I uh'' 	:eX+F+F 	5dI&& 	::eY+G+G 	:"4((D#E**E*D%=99KD%	#$677	 $D))	 5dH%% 	*UH*E*E 		*I,J888"===#x778LMM0|DD1%FF00IaL%*Q-J 1    ##$455 %*:M:MN^:_:_ #x778HII0|DD1%FF00IaL%*Q-J 1   c..ty|UZ]Wa.bbc AAAjT]F]F]00IaL%*Q-J 1    999j+? ? udK(( 	Z{-K-K 	$*d++ 
5;0M0M udK(( 	Zx-H-H 	}!*.>>>5:CVCV$D D> ue[)) 	jx.H.H 	~"+/???DIDVDV$E E? u'euMMMMMr   rw  r  c                "   |p|}|p|}t          |          }t          |t                    r|                     ||||||          S t	          |||ddd||| 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)rK  r  r  r  r  r  r  )r   r   r   check_union_method_call_by_namer   r  r]  check_method_call)	r#  rw  r>  r  r  rW  r  r  ro  s	            r   r  z+ExpressionChecker.check_method_call_by_name  s      &2*	#I..	i++ 	77	4G]   ,'#6688
 
 
 %%fidIW^___r   c           
     d   g }g }|                                 D ]z}	| j                                        5  |                     ||	||||          \  }
}ddd           n# 1 swxY w Y   |                    |
           |                    |           {t          |          t          |          fS )a  Type 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)r  r  r5  r  r  r   )r#  rw  r>  r  r  rW  r  r  meth_resr  r  	meth_items               r   r  z1ExpressionChecker.check_union_method_call_by_nameE  s     !++-- 	' 	'C ,,..  "&"@"@Cy'=# #i               JJtOOI&&&&$S))+@+J+JJJs   AA"	%A"	ro  c                    |                      ||          }||nd}|                     ||||||          }|                     ||||||          S )zType check a call to a method with the given name and type on an object.

        Return tuple (result type, inferred method type).
        Nr  r  )r  r  r  )	r#  r  r>  ro  r  r  rW  r  rU  s	            r   r  z#ExpressionChecker.check_method_calla  s     ,,YDD#0#<ii$ 00;ik 1 
 
 '!  
 
 	
r   op_namerq  	left_exprr  
right_exprc           
     0    d fd}dd}t          |          }t          |          }t          |t                    rt          t          j        |          }	|	|	fS t          |t                    rt          t          j        |          }	|	|	fS t
          j        |         }
 |||          } ||
|          }|t
          j        v rt          ||          r||||fg}nt          ||          rut          |t                    r`t          |t                    rK|j        j        |j        j        j        |j        u s' |||           |||
          k    r|
|||f||||fg}n||||f|
|||fg}d |D             }g }g }|D ]\  }}}} j                            d          5 }                     ||||gt           g          }d d d            n# 1 swxY w Y   |                                r=|                    |                                           |                    |           |c S t          |t                    r|j        j        s!t          |t                    r)|j        j        rt          t          j                  }	|	|	fS |s j                            d          5 }                     |||gt           g          }d d d            n# 1 swxY w Y   |                                r=|                    |                                           |                    |           n|S  j                            |d                    t1          |          dk    r|d         S t          t          j                  }||f}|S )Nr  r  r>  r   r   r  c                (   t          || j                  sdS j                                        5 }t	          | |ddd|j                                        	  	        }|                                rdn|cddd           S # 1 swxY w Y   dS )zYLooks up the given operator and returns the corresponding type,
            if it exists.NFT)	r=  r  rK  r  r  r  rW  r  r  )r   rP  r  rS  r   r  r]  r  )r  r>  r  r  rW  r#  s       r   lookup_operatorz>ExpressionChecker.check_op_reversible.<locals>.lookup_operator  s    
  	7DODD t'')) >Q. !#" $"+#'+'>'>'@'@
 
 
  !//11=ttv> > > > > > > > > > > > > > > > > >s   ABBBr  r   r  r  c                j    | j         j        D ]%}|j                            |          r	|j        c S &dS )a  Returns 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)r:  r  rg  r  rA  )r  r  clss      r   lookup_definerz=ExpressionChecker.check_op_reversible.<locals>.lookup_definer  sE     x| ( (9==++ (<'''(4r   r  c                (    g | ]\  }}}}|	||||fS r   r   )r   nard  objr$  s        r   r  z9ExpressionChecker.check_op_reversible.<locals>.<listcomp>  s0    ```+=BCQSQ_RS#&Q_Q_Q_r   Tr{  r   r  )r  r  r>  r   r   r  )r  r   r  r  r   r  )r   r   r   r   r  r   rn  op_methods_that_shortcutr   r   r   r:  alt_promoter  rS  r  r8   r  r  r  r  r6  r  r  r  r>  )r#  r  rq  r  r  r  rW  r  r  any_typerev_op_nameleft_opright_opvariants_rawvariantsr  r6  r=  rw  r  r$  local_errorsr/  	error_anys   `     `                 r   check_op_reversiblez%ExpressionChecker.check_op_reversible  s   	> 	> 	> 	> 	> 	> 	>,	 	 	 	  $I..	$Z00
 i)) 	&y9iPPPHX%%j'** 	&y9jQQQHX%%
  27;!/'955"?;
;; i888\)U_=`=`8 %gy*EFLLz9--	9h//	 :x00	
 *6N.3zFFy'22nnZQ\6]6]]] h
I>'9j9LL '9j9h
I>L a```` &. 	 	"D&#s''T'BB ^l//c6C57)U\]]^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^**,, l::<<===v&&&&
 y(++ 	&	0N 	&z8,,	&1;1P	& y566HX%%  	''T'BB l77Ywi               
 **,, l::<<===v&&&& F1I&&&w<<11:	 455I	)FMs$   )"GG	G	3!K  K$'K$r$  rc  c                ^   |r|g}t          |          }t          |t                    r.t          t	          |                                                    }|                     |          }g }g }	| j                                        5 }
|D ]Y}| 	                    ||t          |          ||          \  }}|                    |           |	                    |           Z	 ddd           n# 1 swxY w Y   |
                                s"t          |          }t          |	          }||fS ||fg}t          |          }t          |t                    r-fdt	          |                                          D             }g }g }	| j                            d          5 }
|D ]a}|D ]\\  }}| 	                    ||t          |          ||          \  }}|                    |           |	                    |           ]b	 ddd           n# 1 swxY w Y   |
                                r| j                            |
                                           |
                                d         }t          t!                                }|j        |_        |j        |_        t'          |          dk    r.t'          |          dk    r| j                            |           nat'          |          dk    r| j                            d	||           n0t'          |          dk    r| j                            d
||           t          |          }|                     t/          |	                    }||fS |                     |||gt2          g          S )zType check a binary operation which maps to a method call.

        Return tuple (result type, inferred operator method type).
        r?  )r  rq  r  r  r  rW  Nc                6    g | ]}|t          |           fS )r?  )rp   )r   r  rW  s     r   r  z.ExpressionChecker.check_op.<locals>.<listcomp>i  s;     " " " 8D':::;" " "r   Tr{  r4  r  LeftRight)rw  r>  r  r  rW  )r   r   r   r  r   r  ru  r  rS  r  rp   r  r  r   r  r  r   rC  rD  r  "warn_both_operands_are_from_unionswarn_operand_was_from_unionr  r   r  r8   )r#  rw  r>  r$  rW  rc  left_variantsr  all_resultsall_inferredr  left_possible_typer/  r!  results_finalinferred_finalright_variantsright_possible_typer  r  recent_contexts       `                r   rm  zExpressionChecker.check_op/  s     `	&KM'	22I)Y// X $%:9;S;S;U;U%V%V W WS))J
 KL'')) 2\*7 
2 
2&'+'?'? &"4"*+=w"O"O"O#-#& ' (@ ( ($FH  &&v... ''1111
22 2 2 2 2 2 2 2 2 2 2 2 2 2 2  ..00 5 5k B B!6|!D!D$n44  *3/0N(44J*i00 " " " " 5j6O6O6Q6Q R R" " "
 KL''T'BB 6l*7 6 6&;I 
6 
67+Z+/+C+C$*&8&./A7&S&S&S':'1$+ ,D , ,( $**6222$++H5555
666 6 6 6 6 6 6 6 6 6 6 6 6 6 6 **,, ##L$@$@$B$BCCC"2244R8!)(**!5!5&)h#(+
%}%%**s>/B/Ba/G/GH??OOOO''1,,H88Tb8cccc((A--H88^ 9    2+>>M!==>N|>\>\]]N .0011#U") 2   s&   AC66C:=C:,A%HH"%H"c                   | j         d         }|                     |j        |          }t          |d          }|j        dv sJ |j        rd}i }ng|j        ri d}}n[|j        dk    r#| j                            |j                  \  }}n-|j        dk    r"| j                            |j                  \  }}t          j
        | j        j        j        v r.|,|j        s%| j                            |j        |j                   | j                                        r.|,|j        s%| j                            |j        |j                   |                     ||j        |                     |                    }||t)                      S ||J |S ||J |S |j        dk    rt+          |          }|j         }	n"|j        dk    rt/          |          }|j         }	t3          |t(                    r|S |	r|S t5          ||g          S )z/Type check a boolean operation ('and' or 'or').r4  r\  )r[  r\  Nr[  r\  )r  ru  rE  r   rd  right_alwaysright_unreachabler  find_isinstance_checkr  REDUNDANT_EXPRr  enabled_error_codesr  redundant_left_operand should_report_unreachable_issuesunreachable_right_operandrF  analyze_cond_branch_combined_contextr   r   can_be_truer   can_be_falser   r   )
r#  r)  rJ  rq  expanded_left_typeleft_map	right_mapr  restricted_left_typeresult_is_lefts
             r   re  z"ExpressionChecker.check_boolean_op  sS    #KK,,	<YXXt}$$$$> 	I-1H.0II  	I"$diHHTU]]"&("@"@"H"HIxxTT\\"&("@"@"H"HHi
  DH$4$HHH N ! H++AD!&999 H5577	>!' " H..qtQW===--qw 6 67I J J
 

 	 1"$$$'''(((45==#-.@#A#A !3!??NNTT\\#,-?#@#@ !3!@@N*O<< 	M 	M(*>
)KLLLr   c                R   |                      |j                  }t          ||                     d                    r(|                      |j        | j        d                   }n|                      |j                  }|                     d||j        |          \  }}||_        |S )zzType check an expression of form '[...] * e'.

        Type inference is special-cased for this common construct.
        rJ  r4  r  __mul__)ru  rF  r   rP  rE  r  rm  ro  )r#  r)  r  rq  r/  ro  s         r   rf  z%ExpressionChecker.check_list_multiply  s    
 [[))
j$//."A"ABB 	, AF9J29NOOIIAF++I"mmIy!'1MM#r   rC   c                J   |                      |j                  }| j                            |j        |j                   | j                            |           t          |          s | j                            |j        |           |                     |j                   |S r   )	ru  r  r  check_assignmentry  check_finalr5  r  r  )r#  r)  r  s      r   visit_assignment_exprz'ExpressionChecker.visit_assignment_expr  s    AG$$!!!(AG444Q(// 	1 H%000,,QX666r   rz   c                (   |                      |j                  }|j        }|dk    r5|                                 }| j                            ||j                   n5t          j        |         }|                     ||g g |          \  }}||_	        |S )z7Type check an unary operation ('not', '-', '+' or '~').not)
ru  r  rd  r  r  check_for_truthy_typer   unary_op_methodsr  ro  )r#  r)  operand_typerd  r/  rw  ro  s          r   visit_unary_exprz"ExpressionChecker.visit_unary_expr  s    {{16**T;;>>++FH**<@@@@/3F"&"@"@WY[]_`"a"aFK'AMr   rU   c                    |                      |          }|                     ||          }t          |          }|                                 r#t	          |t
                    r|j        |j        }|S )zgType check an index expression (base[index]).

        It may also represent type application.
        )visit_index_expr_helperr,  r   r]  r   r   r^  )r#  r)  r/  p_results       r   visit_index_exprz"ExpressionChecker.visit_index_expr  sw    
 --a00--a88"6**##%%	/8X..	/ )5.Fr   c                    |j         r|                     |j                   S |                     |j                  }|                     ||          S r   )rr  ru  rw  visit_index_with_type)r#  r)  rq  s      r   r  z)ExpressionChecker.visit_index_expr_helper!  sI    : 	+;;qz***KK''	)))Q777r   ProperType | Nonec           	     t    j         }|p|}t          |          }                     |           t          |t                    r.t          d |j        D                       rt          |i           }t          |t                    r5p|t           fd|
                                D             d          S t          |t                    rF j                                        r,t          |t                    r                     ||          S                      |          }|g }|D ]}                     ||          }	|	|                    |	           0 j                            t&          j                   t          d |j        D                       r3                     |          }
 j                            d|
            t/          t0          j                  c S t          |          S                      ||          S t          |t6                    r!                     |j                   d         S t          |t:                    r|                                r|                                j         r. !                    |                                j                   S |                                j"        s|                                j#        d	k    r $                    d
          S t          |tJ                    r* &                    |'                                |          S t          |tP                    r%|j)        j#        dk    r $                    d          S  *                    d|j         gtV          g|          \  }}|_,        |S )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).
        c              3  @   K   | ]}t          |t                    V  d S r   r  r   s     r   r   z:ExpressionChecker.visit_index_with_type.<locals>.<genexpr>;  s=       4
 4
+-Jr:&&4
 4
 4
 4
 4
 4
r   c                >    g | ]}                     |          S r   )r  )r   r  r)  r  r#  s     r   r  z;ExpressionChecker.visit_index_with_type.<locals>.<listcomp>E  s;        ..sA}EE  r   F)contract_literalsNc              3  @   K   | ]}t          |t                    V  d S r   r  r  s     r   r   z:ExpressionChecker.visit_index_with_type.<locals>.<genexpr>Z  s,      RRQz!Z88RRRRRRr   zVariadic tuple can have length r   r<  ztypes.GenericAliasrY  __getitem__)r  r  )-ro  r   ru  r   r   r  r   r'   r   r   r  r  r;  rj   visit_tuple_slice_helpertry_getting_int_literalsvisit_tuple_index_helperr  r  r   TUPLE_INDEX_OUT_OF_RANGEmin_tuple_lengthr  r   r   r>  nonliteral_tuple_index_helperr   visit_typeddict_index_exprr   r  r  r  visit_enum_index_exprr6  rA  rP  r   r  values_or_boundr   r:  r  r8   ro  )r#  rq  r)  r  r  ro  nsoutrn  r  min_lenr/  ro  s   ` ``         r   r  z'ExpressionChecker.visit_index_with_type(  s    *	#I..	 	Ei++ 	3 4
 4
1:4
 4
 4
 1
 1
 	3 $Ir22Ii++ )	=)6YM(     (7799   #(    	9-- 	=$(2N2N2P2P 	= %++ G44YFFF..u55B~ 	= 	=A88AFFD'

4((((&6&OQRSSSRR)/RRRRR Z&*&;&;I&F&FG HMM*UG*U*UWXYYY&y';<<<<<,S11199)UKKK	=11 		=229agFFqII	<00 	=Y5J5J5L5L 	=$$&&. =11)2G2G2I2I17TUVVV%%''1=((**3FF';<<<i-- 	--))++Qy   	8,, 	1HLa1a1a??#8999"&"@"@		+# #A # #FK (AMMr   c                H   t          |j                  }||                                S |j        |         }t          |t                    sJ t          |j        t                    r$|                                dz
  |j        j        z   S |                                dz
  S r  )r   r   lengthr   r   r:  r   r  )r#  rE  unpack_indexunpacks       r   r
  z"ExpressionChecker.min_tuple_length  s    *4:66;;== L)&*-----fk#344 	;;;==1$v{':::{{}}q  r   c           
        t          |j                  }|N|dk     r|t          |j                  z  }d|cxk    rt          |j                  k     rn n|j        |         S d S |j        |         }t          |t                    sJ t          |j                  }t          |t                    rKt          |j                  }t          |t                    sJ |j        j
        dk    sJ |j        d         }n6t          |t                    sJ |j        j
        dk    sJ |j        d         }|                     |          |                                z
  dz   }|dk    ry||                     |          k    rd S ||k     r|j        |         S t          j        |g|j        |dz   t!          ||z
  dz   |dz                      z   |j        |j                  S ||                     |          z  }|dk     rd S |||z   k    r|j        ||z
  dz            S t          j        |j        t'          ||          |         |gz   |j        |j                  S )Nr   r  r  r  )r   r   r  r   r   r   r:  r   r  r   rA  r  r
  r  r   r  maxrC  rD  r  )	r#  rE  rn  r  r  unpackedboundmiddleextra_itemss	            r   r  z*ExpressionChecker.visit_tuple_index_helper  s   *4:661uuS__$A''''DJ'''''z!}$4L)&*-----"6;//h 011 	& $H$899EeX.....:&*:::::Z]FFh11111=)-=====]1%F++D11DKKMMAAE66D))$//// t<z!}$'*\A-AOa4GXYIY0Z0ZZ[\		   	
T""4(((q554{***:a+o122#Js1l++l:;vhF	SWS^
 
 	
r   slicrj   c           	        d g}d g}d g}|j         r4|                     |j                   }||                     ||          S |}|j        r4|                     |j                  }||                     ||          S |}|j        r4|                     |j                  }||                     ||          S |}g }	t          j        |||          D ]\  }
}}|                    |
|||                     d                    }|@| j	        
                    t          j        |           t          t          j                  c S |	                    |           t#          |	          S )Nr  r  )begin_indexr  r  	end_indexstride	itertoolsproductslicerP  r  r  r   !AMBIGUOUS_SLICE_OF_VARIADIC_TUPLEr   r   r>  r  r   )r#  rq  r  beginendr!  	begin_rawend_raw
stride_rawr   br)  sr  s                 r   r  z*ExpressionChecker.visit_tuple_slice_helper  s   '+f%)F(,v 	55d6FGGI 99)TJJJE> 	33DNCCG99)TJJJC; 	 66t{CCJ!99)TJJJF (V<< 	 	GAq!??1aT__EU5V5V?WWD|.PRVWWWy344444LL$U+++r   ro  list[int] | Nonec                   t          |t                    r|j        gS t          |t                    ra|j        dk    r'|j        }t          |t                    rd|j        z  gS |j        dk    r$|j        }t          |t                    r|j        gS t          |                     |                    }t          |t                    r|j	        |j	        }t          |t                    r"t          |j        t                    r|j        gS t          |t                    rgg }t          |j                  D ]N}t          |t                    r5t          |j        t                    r|                    |j                   L dS |S dS )a  If 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
        -r4  r_  N)r   rV   r  rz   rd  r  r   ru  r   r^  r   r^  r   r   r   r  )r#  ro  operandr  r  r  s         r   r  z*ExpressionChecker.try_getting_int_literals  s{    eW%% 
	+K= y)) 	+x3*gw// 0.//x3*gw// +#M?*dkk%0011c8$$ 	')=)I&Cc;'' 	Jsy#,F,F 	I;c9%% 	C(33    dK00  Z
C5P5P  JJtz****44Jtr   c                    |                      d||gt          g|           |                     |          }t          |t                    r| j                            d|g          S |S )Nr  r?  r  )r  r8   union_tuple_fallback_itemr   rj   r  rr  )r#  rq  ro  unions       r   r  z/ExpressionChecker.nonliteral_tuple_index_helper   sl    &&}i%7)]b&ccc..y99eY'' 	J8../?%IIIr   c                   g }|j         D ]}t          |t                    rt          |j                  }t          |t
                    rt          |j                  }t          |t                    r1|j        j        dk    r!|	                    |j
        d                    t          |	                    |           t          |          S )Nr  r   )r   r   r   r   r:  r   r  r   rA  r  r  NotImplementedErrorr   )r#  rq  r   r  r  s        r   r2  z+ExpressionChecker.union_tuple_fallback_item  s    O 	# 	#D$
++ # /	 : :m-=>> O$3M4M$N$NM}h77.%*37GGGLL!3A!67777--T""""$U+++r   td_typesetitemtuple[Type, set[str]]c                   t          |t                    r
|j        g}n(t          |                     |                    }t          |t
                    rt          |j                  }n|g}g }t          |          D ]}t          |t                    r|j
        |j
        }t          |t                    rJt          |j        t                    r0|j        j        j        dk    r|                    |j                   | j                            ||           t'          t(          j                  t-                      fc S g }|D ]y}	|j                            |	          }
|
F| j                            ||	||           t'          t(          j                  t-                      fc S |                    |
           zt3          |          t-          |          fS )Nr   )r   rl   r  r   ru  r   r  r   r   r   r^  r   r  r  r:  rA  r  r  $typeddict_key_must_be_string_literalr   r   r>  rf  r  typeddict_key_not_foundr   )r#  r6  ro  r7  	key_namesr  	key_typesr  value_typeskey_namer  s              r   r  z,ExpressionChecker.visit_typeddict_index_expr  s    eW%% 	@II!$++e"4"455C#y)) "(,SY		 E	I,Y77 @ @h11 9h6O6['8H x55@"8>377@ !).7;KKK$$X^4444HAA'5QQQ"9#788#%%????! 	/ 	/H **844J!00(E7SSSy344cee;;;;"":....$[113y>>AAr   	enum_typec                    |                      d          }| j                            |                     |          ||dd           t	          |g           S )Nr=  zEnum index should be a stringzactual index type)rP  r  check_subtyperu  r   )r#  r@  ro  rW  string_types        r   r  z'ExpressionChecker.visit_enum_index_expr@  s\     !OON;;KK+	
 	
 	
 	2&&&r   rG   c                   |                      |j        t          t          j                  dd          }|j        }| j        j        }|j        rRt          |t          t          j                            s+t          ||          r| j
                            ||           |j        r+t          |          r| j
                            d||           t          || j        j        | j        j        | j
        |           |S )zType check a cast expression.Tr  ro  r  zTarget type of castr?  )ru  r  r   r   r6  r:  r  r  warn_redundant_castsr   r  redundant_castdisallow_any_unimportedr   unimported_type_becomes_anyr   is_typeshed_stub)r#  r  source_typetarget_typer  s        r   visit_cast_exprz!ExpressionChecker.visit_cast_exprM  s   kkI !788"!	 " 
 
 i("(	7 gi6L.M.MNN	7 [+66	7
 H##K666* 	[/KK/X/X 	[H001FUYZZZ)48+DdhX\	
 	
 	
 	
 r   ru   c                T    |j         }t          j        ||j        |j        d          S )NTrC  rD  is_type_form)r:  r   r  rC  rD  )r#  r  r  s      r   visit_type_form_exprz&ExpressionChecker.visit_type_form_exprd  s(    i'#(3:\`aaaar   rB   c                   |                      |j        | j        d         dd          }| j        j        r|S |j        }t          |          }t          |t          j	        j
                  r|j        |j        }t          ||          sU| j                                        s | j                            d|j                   | j                            |||           |S )Nr4  TrE  zC"assert_type" expects everything to be "Any" in unchecked functions)ru  r  r  r  r  r:  r   r   r  r   r   r^  r   r;  r  r  assert_type_fail)r#  r  rK  rL  proper_source_types        r   visit_assert_type_exprz(ExpressionChecker.visit_assert_type_exprh  s    kkI*2."!	 " 
 
 8) 	i,[99)4:+>??	>"3?,=KK55 	F8//11 YI   H%%k;EEEr   rg   c                D   |j         t          k    r|j        J |                     |j        | j        d         d          }| j        j        sn| j                            ||j                   | j        	                                s | j        
                    d|j                   |                     |           |S | j        j        sJ|j        d |j        D             ni }| j                            ||           |                     |           t                      S )z$Type check a reveal_type expression.Nr4  Tr  ro  z9'reveal_type' always outputs 'Any' in unchecked functionsc                (    i | ]}|j         |j        S r   )r=  r:  )r   var_nodes     r   rF  z7ExpressionChecker.visit_reveal_expr.<locals>.<dictcomp>  s    SSShX]HMSSSr   )r  r?   r  ru  r  r  r  r  reveal_typer;  r  check_reveal_importedlocal_nodesreveal_localsr   )r#  r  revealed_typenames_to_typess       r   visit_reveal_exprz#ExpressionChecker.visit_reveal_expr  s7   9##9((( KK	(9"(=QU (  M 81 1$$]DI>>>x3355 HMMSUYU^   **4000   81 1 '3 TS$BRSSSS  &&~t<<<**4000::r   c                   t           j        | j        j        j        vrd S d}|j        t          k    rd}n|j        t          k    r
|j        sd}nd S | j        	                    d| d|t           j                   |dk    rY| j        j        j
        dk    rdnd	}d
                    ||          }| j                            ||t           j                   d S d S )N r]  rZ  zName "z" is not definedr  )r     typingtyping_extensionszXDid you forget to import it from "{module}"? (Suggestion: "from {module} import {name}"))moduler=  )r  UNIMPORTED_REVEALr  r  r  r  r>   r?   is_importedr  r  r  r  )r#  r  r=  rf  hints        r   r[  z'ExpressionChecker.check_reveal_imported  s    "$(*:*NNNF9%%"DDY+%%d.>% DDF5t555t%BYZZZ=   H,;wFFL_ ?fFf..  HMM$5+BMCCCCC ! r   tapprs   c                `   t          |j        t                    rt          |j        j        t                    r|j        j        j        r|                                 S t          |j        j        |j        | j	        j
        |j        j        j        || j	        j                  }t          |          }t          |t                    r6t          |j        | j                  }|                     ||j        |          S t          |t(                    rQ|j        j        j        r@t          |j        j        | j                  }|                     ||j        j        |          S t          |t.                    r|                     |          S | j	        
                    t2          j        |           t7          t8          j                  S t          |                     |j                            }t          |t>          t@          f          rU|!                                s%| j	        
                    t2          j        |           |                     ||j        |          S t          |t6                    rt7          t8          j"        |          S t7          t8          j#                  S )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  )$r   r  rf   r.  r   python_3_12_type_aliastype_alias_type_typer   r   r  r  r  r  r   r   r   r:  rP   apply_type_arguments_to_callabler  r   rh  r  r   r5  r   ONLY_CLASS_APPLICATIONr   r   r>  ru  r   r   r  r  r6  )r#  rj  r  r  s       r   visit_type_applicationz(ExpressionChecker.visit_type_application  s2    di)) 	5j.S.S 	5y~4 300222)	
	&  D #4((D$)) 
5%diAA<<RDQQQD),, 51F1K1Z 5%d&;&@$/RR<<RAVA[]abbbD-00 5;;DAAA.EtLLLy3444 T[[3344b<455 	O>>## M.EtLLL88TZNNNb'"" 	F95"EEEEy-...r   aliasrr   c                <    |                      |j        |d          S )a  Right 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`.
        TrN  )rT  r.  )r#  rq  s     r   visit_type_alias_exprz'ExpressionChecker.visit_type_alias_expr  s"     11%*%Z^1___r   )rO  r   rO  c                  |j         r|                                 S t          |j        t                    r%|j        j        rt          t          j                  S | j	        j
        j        o| j        }t          t          |g |j        |j        | j	        j
        || j        j                            }t          |t                    r?t'          |j        | j                  }|j        r|S |                     ||j        |          S t          |t2                    rDt5          |          j        j        dk    r't'          t5          |          j        | j                  S t          |t8                    r|                     |          S t          |t<                    rt?          ||j        |j                  S t          |t                    rt          t          j         |          S t          |tB                    r<|j"        r5| j	        j
        j#        dk    r | j	        $                    d|j%                  S |rt          t          j&                  S |                     d          S )a  Get 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_anyr  r  rC  rD  r  r  ztypes.UnionTyperY  )'rl  rm  r   ry  r   invalidr   r   r>  r  r  disallow_any_genericsr  r   r   rC  rD  r  r  r   r:  rP  r  rn  r  r   r   rA  r   r5  r   r   r  r   r  r  rr  r   r6  )r#  rq  rJ  rO  ru  r  r  s          r   rT  z/ExpressionChecker.alias_type_in_runtime_context  s:     ' 	/,,...elH-- 	1%,2F 	19/000
 x'=P$.
 )X]  

 

 dH%% 	: "$)T_==B} 	88TYLLLtY''	: 4  %.2BBB#N4$8$8$=tOOOm,, 	:77===h'' 	:DtyEEEEg&& 	:95$GGGGtY''
	:'
	:  /7::8../@$*MMM 7y5666??#8999r   r   c                `   |                                 r|                                j        j        }nt	          |j                  }t          |          }t          |j        |          D ]\  }}t          |t                    rt          t          |          t          t          t          t          f          sb| j                            dt!          || j        j                   |           t          t$          j                  gt)          |          z  c S |rt+          d |D                       st	          |          S |                                 sJ |                                }t-          |||j        |j                  }t3          || j        j        d          sFt5          || j        j        | j        j        d| j        j                   t	          |j                  }t;          d t=          |          D                       }	t)          |          |	z
  d	z
  }
||	         }t          |t>                    sJ tA          tC          |          |	|
          \  }}}t	          |          tE          t	          |          |j#                  gz   t	          |          z   S )
a  Handle 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 c              3  @   K   | ]}t          |t                    V  d S r   r   r   r  s     r   r   z7ExpressionChecker.split_for_callable.<locals>.<genexpr>W  s-      MM1z!-=>>MMMMMMr   rv  T)empty_tuple_indexF)ru  r  c              3  J   K   | ]\  }}t          |t                    |V  d S r   r{  )r   r  r  s      r   r   z7ExpressionChecker.split_for_callable.<locals>.<genexpr>g  s6      YYFQAGW9X9XYaYYYYYYr   r  )$r  r  r  r6  r  r7  r   r  r   r   r   r   r   r   r  r  r6   r  r   r>  r  r  r   rC  rD  r   r   r  r  nextr  r   r   tupler   r   )r#  r   r  rJ  varsri  r$  r  fakeprefixsuffixtvtstartr  r'  s                  r   split_for_callablez$ExpressionChecker.split_for_callable6  s    ==?? 	%==??'1DD$$D$T** 1;-- 
	G 
	GGB"m,, 	G!#C((:}g{*[  G HMMX3>sDHDT3U3UX X  
 $I$899:SYYFFFF 	3MMMMMMM 	::}}}}d#*EEE !tx}MMM 	#dhmTX]PTPXP`    	??DYYiooYYYYYTV#a'6l#/000009%++vvVVvsE{{iVc6HIIJJTRUYYVVr   r  c                    t          |          }t          |t                    r|                                r|                                j        j        }nt          |j                  }t          d |D                       }t          d |D                       }t                    |k     s!t                    t          |          k    r|s|                                r|                                j        dk    rt          t          t                     j                            d                    gt           gdgt          t                     j                            d                    |j        d|j        |j                  S  j                            |t          |          t                               t-          t.          j                  S                      |                     |                    S t          |t6                    r.|j        D ]}|                                r|                                j        j        }nt          |j                  }t          d |D                       }t          d |D                       }t                    |k     s t                    t          |          k    rT|sR j                            |t          |          t                               t-          t.          j                  c S t7           fd	|j        D                       S t-          t.          j                  S )
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.
        c              3  @   K   | ]}|                                  V  d S r   has_defaultr  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s-      GGAMMOO 3GGGGGGr   c              3  @   K   | ]}t          |t                    V  d S r   r{  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s-      $X$XZ3C%D%D$X$X$X$X$X$Xr   r  r  N)r=  r  r=  c              3  @   K   | ]}|                                  V  d S r   r  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s-      #K#KA$7#K#K#K#K#K#Kr   c              3  @   K   | ]}t          |t                    V  d S r   r{  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s-      (\(\QA7G)H)H(\(\(\(\(\(\r   c           
     h    g | ].}                     |                    |                    /S r   )r6  r  )r   r   r  rJ  r#  s     r   r  zFExpressionChecker.apply_type_arguments_to_callable.<locals>.<listcomp>  sP        00T5L5LRQUWZ5[5[]`aa  r   )r   r   r   r  r  r  r6  r  r7  r}  r  r  rA  r   r  rP  r8   r  r  r=  r  incompatible_type_applicationr   r   r>  r6  r  r   r   r6  )r#  r  r  rJ  r6  min_arg_counthas_type_var_tupler   s   ` ``    r   rn  z2ExpressionChecker.apply_type_arguments_to_callablen  sH    R  b,'' '	a~~ / NN,,1;		 ..	GGYGGGGGM!$$X$Xi$X$X$X!X!XD		M))SYYY-G-G( .H>>## (8(8(AEU(U(U ("4::tx/B/B7/K/KLLM 	!$t**dh.A.A'.J.JKK$#%=!#	 	 	 	 66!3y>>3t99c   y3444//D4K4KBPTVY4Z4Z\_```b*%% 	h 9 9>>## 3 " 0 0 5 ?II $R\ 2 2I ##K#K#K#K#K K K%((\(\R[(\(\(\%\%\"II--TS^^1K1K, 2LH::%s9~~s4yy#   #9#788888      h     y-...r   rY   c                0    |                      |dd          S )z#Type check a list expression [...].re  z<list>check_lst_exprrL  s     r   visit_list_exprz!ExpressionChecker.visit_list_expr  s    ""1ox@@@r   ri   c                0    |                      |dd          S )Nr   z<set>r  rL  s     r   visit_set_exprz ExpressionChecker.visit_set_expr  s    ""1ng>>>r   ListExpr | SetExpr | TupleExprcontainer_fullnamec                   | j         d         }|s|j        sdS | j        j        rdS | j                            |d          }|t          |t                    r|ndS g }t                      }|j        D ]s}t          |t                    rt                      | j        |<    dS |                     |          }||vr*|                    |           |                    |           t|                     |          }	|	t                      | j        |<   dS | j                            ||	g          }
| j        s
|
| 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,
        r4  N)r  r   r  r  r  r  r   r   rf  rk   r   ru  r  rj  _first_or_join_fast_itemrr  r   )r#  r)  r  rJ  rtr  
values_setr  r  vtcts              r   fast_container_typez%ExpressionChecker.fast_container_type  s`   " # 	ag 	48) 	4##At,,>#B11;22t; #
G 		$ 		$D$)) (0

"1%tt++d##C*$$c"""s###**622:$,JJDq!4X(();bTBB" 	' %'Dq!	r   r   c                    t          |          dk    r| j        j        s|d         S t          j        |          }t          |          sd S |S )Nr  r   )r  r  r  r   r  r   )r#  r   r  s      r   r  z*ExpressionChecker._first_or_join_fast_item  sO    u::??48#A?8O!%((+C00 	 4
r   tagc           
        |                      ||          }|r|S t          ddt          dd          g |                                 t	          t
          j                            }t          |gt          j	        gd g| j
                            ||g          |                     d          ||g          }|                     |d |j        D             d	 |j        D             |          d
         }t          |          S )NTr4  z<lst>	namespacer  r  r  defaultrM  r=  r7  c                J    g | ] }t          |t                    r|j        n|!S r   )r   rk   r  r   r  s     r   r  z4ExpressionChecker.check_lst_expr.<locals>.<listcomp>  s-    IIIA
1h//6affQIIIr   c                h    g | ]/}t          |t                    rt          j        nt          j        0S r   )r   rk   r   r9   r8   r  s     r   r  z4ExpressionChecker.check_lst_expr.<locals>.<listcomp>  s0    ]]]PQ
1h 7 7JennU]]]]r   r   )r  r   r   rU  r   r   from_omitted_genericsr   r   r9   r  rr  rP  r  r   r"   )r#  r)  rA  r  r   ri  constructorr  s           r   r  z ExpressionChecker.check_lst_expr  s$   $$Q11 	H w///((**I;<<
 
 
 #D^FH''2$77OO/00d
 
 
 ooIIIII]]UVU\]]]	
 

  1555r   rq   c                   t          |j                  }|4t          d |j        D                       t          |j                  k    S t          d |j        D                       dk    rdS t          d t	          |j                  D                       }t          |j                  t          |j                  k    o||k    S )Nc                <    g | ]}t          |t                    |S r   r   rk   r   r)  s     r   r  z;ExpressionChecker.tuple_context_matches.<locals>.<listcomp>'  s'    MMMaZ85L5LMMMMr   c                <    g | ]}t          |t                    |S r   r  r  s     r   r  z;ExpressionChecker.tuple_context_matches.<locals>.<listcomp>*  s'    AAAaAx)@)@AAAAr   r  Fc              3  J   K   | ]\  }}t          |t                    |V  d S r   r  )r   r  lvs      r   r   z:ExpressionChecker.tuple_context_matches.<locals>.<genexpr>,  s7      ``UQzRTV^G_G_`q``````r   )r   r   r  r~  r  )r#  r  rJ  ctx_unpack_indexexpr_star_indexs        r   tuple_context_matchesz'ExpressionChecker.tuple_context_matches"  s    .sy99# MM4:MMMNNRUVYV_R`R``` AA4:AAABBaGG5``i
.C.C`````4:#ci..0X5E5XXr   c                j    t           j        d                   }d}t          |t                    r> fdt	          |j                  D             }t          |          dk    r	|d         }n	 t          |t                    r                     |          r|j        }nX|rVt          |t                    rAt          |t                    sJ |j        r#|j        d         gt          j                  z  }d}|t          |          du}d}|pt           j        j        j        v }g }d}	t%          t          j                            D ]	}
j        |
         }t          |t&                    r|r+|sJ ||	         }t          |t(                    sJ |j        }nd}                     |j        |          }t          |          }t          |t                    rkt          |j                  |r                     dd          c S d	}|                    |j                   |r|	dz  }	|	t          |j                  z  }	|r|st          |t                    rw j                            |          r] j                            |          } j                            d|g          }|                    t)          |                     d	}                     dd          c S |r|	t          |          k    r                     |          }n!                     |||	                   }|	dz  }	|                    |           t=          t>          j                   }t          | j                            d|g                    }|rtC          |i           }|S )
zType check a tuple expression.r4  Nc                    g | ]D}t          |t                    r                    |          st          |t                    B|ES r   )r   r   r  r   r   )r   r   r)  r#  s     r   r  z6ExpressionChecker.visit_tuple_expr.<locals>.<listcomp>5  sh     ! ! !q),,! 261K1KAq1Q1Q! %Q(ABB	!! ! !r   r  r   Fr  z<tuple>T)"r   r  r   r   r   r   r  r   r  r   r   r   r  r   r   r  r  ri  r  rk   r   r:  ru  r  r  rg  rj  rk  rr  r  r   r   r6  r'   )r#  r)  r  type_context_itemstuples_in_contextunpack_in_contextseen_unpack_in_itemsallow_precise_tuplesr   r  r  r  ctx_itemrJ  ttr  r-  fallback_itemr/  s   ``                 r   visit_tuple_exprz"ExpressionChecker.visit_tuple_expr/  s    't'8'<==!lI.. 	! ! ! ! !),*<==! ! ! $%%**03 lI.. 	K43M3MaQ]3^3^ 	K!-!3 	K/>WXX 	KlH55555  K&2&7&:%;c!'ll%J" ") 34F G Gt S$b!48H8b!b 	 s17||$$ 4	! 4	!A71:D$)) 2! % ----1!4H%h
;;;;;"-CCC[[C00$R((b),, O*2844@/ 8 $(#6#6q:JI#V#VVVV370LL***( +Q S]]*+ %4H %%b(33 %8Q8QRT8U8U %(,(C(CB(J(JI%)X%@%@AQT]S^%_%_F!LLF););<<<370$  ..q2BINNNNN) Q#6H2I2I-I-IT**BBT+=a+@AABFAR    	 677&48../?-QQ
 
   	- ,,Fr   rM   c                   | j         d         }|s|j        sdS | j        j        rdS | j                            |d          }|t          |t                    r|ndS g }g }t                      }t                      }d}|j        D ]!\  }	}
|	t          | 
                    |
                    }t          |t                    rC|j        j        dk    r3t          |j                  dk    r|j        d         |j        d         f}t                      | j        |<    dS | 
                    |	          }||vr*|                    |           |                    |           | 
                    |
          }||vr*|                    |           |                    |           #|                     |          }|t                      | j        |<   dS |                     |          }|t                      | j        |<   dS |r0|d         |k    s|d         |k    rt                      | j        |<   dS | j                            d||g          }| j        s
|| 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
        r4  Nri  r  r   r  )r  r   r  r  r  r  r   r   rf  r   ru  r:  rA  r  r  r   r  rj  r  rr  r   )r#  r)  rJ  r  r  r  keys_setr  stargsr  r  stkey_tvalue_tktr  dts                    r   fast_dict_typez ExpressionChecker.fast_dict_type  su    # 	ag 	48) 	4##At,,>#B11;22t;!ee #
+/' 	, 	,JC{$T[[%7%788r8,, (O;;BG)) gaj"'!*5FF,4JJD&q)44C((((KK&&&LL'''++e,,*,,MM'***NN7+++**400:$,JJDq!4**622:$,JJDq!4 	vayB&)r//$,JJDq!4X((2r(CC" 	' %'Dq!	r   typeddict_contextc                    |                      ||j        |d           }t          |          }t          |t                    r|                                S |                                S )N)r  r  rW  r  )r  r   r   r   r   re  )r#  r)  r  rY  rB  s        r   "check_typeddict_literal_in_contextz4ExpressionChecker.check_typeddict_literal_in_context  sn     ;;$QWaT < 
 
 #=11h.. 	,))+++ ..000r   c           
        |                      | j        d         |          \  }}|rt          |          dk    r|r|                     ||d                   S |D ]}| j                                        5 }| j        j        5 }|                     ||          }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                                r| j        	                    |           |c S |r| j        
                    ||           |                     |          }|r|S t          ddt          dd          g |                                 t          t           j                            }	t          d	d	t          d
d          g |                                 t          t           j                            }
g }g }|j        D ] \  }}|F|                    |           |                    | j                            d|	|
g                     Nt+          ||g          }|j        dk    r|j        |_        |j        |_        n|j        |_        |j        |_        |j        |_        |j        |_        |                    |           |                    t5          |	|
g|                     d                               t9          |t:          j        gt          |          z  dgt          |          z  | j                            d|	|
g          |                     d          d|	|
g          }|                     ||t:          j        gt          |          z  |          d         S )zoType check a dict expression.

        Translate it into a call to dict(), with provisions for **expr.
        r4  r  r   NKT<dict>r  r  VTr  r  ri  rM  r  ) find_typeddict_contextr  r  r  r  rS  r  rR  r  r  typeddict_context_ambiguousr  r   r   rU  r   r   r  r   r  rr  rq   rC  rD  end_line
end_columnr   rP  r   r   r8   r  )r#  r)  typeddict_contexts
exhaustiver  r  tmaprB  r  r  r  r  expected_typesr  r  tupr  s                    r   visit_dict_exprz!ExpressionChecker.visit_dict_expr  s3    *.)D)DTEVWYEZ\])^)^&J 	L%&&!++
+>>qBTUVBWXXX%7    !X++-- ]dh6M ]QU#FFqJ[\\H] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]%%'' $$T*** L445GKKK   ## 	I x000((**I;<<
 
 
 x000((**I;<<
 
 
 "$%'' 	^ 	^JC{E"""%%H//0RUWY[T\]]     e--8q=="xCH!$CJJ$zCH!&CJ$~!&!1C   %%iR$//JZ:[:[&\&\]]]] #]Oc.111FS(((H''"bBBOO/002h
 
 
 {D5=/CII2MqQQRSTTs6   5B<B%B<%B))B<,B)-B<<C 	C 		dict_expr tuple[list[TypedDictType], bool]c                P   t          |          }t          |t                    r|gdfS t          |t                    reg }d}|j        D ]U}|                     ||          \  }}|D ]3}|                     ||j        |          r|                    |           4|o|}V||fS g dfS )zExtract `TypedDict` members of the enclosing context.

        Returns:
            a 2-tuple, (found_candidates, is_exhaustive)
        TF)r   r   r   r   r   r  r1  r  )	r#  rW  r  r   r  r  item_contextsitem_exhaustiveitem_contexts	            r   r  z(ExpressionChecker.find_typeddict_context@  s     "'**g}-- 	%9d?"++ 	%EJ < <151L1LTS\1]1].$1 3 3L::$ioy  3 \222';O

*$$5yr   rW   c                   | j         }d| _         | j                            |d           |                     |          \  }}|sK| j        j                            t          t          j                             | j        j	        
                    dd          5  | j        j                            |          5  |j        j        dd         D ]}|                    | j                   |                     |                                d          }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                     d	          }| j        j                                         || _         t%          |||          S | j        j                            |j                   | j        j                            |          5  | j                            ||
           ddd           n# 1 swxY w Y   | j                            |                                          sb| j        j	        
                    dd          5  |                     |                                d           ddd           n# 1 swxY w Y   | j                            |                                          }| j        j                                         || _         t3          ||          S )zType check lambda expression.TF)body_is_trivialr   can_skipfall_throughNr4  rq  rM  )type_override)r   r  check_default_argsinfer_lambda_type_using_contextr  r  r   r   r6  r  frame_contextra  push_functionbodyru  r  rP  popr   rB  tscopefunction_scopecheck_func_itemr  r  replace_callable_return_type)r#  r)  old_in_lambdarh  r  stmtrB  r  s           r   visit_lambda_exprz#ExpressionChecker.visit_lambda_exprZ  s   +"##Au#==='+'K'KA'N'N$}  	IH!((1G)H)HIII --t!-LLI I,,Q//I I FK, * *DKK))))  ;;qvvxx4;HHI I I I I I I I I I I I I I I I I I I I I I I I I I I I I I ':;;HH!%%'''"/D Hh777 H!(()?@@@//22 I I((-(HHHI I I I I I I I I I I I I I I8$$QVVXX.. BX_22Dq2QQ B BKKDKAAAB B B B B B B B B B B B B B Bx++AFFHH55HH!%%'''"/D/xHHHs[    D;=AD$D;$D(	(D;+D(	,D;;D?D?G==HH*JJJ/tuple[CallableType | None, CallableType | None]c                >  	 t          | j        d                   }t          |t                    rFd t	          |                                          D             }t          |          dk    r|d         }|rt          |t                    sdS | j        j	        j
        sg 	|j        D ]<}d t          |          D             }	                    	fd|D                        =|                    t          |j        t#                                t%          |j                  	z             }nJt          |t#                                }t          |t(                    rt          |t                    sJ |}|                    |                     d	          
          }|j        |j        dS d |j        D             }|j        s|                                X|                    dt7          t8          j                  gt          |          z  ||j                                                  }t@          |v s	tB          |v r|dfS |j"        |k    r'| j        #                    tH          j%        |           dS |                    |j                  |fS )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.
        r4  c                <    g | ]}t          |t                    |S r   r  r  s     r   r  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s9       ZPQS_E`E`  r   r  r   NNc                D    g | ]}|j                                         |S r   )r  is_meta_var)r   ri  s     r   r  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s+    XXXBBEDUDUDWDWXRXXXr   c                    g | ]}|v|	S r   r   )r   ri  
extra_varss     r   r  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s#    "R"R"R"Rz=Q=Q2=Q=Q=Qr   )rB  r7  rM  r  Nc                    g | ]	}|j         
S r   )r  )r   r$  s     r   r  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s    555#SX555r   F)is_ellipsis_argsr  r  r  )r  )&r   r  r   r   r   r  r  r   r  r  r  r  r   rg  re  r#   rB  r   r  r7  r   rP  r  r  	argumentsr  r  r   r   r6  r  r  r9   r:   r  r  r   CANNOT_INFER_LAMBDA_TYPE)
r#  r)  rJ  r   r$  	meta_varscallable_ctxr7  r  r  s
            @r   r  z1ExpressionChecker.infer_lambda_type_using_context  s    d/344c9%% 	# +C,>,>,@,@AA  I 9~~""l 	*S,77 	: x2 	& J} T TXX*;C*@*@XXX	!!"R"R"R"R	"R"R"RSSSS,,*3<FFs}--
: -  LL
 +3
==Jj*55^*ZQ]:^:^^^^%L $114??K^;_;_1``".,2F2R :55555	( 	CNN,<,<,H'55!&"9#9::;c)nnL#+**,,	 6  L y  I$:$:%%!Y..HMM*CQGGG: ))AK)@@,NNr   rm   c                `   |                      |          }t          |t                    r|\  }}n|S t          |          }|>| j                            t          j        |           t          t          j
                  S t          |          }|>| j                            t          j        |           t          t          j
                  S |j        }d}||v r|                    |          }nl| j        j                                        }	|	Lt!          ||	j                  r6|j        r/||j        j        v r!|j        j        }|                    |          }|U|j        r||k    r
|j        sd}n>| j                            t          j        |           t          t          j
                  S t+          |          |dz   k    r>| j                            t          j        |           t          t          j
                  S ||dz   d         D ]}
|j        |
j        v s|
|d         k    rq|j        r3|j        j        r'|
|d         k    rt          t          j                  c S t7          |j        |ddd||
|| j        |                                 
  
        c S J d            )	z+Type check a super expression (non-lvalue).N)is_classmethodr4  r  FT)
r=  r  rK  r  r  r  override_inforW  r  r  r  )_super_arg_typesr   r  type_info_from_typer  r  r   UNSUPPORTED_ARG_1_FOR_SUPERr   r   r>  UNSUPPORTED_ARG_2_FOR_SUPERr  ro  ra  current_functionr   is_classr  r  !SUPER_ARG_2_NOT_INSTANCE_OF_ARG_1r  TARGET_CLASS_HAS_NO_BASE_CLASSr=  rg  r  r6  r   r]  )r#  r)  r   	type_typeinstance_type	type_infoinstance_infor  ro  rw  rw  s              r   visit_super_exprz"ExpressionChecker.visit_super_expr  s    %%a((eU## 	',$I}}L (	22	HMM*FJJJ9/000+M:: HMM*FJJJ9/000 IIi((EEX^4466F !&7fo' ' '! 6 1i16:55&*CIIi00E=)5!Y..!- / .PRSTTTy3444s88uqy  HMM*I1MMM9/000	$ 	 	Dv##ts2w6 ;af4 ;R #9#9:::::,%#! %"/"&'+'>'>'@'@      (7& 	$m###r   Type | tuple[Type, Type]c                
   | j                                         st          t          j                  S t          |j        j                  dk    r!|j        st          t          j	                  S | j         j
                                        r>| j                             t          j        |           t          t          j	                  S t          |j                  }t!          |          }| j         j
                                        }|J |j        r|j        d         j        j        p|}n| j                             t          j        |           t          t          j	                  S t,          |j        j        v r>| j                             t          j        |           t          t          j	                  S t3          |j        j                  t4          hk    r>| j                             t          j        |           t          t          j	                  S t          |j        j                  dk    r>| j                             t          j        |           t          t          j	                  S t          |j        j                  dk    rXt;          |                     |j        j        d                             }|                     |j        j        d                   }n>| j                             t          j        |           t          t          j	                  S tA          |t                    rD|j        r"t!          t          |j                            }nt          t          j!        |          S tA          |t                     r`|j"        }tA          |t                    rD|j        r"t!          t          |j                            }nt          t          j!        |          S tA          |t                     s]tA          |tF                    r|$                                s4| j%        &                    ||           t          t          j	                  S t;          |          }tA          |t                    r7|j        rt          |j                  }nt          t          j!        |          S tA          |t                     r`|j"        }tA          |t                    rD|j        r"t!          t          |j                            }nt          t          j!        |          S ||fS )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.
        r   Nr  r  r  )'r  r;  r   r   rN  r  callr  r  r>  ra  active_classr  r   %SUPER_OUTSIDE_OF_METHOD_NOT_SUPPORTEDr   r   r  r  variabler:  (SUPER_ENCLOSING_POSITIONAL_ARGS_REQUIREDr9   r  SUPER_VARARGS_NOT_SUPPORTEDrf  r8   SUPER_POSITIONAL_ARGS_REQUIRED#SUPER_WITH_SINGLE_ARG_NOT_SUPPORTEDr   ru  TOO_MANY_ARGS_FOR_SUPERr   r  r  r   r  r  %first_argument_for_super_must_be_type)r#  r)  current_typer  rw  r  	type_iteminstance_items           r   r	  z"ExpressionChecker._super_arg_types"  sT    x++-- $	190111""6 5y3444,,.. 5.TVWXXXy3444 )00L$,\$:$:I X^4466F%%% 5&,&6q&9&B&G&W<.WYZ[[[y3444)))HMM*FJJJ9/000!""wi//HMM*I1MMM9/000""HMM*NPQRRR9/000""'AFKN(C(CDDI KKA77MMHMM*BAFFF9/000 i)) 	Uv Q$]16%:%:;;		y9iPPPP	8,, 	U!I)W-- U6 U (qv)>)> ? ?II"9#=)TTTT)X.. 	1y,//	14=4I4I4K4K	1 H::9aHHH9/000 (66mW-- 	Yv U -af 5 5y9mTTTTx00 	Y).M-11 Y6 Y$,]16-B-B$C$CMM"9#=-XXXX-''r   c                   	 | j                             d          }n*# t          $ r | j                             d          }Y nw xY wt          |          }g }|j        |j        |j        fD ]w}|rR|                     |          }| j                             |||t          j
                   |                    |           V|                    t                                 x| j                             d|          S )Nztyping_extensions.SupportsIndexrJ  zbuiltins.slice)r  rP  rd  r   r  r   r!  ru  rB  r   INVALID_SLICE_INDEXr  r   rr  )r#  r)  supports_indexexpected	type_argsro  r   s          r   visit_slice_exprz"ExpressionChecker.visit_slice_exprt  s
   	A!X001RSSNN 	A 	A 	A!X00@@NNN	A%n55	mQ[!(; 	- 	-E -KK&&&&q(E;K;_```  ####  ,,,,x**+;YGGGs    $AArX   c                :    |                      |j        dd          S )Nre  z<list-comprehension> check_generator_or_comprehension	generatorrL  s     r   visit_list_comprehensionz*ExpressionChecker.visit_list_comprehension  s$    44K*@
 
 	
r   rh   c                :    |                      |j        dd          S )Nr   z<set-comprehension>r,  rL  s     r   visit_set_comprehensionz)ExpressionChecker.visit_set_comprehension  s$    44K)>
 
 	
r   rT   c                l   t          |j                  sXt          |j                  sDt          d |j        dd          D                       st          d |j        D                       rd}t                      g}nd}t                      t                      g}|                     ||d|          S )Nc              3  4   K   | ]}t          |          V  d S r   r   )r   sequences     r   r   z9ExpressionChecker.visit_generator_expr.<locals>.<genexpr>  s+      RRh'11RRRRRRr   r  c              3  >   K   | ]}|D ]}t          |          V  d S r   r4  )r   condlistconds      r   r   z9ExpressionChecker.visit_generator_expr.<locals>.<genexpr>  s9      __(V^__d'--_______r   ztyping.AsyncGeneratortyping.Generatorz<generator>)additional_args)r  is_asyncr   r  	sequences	condlistsr   r-  )r#  r)  r  r:  s       r   visit_generator_exprz&ExpressionChecker.visit_generator_expr  s     
OO	7#AK00	7 RR!+abb/RRRRR	7 __ak_____		7 *C+3::,OO$C'zz8::6O44sM? 5 
 
 	
r   genr  id_for_messagesr:  list[Type] | Nonec                V   |pg }| j         j                            dd          5  |                     |           t	          ddt          dd          g |                                 t          t          j	                            }|g}t          |t          j        gd	g| j                             |||z             | j                             d
          ||g          }|                     ||j        gt          j        g|          d         cd	d	d	           S # 1 swxY w Y   d	S )z:Type check a generator expression or a list comprehension.Tr   r  r  r4  z<genexp>r  r  NrM  r  )r  r  r  check_for_compr   r   rU  r   r   r  r   r   r8   rr  rP  r  r  )r#  r?  r  r@  r:  ri  tv_listr  s           r   r-  z2ExpressionChecker.check_generator_or_comprehension  s    */RX_**Dq*II 	Z 	Z$$$ R:666 ,,..	 ?@@  B $&$G&++Iw7PQQ##$788$$  K ??;%-RUVVWXY/	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Zs   C+DD"%D"rN   c                    | j         j                            dd          5  |                     |           t	          ddt          dd          g |                                 t          t          j	                            }t	          d	d	t          d
d          g |                                 t          t          j	                            }t          ||gt          j        t          j        gddg| j                             d||g          | j                             d          d||g          }|                     ||j        |j        gt          j        t          j        g|          d         cddd           S # 1 swxY w Y   dS )z&Type check a dictionary comprehension.Tr   r  r  r4  r  r  r  r  r  Nri  rM  z<dictionary-comprehension>r  )r  r  r  rC  r   r   rU  r   r   r  r   r   r8   rr  rP  r  r  r  )r#  r)  ktdefvtdefr  s        r   visit_dictionary_comprehensionz0ExpressionChecker.visit_dictionary_comprehension  s   X_**Dq*II  	  	"""  R8444 ,,..	 ?@@  E  R8444 ,,..	 ?@@  E '.t++OeU^LL##$7881 %.  K ??aeQW-u}/Mq = 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	s   EFF
F'GeneratorExpr | DictionaryComprehensionc                &   t          |j        |j        |j        |j                  D ]h\  }}}}|r| j                            |          \  }}nx| j                            |          \  }}t          t          |          t                    r9t          |t                    r$|j        dk    rt          t          j                  }| j                            ||d|           |D ]}|                     |           | j                            |          \  }	}
|	r| j                            |	           t(          j        | j        j        j        v r;|	| j                            d|           |
| j                            d|           jdS )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.
        r0  TNF)r  indicesr<  r=  r;  r   analyze_async_iterable_item_typeanalyze_iterable_item_typer   r   r   r^   r=  r   r   r6  analyze_index_variablesru  r  push_type_mapr  r  r  r  r  $redundant_condition_in_comprehension)r#  r)  ro  r5  
conditionsr;  r0  sequence_type	conditiontrue_map	false_maps              r   rC  z ExpressionChecker.check_for_comp  s    69Iq{AK6
 6
 	W 	W1E8Z  
D#'8#L#LX#V#V ==#'8#F#Fx#P#P =}==OOD"5(33D 
c)) %,I,B$C$CMH,,UM4KKK' W W	I&&& '+h&D&DY&O&O#) 5H**8444'48+;+OOO'EEeYWWWW"*EEdIVVVW!	W 	Wr   rJ   c                   |                      |j                   | j        d         }| j                            |j                  \  }}t
          j        | j        j        j        v rE|!| j	        
                    d|j                   n"| | j	        
                    d|j                   |                     ||j        ||          }t          t          |                    p|}|                     ||j        ||          }t           j                            || j        j                  sQ|}	t          t          |	                    p|	}
|t'          |
|          s|                     ||j        |
|          }n'||k    r|}	n|                     ||j        ||          }	t)          |          rt)          |	          s|}	t+          ||	g          }t-          |          rxt/          t          | j        d                   t0                    sKt3          j        ||	          }t          |          }t/          |t6                    r|j        j        dk    r|}|S )Nr4  FT)rW  ro  rc  )ru  r8  r  r  r  r  r  r  r  r  redundant_condition_in_ifr  if_exprr   r   	else_exprr  r  rq  r   r   r   r5  r   r   r   r  r   r:  rA  )r#  r)  ro  rJ  if_mapelse_mapif_typeif_type_fallbackfull_context_else_type	else_typeelse_type_fallbackr  alternativep_alts                 r   visit_conditional_exprz(ExpressionChecker.visit_conditional_expr  s   AF#  899!&AA48#3#GGG~225!&AAAA!224@@@**AIs>O + 
 
 /w/G/GHHSG "&!9!9ak3BS ": "
 "
 |227DH<LMM $	.I "5_Y5O5O!P!P!]T] {-0BC"H"H{ 22I.&7	 3   $$ /II 00("3	 1  I   677 	/@TU^@_@_ 	/.I)7I*>??$S)) 	"*D-b122I3
 3
 	" /'9==K#K00EeX.. "%*2EIZ2Z2Z!
r   r  dict[Expression, Type] | Nonesuppress_unreachable_errorsc                   | j         j                            dd          5  |e| j                            |          5  |                     |||           d d d            n# 1 swxY w Y   t                      cd d d            S | j                             |           |                     |||          cd d d            S # 1 swxY w Y   d S )NTr   r  )rS  rW  )r  r  r  r  rS  ru  r   rO  )r#  r  r.  rW  ro  re  s         r   r  z%ExpressionChecker.analyze_cond_branch^  s    X_**Dq*II 		` 		`{ X++:U+VV a aKK7N_K```a a a a a a a a a a a a a a a&((		` 		` 		` 		` 		` 		` 		` 		` H""3''';;t'M^;__		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		`s;   C A%C%A)	)C,A)	-C
1CCCtyc                    g }|&t          |          r|S |                    |           | j        r-| j        d          |                    | j        d                    |rt          |          S d S rB  )r  r  r  r   )r#  rg  	ctx_itemss      r   r  z#ExpressionChecker._combined_contextq  s    	>B  	R    	4!22!6!BT.r2333 	4(333tr   r  r  c                P	   || j         v r| j         |         S d}| j        r#| j        st          j                    }d| _        d}| j                            |           | j        }|| _        	 t          |          }	|r.t          |t                    r|                     |d          }
n|r.t          |t                    r|                     |d          }
nR|r.t          |t                    r|                     |d          }
n"|r.t          |t                     r|                     |d          }
nt          |	t$                    rB|	j        r;|                     |          x}$t%          j        ||j        |j        d          }
nt          |	t0                    rt3          fd|	j        D                       rf|                     |          x}Ot%          j        ||j        |j        d          }t7          ||	          r|}
n|                    |           }|}
n t          |t          t:          t<          t>          t@          f          r| j!        s| j"        j#        s| j"        j$        j%        s||f| j&        v rv| j&        ||f         \  }}
}}|| j"        j'        j(        k    r5| j"        )                    |           | j*        +                    |           nE| ,                    ||          }
n-| ,                    ||          }
n|                    |           }
nR# tZ          $ rE}t]          || j"        j/        j0        |j        | j"        j/        | j"        j$                   Y d}~nd}~ww xY w|| _        | j        1                                 |
J | j"        2                    ||
           | j"        j$        j3        r]|s[| j"        j4        sO| j"        5                                r6tm          |
          r'| j"        j#        s| j*        7                    |
|           | j"        5                                r| j"        j#        rtq          tr          j:                  }n|
}|r5| j;        |j        xx         t          j                    |z
  z  cc<   d| _        |S )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.
        FTrq  NrO  c              3  n   K   | ]/}t          t          |          xt                    oj        V  0d S r   )r   r   r   rP  )r   r  p_items     r   r   z+ExpressionChecker.accept.<locals>.<genexpr>  sV         )>)>>vIIafNa     r   r  )<r  r  r  timeperf_counter_nsr  r  r  r   r   rF   rv  r}   visit_yield_from_exprrJ   rc  rD   visit_await_exprr   rP  try_parse_as_type_expressionr  rC  rD  r   r  r   r   ru  rY   rq   rM   ra   r   r  r  r  disable_expression_cacher  r  versionr  r  r  accept_maybe_cache	Exceptionr&   r  filer  r  disallow_any_expris_stubr;  r  disallowed_any_typer   r   rN  r  )r#  r.  r  ro  r  r  record_timet0old_is_calleep_type_contextr  node_as_typetyp1typ2binder_versionmessagestype_mapr  r/  rl  s                      @r   ru  zExpressionChecker.accept  s$    4&&&&t,,+ 	D4F 	%''B!%DK  ..."B	,\::N  <(Zh%?%? <(**44*HH" :(z$'F'F :(000NN" 8(z$'H'H 8(11$$1OO" 6(z$	'B'B 6(++DD+II >8443("/3( &*%F%Ft%L%LL\Y. %*'.!%	   >955((     . 4    (( &*%F%Ft%L%LL\Y/ %*'.!%	   dN33 CC;;t,,DCC 4(Hi6!RSS(,(040N( (A(
 ,'4?::>BotUaNb>c;NC8%)@@@,,X666++H5555"55d5VV11$\1RRCCkk$'' 	 	 	!TX_)49dhotxGW       	 'D#&&& H.	4$	4 H$	4 ,,..		4
 S!!	4 H2	4 H((d333x++-- 	1O 	"9#899FFF 	'*495559M9O9ORT9TT555!&Ds   -KL/ /
M>9;M99M>c                   | j         j        j        }| j                            dd          5 }| j         j        5 }|                    |           }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                                }|| j         j        j        k    r| j         j        s||||f| j	        ||f<   | j         
                    |           | j                            |           |S )NT)rS  r|  )r  r  rs  r  rS  rR  ru  r  r  r  r  r  )r#  r.  r  r  r  r  r  r  s           r   rt  z$ExpressionChecker.accept_maybe_cache  se   0X##$T#RR 	(VY( (Hkk$''( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( &&((TX_444TX=[45CS(T\4]DOT<01X&&&H%%%
s4   A4AA4A!	!A4$A!	%A44A8;A8r=  c                6    | j                             |          S )z}Return an instance type with type given by the name and no type
        arguments. Alias for TypeChecker.named_type.
        )r  rP  )r#  r=  s     r   rP  zExpressionChecker.named_type  s     x""4(((r   c                    | j         j        j        dk    r|                     d          S |                     d          S )zFReturns a `typing.TypeAliasType` or `typing_extensions.TypeAliasType`.)r     ztyping.TypeAliasTypeztyping_extensions.TypeAliasType)r  r  r  rP  r'  s    r   rm  z&ExpressionChecker.type_alias_type_type  s;    8*g55??#9:::@AAAr   c           	         t          |          }t          |t          t          t          t
          f          p@t          || j                            dt          t          j
                  g                    S )z$Is a type valid as a *args argument?r\  )r   r   r   r   r   r   r   r  rr  r   r6  r  s     r   r  z"ExpressionChecker.is_valid_var_arg  sd    c""#	7M:NOO 
S],,->I_A`A`@abbT
 T
 	
r   c           
     \   t          || j                            d|                     d          t	          t
          j                  g                    pWt          || j                            dt                      t                      g                    pt          |t                    S )z'Is a type valid as a **kwargs argument?r  r=  )
r   r  rr  rP  r   r   r6  r   r   r   r  s     r   r  z*ExpressionChecker.is_valid_keyword_var_arg  s     ++6__^44gi>T6U6UV   . ++69J9JOL]L]8^  . #}--	
r   c                <    | j                             ||           dS )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)r  r<  )r#  r=  rW  s      r   not_ready_callbackz$ExpressionChecker.not_ready_callback(  s"     	--dG<<<<<r   r|   c                   | j         j        d         }| j                             |d          }|j        ht	          t          |          t          t          f          s>| j                                         r%| j         	                    t          j        |           nD|                     |j        |          }| j                             |||t          j        dd           | j                             |d          S )Nr4  Factual typeexpected type)r  r  get_generator_yield_typer  r   r   r   r   r;  r  r   YIELD_VALUE_EXPECTEDru  rB  INCOMPATIBLE_TYPES_IN_YIELDget_generator_receive_type)r#  r)  return_typeexpected_item_typeactual_item_types        r   visit_yield_exprz"ExpressionChecker.visit_yield_expr0  s    h+B/!X>>{ERR6>/ABBXwDWXXHH0022H .CQGGG#{{163EFFH"" " <   x22;FFFr   rD   c                   | j         d         }|| j                            d|g          }t          |                     |j        |                    }t          |t                    rt          t          j	        |          S | 
                    ||t          j                  }|sBt          t          |          t                    r | j        j                            d |           |S )Nr4  typing.Awaitabler  )r  r  rr  r   ru  r  r   r   r   r  check_awaitable_exprr   INCOMPATIBLE_TYPES_IN_AWAITr   r  r  )r#  r)  ro  expected_typer  rs  s         r   rp  z"ExpressionChecker.visit_await_exprE  s    )"-$ H778J]O\\M%dkk!&-&H&HIIk7++ 	O95+NNNN'',H
 
 ! 	8Z0D0Dh%O%O 	8HL..tQ777
r   str | ErrorMessageignore_binderc                   | j                             ||                     d          ||dd          st          t          j                  S |                     d|g g |          d         }| j                             |d          }t          |          }|s:t          |t                    r%|j        s| j         j                                         |S )zyCheck the argument to `await` and extract the type of value.

        Also used by `async for` and `async with`.
        r  r  r  	__await__r   F)r  rB  rP  r   r   r6  r  get_generator_return_typer   r   r   r  r  r  )r#  r   rJ  r  r  r.  rB  s          r   r  z&ExpressionChecker.check_awaitable_exprS  s     x%%t122Cm_
 
 	 9122266{Ar2sSSTUVIx99)UKKH&x00H!.x99. !*.
 ++---Or   r}   c                   | j         j        d         }t          |                     |j                            }t          |t                    rt          t          j        |          }n;| j         	                    |          rt          |          r/t          |          s | j         j                            ||           t          t          j                  }| j                             d|||g          }|                    |           |                     d|g g |          \  }}nyt          |          rt          |          s:| j         j                            ||           t          t          j                  }n!|                     ||t(          j                  }| j                             |d          }	| j                             |d          }
| j                             |
|	|t(          j        dd           t          |          }| j                             |d	          }|sBt          t          |          t2                    r | j         j                            d |           |S )
Nr4  r  r9  __iter__r?  Fr  r  )is_coroutine)r  r  r   ru  r  r   r   r   r  rj  is_async_defhas_coroutine_decoratorr  yield_from_invalid_operand_typer6  rr  r   r  r>  r  r    INCOMPATIBLE_TYPES_IN_YIELD_FROMr  rB  r  r   r  )r#  r)  ro  r  subexpr_type	iter_typer  generic_generator_typer0  r  r  	expr_types               r   ro  z'ExpressionChecker.visit_yield_from_exprj  s^    h+B/
 't{{16':':;; lG,, 	%i&@\ZZZIIX&&|44 	L)) N2I+2V2V N<<\1MMMy566H%)X%@%@"Xx$B& &" #++A...99L"b:P :  LIqq !.. 3J;3W3W <<\1MMM#I$899		 55 !%5%V 	 "X>>{ERR8<<YNN=	
 	
 	
 $I..	H66yu6UU	  	8Z	0J0JH%U%U 	8HL..tQ777r   rp   c                    |j         S r   r:  rL  s     r   visit_temp_nodez!ExpressionChecker.visit_temp_node  	    vr   rw   c                   t          |j                  t          t                    rj        t
          j        k    srt          |j                  s| j	        
                    d|           |j        r;t          fd|j        D                       s| j	        
                    d|           t          t
          j                  S )Nz3TypeVar default must be a subtype of the bound typec              3  8   K   | ]}t          |          V  d S r   r   )r   r  	p_defaults     r   r   z8ExpressionChecker.visit_type_var_expr.<locals>.<genexpr>  s-      #Y#YuLE$B$B#Y#Y#Y#Y#Y#Yr   z3TypeVar default must be one of the constraint types)r   r  r   r   type_of_anyr   r  r   r  r  r  r  r  r6  )r#  r)  r  s     @r   visit_type_var_exprz%ExpressionChecker.visit_type_var_expr  s    #AI..	y'**	X%)HHHi77 XSUVWWWx X#Y#Y#Y#YPQPX#Y#Y#Y Y Y XSUVWWWy-...r   rc   c                4    t          t          j                  S r   r   r   r6  rL  s     r   visit_paramspec_exprz&ExpressionChecker.visit_paramspec_expr      y-...r   ry   c                4    t          t          j                  S r   r  rL  s     r   visit_type_var_tuple_exprz+ExpressionChecker.visit_type_var_tuple_expr  r  r   r_   c                4    t          t          j                  S r   r  rL  s     r   visit_newtype_exprz$ExpressionChecker.visit_newtype_expr  r  r   r]   c                "   |j         j        }|ri| j        j        j        r+t          |          r| j                            d||           t          || j        j        | j        j	        | j        |           t          t          j                  S )NzNamedTuple typer?  )r  
tuple_typer  r  rH  r   r  rI  r   rJ  r   r   r6  )r#  r)  r  s      r   visit_namedtuple_exprz'ExpressionChecker.visit_namedtuple_expr  s    V&
 	x7 W<X= = W 445F
TUVVV"DH,dh.G[\    y-...r   rP   c                Z   t          |j        |j                  D ]x\  }}|q|                     |          }t	          t          |          t                    s:|j        j        |         j	        }t	          |t                    r||_        d|_        yt          t          j                  S NT)r  r   r  ru  r   r   r   r  rg  r.  r{   r:  r  r   r6  )r#  r)  r=  r  r  r9  s         r   visit_enum_call_exprz&ExpressionChecker.visit_enum_call_expr  s    qw11 	/ 	/KD% kk%((!/#"6"6@@ /&,t,1C!#s++ /
 $'*.y-...r   rt   c                4    t          t          j                  S r   r  rL  s     r   visit_typeddict_exprz&ExpressionChecker.visit_typeddict_expr  r  r   re   c                    |j         S r   r  rL  s     r   visit__promote_exprz%ExpressionChecker.visit__promote_expr  r  r   rk   c                6    |                      |j                  S r   )ru  r  rL  s     r   visit_star_exprz!ExpressionChecker.visit_star_expr  s    {{16"""r   c                ,    |                      d          S )zReturn instance type 'object'.rc  rT  r'  s    r   rU  zExpressionChecker.object_type  s    0111r   c                ,    |                      d          S )zReturn instance type 'bool'.r\  rT  r'  s    r   r  zExpressionChecker.bool_type  s    ///r   
known_typec                    d S r   r   )r#  r  r  s      r   r,  z)ExpressionChecker.narrow_type_from_binder  s    SVSVr   r  c                    d S r   r   )r#  r  r  r  s       r   r,  z)ExpressionChecker.narrow_type_from_binder  s	     cr   c                l   t          |          t          k    r| j        j                            |          }|rzt          t          |          t                    r| j        j        sL|rt          ||d          sdS t          ||          }t          t          |          t                    r|S |S |S )zNarrow down a known type of expression using information in conditional type binder.

        If 'skip_non_overlapping' is True, return None if the type and restriction are
        non-overlapping.
        T)prohibit_none_typevar_overlapN)r0   r=   r  r  r  r   r   r   r  r2   r3   r   )r#  r  r  r  restrictionr0  s         r   r,  z)ExpressionChecker.narrow_type_from_binder  s     4==L(((/--d33K   ?:66@@ EIXEc  (  0D41 1 1    4/
KHHoh77II ' '&r   c                     t          |t                    rHt          |t                    r3t           fdt          |j        |j                  D                       S                      ||          S )Nc              3  ~   K   | ]7\  }}                     t          |          t          |                    V  8d S r   )has_abstract_typer   )r   callerr  r#  s      r   r   z;ExpressionChecker.has_abstract_type_part.<locals>.<genexpr>  s\        "FF &&v'>'>PV@W@WXX     r   )r   r   r  r  r   r  r#  r  r  s   `  r   r  z(ExpressionChecker.has_abstract_type_part  s    k9-- 	*[)2T2T 	    &)+*;[=N&O&O      %%k;???r   c                t   t          |t                    ot          |t                    o|                                oz|                                j        p|                                j        oHt          |j        t                    o.|j        j	        j        p|j        j	        j        o| j
        j         S r   )r   r   r   r  r  r  r  r  r   r:  r  allow_abstract_callr  s      r   r  z#ExpressionChecker.has_abstract_type  s    {L11 1;111''))1 ((**6_+:Q:Q:S:S:_1 ;+X66	1
 !&2Wk6F6K6W1 H00	
r   maybe_type_exprc                  	 t          |t                    sdS t          |t          t          t          f          r|j        t          j        k    r|j        S t          |          r)| j	        
                    d|t          j                   dS t          |          \  }}d |D             	fd|D             z  }t          j                            | j	        |          }t#          |t%                      | j        | j	        j        | j	        j        | j	        j                  }	 t/          || j	        j        | j	        j                  }|                    |          }|j        rdS |S # t4          $ r Y dS w xY w)a  Try to parse a value Expression as a type expression.
        If success then return the type that it spells.
        If fails then return None.

        A value expression that is parsable as a type expression may be used
        where a TypeForm is expected to represent the spelled type.

        Unlike SemanticAnalyzer.try_parse_as_type_expression()
        (used in the earlier SemanticAnalyzer pass), this function can only
        recognize type expressions which contain no string annotations.NzlTypeForm containing a string annotation cannot be recognized here. Surround with TypeForm(...) to recognize.r  c                N    i | ]"}|j         t          t          |j                  #S r   )r=  ro   r@   r.  r  s     r   rF  zBExpressionChecker.try_parse_as_type_expression.<locals>.<dictcomp>L  s)    ^^^a0@!& I I^^^r   c                h    i | ].}t          |          xt          t          |j                  /S r   )r~   ro   r@   r.  )r   r)  e_names     r   rF  zBExpressionChecker.try_parse_as_type_expression.<locals>.<dictcomp>L  sH     b
 b
 b
21555B O$4af==BBBr   )r   rZ   rl   rU   ra   as_typer`   VALUEr   r  r  r  MAYBE_UNRECOGNIZED_STR_TYPEFORMr   r  r  TypeCheckerAsSemanticAnalyzerr   r   r  r  treerJ  r,   ru  did_failr+   )
r#  r  
name_exprsmember_exprssym_for_namechk_semtpanr  r  r  s
            @r   rq  z.ExpressionChecker.try_parse_as_type_expression%  s    /+>?? 	4 )V(DEE	+'9?::"**
 o.. 	HMM<:	     4
 &E_%U%U"\^^S]^^^ b
 b
 b
 b
!b
 b
 b
 
 ,<<TX|TT KHHMH%
 
		*!1483L D ;;t$$D tK# 	 	 	44	s   %AE* (E* *
E87E8)
r  r  r  r5   r  r   r  r  r   r  r   r  )r)  r^   r   r   F)r)  rf   r2  r   r   r   )r.  rn   rJ  rK   rK  r   rH  r   rI  r   r   r   )r9  r{   rW  rK   r   r   )r.  r\   r   r   )r)  rF   ro  r   r   r   )rw  rQ   r   r   )r)  rF   r   r  )rU  r   r  r  r   r  r.  rQ   r   r   )r  r  r   r   )r  r   r  r  r  r  r  r  rW  rK   r  r  r   r   )r  r  r  r   r   r  )
r
  rQ   r  r   r/  r  r  r  r   r   r  r   r   r   )r  r   r  r.  rW  rK   r   r   )
r  r   r  r.  rW  rK   r  r  r   r   )r  rv   r   r   r   )r  r   r7  r8  r   r   )r  r   r  r  rW  rK   r  r  r  r  r   r   )r  r[   r   r^  )rx  rf   r   ry  )r)  rF   r|  r  r9  r{   r   r}  )r  r   r  r  r  r  r  r  r  r  r  r  rA  r  rU  r  rW  rK   r   r   )r  r   r  r  r  r  r  r  r  r  r   r   )r  r   r  r  r  r  rW  rK   r  r  r  r  r   r   )r  r   r  r  r  r  rW  rK   r  r  rU  r   r  r  r   r   r  )r  r  r  r   r  r  r  r  rW  rK   r  r  rU  r  r   r   )r  r   r  r  r   r  )r  r   r  r   rJ  rK   r   r  )r  r   r)  rF   r  r  rU  r  r  r  r   r   )r)  rF   rU  r   r  r  r   r   )NNNNN)r  r   r  r  r  r  rW  rK   r  r  r  r  r  r  rU  r  r  r  r   r  )r  r   r  r  r  r  rW  rK   r  r  r  r  r  r  rU  r  r   r  )r:  rv   r  r  r   r   )r  r   rW  rK   r   r   )r  r  r   r  )r  r   r   r   )
r  r   r  r  r  r  r  r  r   r  )r-  r   r.  rK   r   r   )r  r   r  r  r  r  r  r  r  r  r  r   rW  rK   r   r   )r  r   r  r  r  r  r  r  r  r  rV  rW  r  r   rW  rK   r   rX  )r   r-   )r  r   r  r  r  r  r  r  r]  r^  r   r_  )r  r   r  rW  rW  rK   r   r   )r  r   rj  r  rk  r  rl  r  r  r  rW  rm  rU  r  r  r  r   r   )r  r   rj  r  rk  r  rl  r  r~  r  rW  rK   r   r  )rU  r   r  r  rW  rK   r   r  )r  r  r  r  r  r  r  r   r  r  rW  rK   r  r  rU  r  r   r  )r  r   r  r   r  rA   r  r   rn  r^  r  r^  r  r   rU  r  rW  rK   r  rK   r   r  )r  r   r  r  r  r  r  r  r  r  rU  r  rW  rK   r   r  )
r  r  r  r  r  r  r   r   r   r  )r  r  r  r  r  r  r  r  r  r  r  r  rU  r  rW  rK   r   r  )r  r  r  r  r  r  r  r  r  r  rW  rK   r   r  )r  r  r  r  r   r   rG  )r  r  r  r  r  r  r  r  r  r  r  r  rU  r  r  r   rW  rK   r  r^  r   r  r  )r  r  r  r  r   r  )r   r  r   r  )r  r  r  r  r  r  r  r  r  r   rW  rK   r   r   )
r-  r   r   rW  rW  rK   r4  r   r   r   )r  r  r  r   r   r  )r  r   r  r  r  r  r  r  rW  rK   r   r  )r)  r[   rK  r   r   r   )r)  r[   rK  r   rK  r  r   r   )r  r  r>  r   rW  rK   r   r   )r   r   )r  r   rC  r  r   r   )rE  r   rF  r   r   r   )r)  rV   r   r   )r)  rl   r   r   )r)  rE   r   r   )r)  rR   r   r   )r)  rI   r   r   )r)  rO   r   r   )r)  ra   r   r   )r)  rH   r   r   )r  rQ   r   r  )rE  r   rF  r   r~  r  r  r  r  r   r  r   r   r   )rw  r  r>  r   r  r  r  r  rW  rK   r  r  r  r  r   r  )rw  r  r>  r   r  r  r  r  rW  rK   r  r  r   r  )r  r  r>  r   ro  r   r  r  r  r  rW  rK   r   r  )r  r  rq  r   r  rQ   r  r   r  rQ   rW  rK   r   r  )rw  r  r>  r   r$  rQ   rW  rK   rc  r   r   r  )r)  rC   r   r   )r)  rz   r   r   )r)  rU   r   r   )
rq  r   r)  rU   r  r  r  r  r   r   )rE  r   r   r^  )rE  r   rn  r^  r   r  )rq  r   r  rj   r   r   )ro  rQ   r   r-  )rq  r   ro  rQ   r   r   )rq  r   r   r   )r6  r   ro  rQ   r7  r   r   r8  )r@  rv   ro  rQ   rW  rK   r   r   )r  rG   r   r   )r  ru   r   r   )r  rB   r   r   )r  rg   r   r   )r  rg   r   r  )rj  rs   r   r   )rq  rr   r   r   )rq  r   rJ  rK   rO  r   r   r   )r   r   r  r  rJ  rK   r   r  )r  r   r  r  rJ  rK   r   r   )r)  rY   r   r   )r)  ri   r   r   )r)  r  r  r  r   r  )r   r  r   r  )r)  r  rA  r  r  r  r   r   )r  rq   rJ  r   r   r   )r)  rq   r   r   )r)  rM   r   r  )r)  rM   r  r   r   r   )r)  rM   r   r   )rW  r  r  rM   r   r  )r)  rW   r   r   )r)  rW   r   r  )r)  rm   r   r   )r)  rm   r   r  )r)  rj   r   r   )r)  rX   r   r   )r)  rh   r   r   )r)  rT   r   r   )
r?  rT   r  r  r@  r  r:  rA  r   r   )r)  rN   r   r   )r)  rI  r   r  )r)  rJ   ro  r   r   r   )FT)r  rd  r.  rQ   rW  r  ro  r   re  r   r   r   )rg  r  r   r  )NFFF)r.  rQ   r  r  ro  r   r  r   r  r   r   r   )r.  rQ   r  r  r   r   )r=  r  r   r   )r   r   )r=  r  rW  rK   r   r  )r)  r|   r   r   )r)  rD   ro  r   r   r   )
r   r   rJ  rK   r  r  r  r   r   r   )r)  r}   ro  r   r   r   )r)  rp   r   r   )r)  rw   r   r   )r)  rc   r   r   )r)  ry   r   r   )r)  r_   r   r   )r)  r]   r   r   )r)  rP   r   r   )r)  rt   r   r   )r)  re   r   r   )r)  rk   r   r   )r  rQ   r  r   r   r   )r  rQ   r  r   r  r   r   r  )r  r   r  r   r   r   )r  rQ   r   r  )r   r   r   r   __annotations__r$  r(  r1  r+  r?  r7  rV  rv  rz  rt  r  r  r  r  r  r  r  r  r  r  r1  r  rR  r5  r  rc  rf  rj  r  rl  rm  r  r  r  r  r  r  r  r  r  r  rS  r  r  r$  r(  r  r  r.   rJ  rI  rH  rO  r  rs  rw  r  r  r  r  r  r  r  r  r  r   r  r  r  r6  r  r  r9  r8  r@  r]  r_  rH  rM  rP  rR  rU  rW  rY  rx  r  r  r  r  r  r  r  rm  re  rf  r  r  r  r  r  r
  r  r  r  r  r2  r  r  rM  rQ  rU  r`  r[  rp  rs  rT  r  rn  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r*  r/  r1  r>  r-  rH  rC  rc  r  r  ru  rt  rP  rm  r  r  r  r  rp  r  ro  r  r  r  r  r  r  r  r  r  r  rU  r  r   r,  r  r  rq  r   r   r   r
  r
    s          "!!!#### 0///****NNN9999*4 *4 *4 *4X          + + + + +f !% %.- .- .- .- .- .-`3 3 3 3$   6	R 	R 	R 	R 	R
 
 
 
V V V V VpG G G G0   8   ,   ,	M 	M 	M 	M_ _ _ _(- (- (- (-T0+ 0+ 0+ 0+d6 6 6 6pR R R R   1 1 1 1(Q Q Q Q TX
 
 
 
 
 ] ] ] ]~   0 #	*1 1I    
 #_$56"_$56$,.?#@!NO#DE	A AN    %P %P %P %PN	" 	" 	" 	") ) ) )VG G G GR% % % %@
 
 
 
$
 
 
 
> 26#'' ' ' ' 'R   &= = = =H "0 0 0 0 0d* * * *D 26+/$(#'%)xY xY xY xY xYts' s' s' s'j   0,- ,- ,- ,-\        #% #% #% #%JS
 S
 S
 S
jIR IR IR IRV;* ;* ;* ;*z- - - -- - - -^Q Q Q Q8 $($(N N N N N`;+ ;+ ;+ ;+z   , (,#'K K K K KZ+ + + +ZM M M M^9& 9& 9& 9&vR6 R6 R6 R6h   *$ $ $ $b d d d d dLL L L L . . . ^.P
 P
 P
 P
d3 3 3 3t "'
 
 
 
 
 	T 	T 	T 	TL L L L      KO( ( ( ( (T
 
 
 
&; ; ; ;!^ !^ !^ !^F
 
 
 
E E E EE E E EG G G G1 1 1 13 3 3 34 4 4 4k; k; k; k;ZS S S Sj   * +/48#$AN AN AN AN AN ANT &*!%%` %` %` %` %`\ &*K K K K K8
 
 
 
<n n n nl $m m m m m^IM IM IM IMV    	 	 	 	       8 8 8 8 ,0!%V V V V Vp! ! ! !.
 .
 .
 .
`, , , ,@$ $ $ $L   , , , ,( JO#B #B #B #B #BJ' ' ' '   .b b b b   4   >D D D D.)/ )/ )/ )/V` ` ` ` KPC: C: C: C: C: C:J6W 6W 6W 6WpJ/ J/ J/ J/XA A A A? ? ? ?1 1 1 1f	 	 	 	!6 !6 !6 !6FY Y Y Yg g g gRH H H HT	1 	1 	1 	1QU QU QU QUf   4&I &I &I &IPKO KO KO KOZQ$ Q$ Q$ Q$fP( P( P( P(dH H H H 
 
 
 


 
 
 


 
 
 
2 .2 Z  Z  Z  Z  ZD" " " "H#W #W #W #WJO O O O Ol #(,0` ` ` ` `&   * %)"'!&q q q q qf
 
 
 
 
) ) ) )B B B B
 
 
 

 
 
 
&= = = =G G G G*     UZ    .: : : : :x   
/ 
/ 
/ 
// / / // / / // / / /
/ 
/ 
/ 
// / / // / / /   # # # #2 2 2 20 0 0 0 VVV XV   X
 PU    <@ @ @ @	
 	
 	
 	
E E E E E Er   r
  Fignore_in_type_objc                F    |                      t          |                    S )zWhether t contains an Any type)ru  
HasAnyType)r   r  s     r   r  r  m  s    88J122333r   c                  L     e Zd Zd fdZddZd fd
ZddZddZddZ xZ	S )r  r  r   r   r  c                l    t                                          t          j                   || _        d S r   )superr$  r   ANY_STRATEGYr  )r#  r  	__class__s     r   r$  zHasAnyType.__init__s  s,    +,,,"4r   r   r   c                ,    |j         t          j        k    S r   )r  r   r6  r#  r   s     r   	visit_anyzHasAnyType.visit_anyw  s    }	 666r   r   c                    | j         r|                                rdS t                                          |          S )NF)r  r  r  visit_callable_type)r#  r   r  s     r   r  zHasAnyType.visit_callable_typez  s:    " 	q}} 	5ww**1---r   r   c                    |                                 r|j        gng }|                     |j        g||j        z             S r   )r  r  query_typesr  r  r#  r   r  s      r   visit_type_varzHasAnyType.visit_type_var  sA    !"819++b 9 9AH DEEEr   r   c                    |                                 r|j        gng }|                     |j        g||j                  S r   )r  r  r  r  r  r  s      r   visit_param_speczHasAnyType.visit_param_spec  sA    !"819++b C C!( CDDDr   r   c                x    |                                 r|j        gng }|                     |j        g|          S r   )r  r  r  r  r  s      r   visit_type_var_tuplezHasAnyType.visit_type_var_tuple  s:    !"819++b 9 9:::r   )r  r   r   r  )r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )
r   r   r   r$  r  r  r  r   r  __classcell__r  s   @r   r  r  r  s        5 5 5 5 5 57 7 7 7. . . . . .
F F F FE E E E; ; ; ; ; ; ; ;r   r  c                j    t          |           } t          | t                    o| j        j        dk    S )z;Whether t came from a function decorated with `@coroutine`.typing.AwaitableGenerator)r   r   r   r:  rA  r   s    r   r  r    s.    Aa""Uqv:U'UUr   c                   t          |           } t          | t                    rB| j        j        dk    r2t          | j                  dk    rt          | j        d                   } t          | t                    o| j        j        dk    S )z9Whether t came from a function defined using `async def`.r     r  ztyping.Coroutine)r   r   r   r:  rA  r  r  r   s    r   r  r    sx     	A1h'FO:::KK1AF1I&&a""Lqv:L'LLr   c                r    t          |           } t          | t                    ot          | j                  S r   )r   r   r   r   r   r   s    r   r  r    s,    Aa##5QW5r   mappingr_  rj  r  rk  r  c                    t          |           dk    oht          |           dk    o7| d                  t          j        k    o| d                  t          j        k     ot	          fd| D                        S )Nr  r  r   c              3     K   | ]C}|         t           j        k    o(t          t          |                   t                     V  Dd S r   )r   r:   r   r   r   )r   r  rk  rj  s     r   r   z'is_duplicate_mapping.<locals>.<genexpr>  sf       
 
  Ou. P|A??OOO
 
 
 
 
 
r   )r  r   r9   r:   r   )r  rj  rk  s    ``r   ry  ry    s     	Gq 	
 LLA <WQZ(EN:<WQZ(EO;
	
  
 
 
 
 
 
 
 
 
 
 
r   r  r   r  c                .    |                      |          S )z>Return a copy of a callable type with a different return type.r  r  )r  r  s     r   r  r    s    ??L?111r   c                  ,     e Zd ZdZd	 fdZd
dZ xZS )ra  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.
    r   r  c                ^    t                                          t          j                   d S r   r  r$  r   r  r#  r  s    r   r$  z ArgInferSecondPassQuery.__init__  $    +,,,,,r   r   r   r   c                T    |                      |j                  pt          |          S r   )r  r  r   r  s     r   r  z+ArgInferSecondPassQuery.visit_callable_type  s%    ,,@a0@0@@r   r  r  )r   r   r   r   r$  r  r  r  s   @r   ra  ra    sc         - - - - - -A A A A A A A Ar   ra  r  c                L    | d uo |                      t                                S r   )ru  HasErasedComponentsQueryr   s    r   r#  r#    s$    D=AQXX&>&@&@AAAr   c                  ,     e Zd ZdZd	 fdZd
dZ xZS )r  z<Visitor for querying whether a type has an erased component.r   r  c                ^    t                                          t          j                   d S r   r  r  s    r   r$  z!HasErasedComponentsQuery.__init__  r  r   r   r   r   c                    dS r  r   r  s     r   visit_erased_typez*HasErasedComponentsQuery.visit_erased_type      tr   r  )r   r   r   r   )r   r   r   r   r$  r  r  r  s   @r   r  r    sW        FF- - - - - -       r   r  c                L    | d uo |                      t                                S r   )ru  HasUninhabitedComponentsQueryr   s    r   r5  r5    s$    D=FQXX&C&E&EFFFr   c                  ,     e Zd ZdZd	 fdZd
dZ xZS )r  zEVisitor for querying whether a type has an UninhabitedType component.r   r  c                ^    t                                          t          j                   d S r   r  r  s    r   r$  z&HasUninhabitedComponentsQuery.__init__  r  r   r   r   r   c                    dS r  r   r  s     r   visit_uninhabited_typez4HasUninhabitedComponentsQuery.visit_uninhabited_type  r  r   r  )r   r   r   r   )r   r   r   r   r$  r!  r  r  s   @r   r  r    sW        OO- - - - - -       r   r  r  r  c                    t                      t                    t           t                    rt                      t          t                    rt                    d
d}t          t                    r$t           t          t
          t          f          rdS  |           r |          rdS t           t                    r-t          fd 	                                D                       S t          t                    r-t           fd	                                D                       S t           t                    r,t          t                    rdS t           j                  S t          t                    rt           t                    r j         t           t
                    r j        d	         j         t           t                    rt!                      t           t                    rj         j        j        v rdS t'          t)          j                   t)          j                            S )a  Return if caller argument (actual) is roughly compatible with signature arg (formal).

    This function is deliberately loose and will report two types are similar
    as long as their "shapes" are plausibly the same.

    This is useful when we're doing error reporting: for example, if we're trying
    to select an overload alternative and there's no exact match, we can use
    this function to help us identify which alternative the user might have
    *meant* to match.
    r  r   r   r   c                    t          | t                    pMt          | t                    o|                                 p$t          | t                    o| j        j        dk    S )Nr<  )r   r   r   r  r   r:  rA  r  s    r   is_typetype_likez4arg_approximate_similarity.<locals>.is_typetype_like  sX    sH%% T3--C#//2C2CT3))Rch.??.R	
r   Tc              3  8   K   | ]}t          |          V  d S r   r-  )r   r  r  s     r   r   z-arg_approximate_similarity.<locals>.<genexpr>  s.      ``-dF;;``````r   c              3  8   K   | ]}t          |          V  d S r   r&  )r   r  r  s     r   r   z-arg_approximate_similarity.<locals>.<genexpr>  s.      ``-fd;;``````r   r   r  )r   r   r   r   r   r   r   r   r  r  r   r-  r  r   r   r   r   r:  r  r   r   r!   )r  r  r$  s   `` r   r-  r-    sP    V$$FV$$F &+&& 1(00&+&& 1(00
 
 
 
 &,'' f|ZBCC 	4 $4$4V$<$< t &)$$ a````H]H]H_H_``````&)$$ a````H]H]H_H_`````` &-(( Cfm,, 	4)&/6BBB &(## 	fl++ 	%_Ffj)) 	.\!_-Ffi(( 	,#F++Ffh'' 	FK6;?,J,J4 i*622I4H4P4PQQQr   r   r  r  r  r  r  r  c                   t          |          rdS fd| D             }t                    D ]\  }t          |d          rfdt          |          D             }g }g }	|D ]L\  }
}| |
         }|                    |j                   |D ]"}|	                    |j        |                    #Mt          |	          st          |          s dS dS )a  May 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           
     P    g | ]"}t          |j        |j        fd           #S )c                    |          S r   r   r  s    r   r  z:any_causes_overload_ambiguity.<locals>.<listcomp>.<lambda>P  s    IVWL r   )r   r  r  )r   r  r  r  r  s     r   r  z1any_causes_overload_ambiguity.<locals>.<listcomp>N  sN         	y$.$.BXBXBXBX	
 	
  r   T)r  c                :    g | ]\  }}|         ||         fS r   r   )r   item_idxlookuparg_idxs      r   r  z1any_causes_overload_ambiguity.<locals>.<listcomp>Z  s@     + + +$Hf'?+6'?++ + +r   )r  r  r  r  rB  r  )r   r  r  r  r  actual_to_formalr  matching_formals_unfilteredmatching_returnsmatching_formalsr,  formalsmatched_callabler  r.  s     ```         @r   r  r  8  sf   & l## u      	   'y11   T::: 	+ + + +(12B(C(C+ + +'  "!%@ 	P 	P!'#(?  ''(8(ABBB & P PF$++,<,Fv,NOOOOP!"233 NK[<\<\ tt5r   r   c                R      sdS t           fd dd          D                       S )NTc              3  D   K   | ]}t          |d                    V  dS )r   Nr  )r   r   r   s     r   r   z!all_same_types.<locals>.<genexpr>u  s1      <<Q|AuQx((<<<<<<r   r  )r   )r   s   `r   r  r  r  s;     t<<<<%)<<<<<<r   r   Sequence[CallableType],tuple[list[CallableType], list[TypeVarType]]c                   g }i }g }| D ]}|                                 rt          |          }i }|j        D ]k}|j        }||vrNt	          |t
          t          f          r*t	          |t                    sJ |||<   |                    |           ||         ||j	        <   lt          ||          }|                    |           ||fS )a<  Takes all the typevars present in the callables and 'combines' the ones with the same name.

    For example, suppose we have two callables with signatures "f(x: T, y: 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.
    )r  r*   r7  rA  r   r   r   r   r  r  r'   )r   outputunique_typevarsr7  ry  renameri  r=  s           r   r  r  x  s    & "$F.0O#%I   	1/77FF& 	6 	6{..!"}6F&GHH ! %b+66666,.OD)$$R((( / 5ru 00Ff9r   r  r   c                j    t          |           } t          | t                    r| j        | j        S | S )z>If possible, get a more precise literal type for a given type.)r   r   r   r^  r  s    r   r  r    s7    
#

C#x   $S%9%E##Jr   r.  rQ   c                4   t          | t                    r*| j        }t          |t                    o|j        t
          v S t          | t                    rC| j        }t          |t                    o&t          t          |j
                  t                    S dS )z-Returns 'true' if the given node is a LiteralF)r   rU   rw  rf   rA  r   r^   r.  r   r   ry  r   )r.  rw  
underlyings      r   r  r    s    $	"" Qy$((PT]>P-PP$!! 
Y
*i00 
ZJ-..6
 6
 	
 5r   c                    t          |           } ddh}t          | t                    rt          d | j        D                       S t          | t
                    r| j        j        |v rdS dS )z?Is this one of builtin byte types, or a union that contains it?r   r   c              3  4   K   | ]}t          |          V  d S r   )r  r  s     r   r   z&has_bytes_component.<locals>.<genexpr>  s+      ==a&q))======r   TF)r   r   r   r  r   r   r:  rA  )r  
byte_typess     r   r  r    sv    
#

C"$89J#y!! >==39======#x   SX%6*%D%Dt5r   TypeInfo | Nonec                   t          |           } t          | t                    r(|                                 r|                                 S t          | t
                    r| j        } t          | t                    rt          | j                  } t          | t                    rt          |           } t          | t                    r| j        S dS )zXGets the TypeInfo for a type, indirecting through things like type variables and tuples.N)r   r   r   r  r  r   r  r   r  r   r   r   r:  r  s    r   r
  r
    s    
#

C#|$$ !):): !   #x   h#{## /co..#y!! "S!!#x   x 4r   rA  r  c                    | sdS |                      d          d         }|t          j                                        v p?|t          j                                        v p|t          j                                        v S )NFr  r4  )splitr   rl  r  rn  r  )rA  
short_names     r   r  r    sy     u$$R(Ji*11333 	=5<<>>>	=3::<<<r   PartialType | Nonec                F    | t          | t                    r| j        d S | S r   )r   r   r:  r   s    r   rp  rp    s%    y
1k22yafntHr   rW  c                    t          |           } t          | t                    rdS t          | t                    rt	          d | j        D                       S dS )NTc              3  4   K   | ]}t          |          V  d S r   )rE  )r   r  s     r   r   z'is_type_type_context.<locals>.<genexpr>  s+      HH$'--HHHHHHr   F)r   r   r   r   r  r   r?  s    r   rE  rE    s]    g&&G'8$$ t'9%% IHH'-HHHHHH5r   )r   r   r   r   r  )r   r   r  r   r   r   )r  r_  rj  r  rk  r  r   r   )r  r   r  r   r   r   )r   r  r   r   )r  r   r  r   r   r   )r   r  r  r  r  r  r  r  r  r  r   r   )r   r  r   r   )r   r7  r   r8  )r  r   r   r   r  r  )r  r   r   rC  )rA  r  r   r   )r   r  r   rH  )rW  r  r   r   (0  r   
__future__r   enumr"  rm  collectionsr   collections.abcr   r   r   
contextlibr   r	   rd  r
   r   r   r   r   r   re  r   r   r   mypy.checkerr  mypy.errorcodes
errorcodesr  r   r   r   r   r   r   r   mypy.argmapr   r   r   mypy.checker_sharedr   mypy.checkmemberr   r   mypy.checkstrformatr   mypy.constant_foldr    mypy.erasetyper!   r"   r#   mypy.errorsr$   r%   r&   mypy.expandtyper'   r(   r)   r*   mypy.exprtotyper+   r,   
mypy.inferr-   r.   r/   mypy.literalsr0   mypy.maptyper1   	mypy.meetr2   r3   mypy.message_registryr4   mypy.messagesr5   r6   
mypy.nodesr7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   mypy.optionsr   mypy.pluginr   r   r   r   r   mypy.semanal_enumr   
mypy.stater   mypy.subtypesr   r   r   r   r   mypy.traverserr   r   r   mypy.tvar_scoper   mypy.typeanalr   r   r   r   r   r   r   r   mypy.typeopsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
mypy.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mypy.types_utilsr   r   r   r   mypy.typestater   mypy.typevarsr   mypy.visitorr   r^  r   r  r   r   r   ru  r   r   r   uniqueEnumr   r  r  r  r  r  r  r
  r  BoolTypeQueryr  r  r  r  ry  r  ra  r#  r  r5  r  r-  r  r  r  r  r  r  r
  r  rp  rE  r   r   r   <module>ru     s   M M M " " " " " "       # # # # # # 8 8 8 8 8 8 8 8 8 8 2 2 2 2 2 2 2 2 F F F F F F F F F F F F F F F F C C C C C C C C           V V V V V V V V V V V V V V V V V V W W W W W W W W W W : : : : : : @ @ @ @ @ @ @ @ 6 6 6 6 6 6 1 1 1 1 1 1 [ [ [ [ [ [ [ [ [ [ F F F F F F F F F F            J I I I I I I I ` ` ` ` ` ` ` ` ` ` ! ! ! ! ! ! 2 2 2 2 2 2 @ @ @ @ @ @ @ @ . . . . . . 5 5 5 5 5 5 5 5J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J J JV - , , , , ,              ) ( ( ( ( (                            
 - , , , , ,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                                     &* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *V            & % % % % % ' ' ' ' ' ' * * * * * * "	4$S,QXY[__
     
    
	& 	& 	&  	 	 	 	& & &         I      O O O O Oy O O O         (/  / / / /&-  - - - -%+  + + + +Pa Pa Pa Pa Pa)$/1K Pa Pa PafB4 4 4 4 4
; ; ; ; ;$ ; ; ;4V V V VM M M M06 6 6 6
   22 2 2 2
A A A A Ae1 A A A B B B B    u2   G G G G    E$7   <R <R <R <R~7 7 7 7t= = = =* * * *Z   
 
 
 
      &           r   