
    *ea                      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	 ddl
mZmZ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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*m+Z+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZDmEZE ddlFmGZG ddlHmIZImJZJ ddlKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dd lmZmZmZmZ dd!lmZ dd"lmZ dd#lmZ dd$lmZ eeeeTeeeeee         e^e^g
df         Zd%ed&<   d'Zd(ed)<   g d*Zd(ed+<   h d,Zd(ed-<    G d. d/e          Zdd4Zdd8Z G d9 d:e          Zej         G d; d<ej                              Zej        Zd(ed=<   ej         Zd(ed><   ej        Zd(ed?<    G d@ dAee                   ZdddDZ G dE dFe$j                  ZddGZddHZ	ddIZ
ddPZddTZddYZ G dZ d[e          Z G d\ d]e          Z G d^ d_e$j                  Z G d` dae$j                  ZddcZ G dd dee$j                  ZddfZ G dg dhe$j                  ZddkZddsZdduZddyZdd|ZddZddZddZddZddZdS )zGExpression type checker. This file is conceptually part of TypeChecker.    )annotationsN)defaultdict)contextmanager)	CallableClassVarFinalIterableIteratorListOptionalSequencecast)	TypeAliasassert_neveroverload)	applytype	erasetypejoinmessage_registrynodes	operatorstypes)ArgTypeExpandermap_actuals_to_formalsmap_formals_to_actuals)analyze_member_accessfreeze_all_type_varstype_object_type)StringFormatterChecker)
erase_type!remove_instance_last_known_valuesreplace_meta_vars)ErrorWatcherreport_internal_error)expand_typeexpand_type_by_instancefreshen_all_functions_type_varsfreshen_function_type_vars)ArgumentInferContextinfer_function_type_argumentsinfer_type_arguments)literal)map_instance_to_supertype)is_overlapping_typesnarrow_declared_type)ErrorMessage)MessageBuilderformat_type)A	ARG_NAMEDARG_POSARG_STAR	ARG_STAR2IMPLICITLY_ABSTRACTLITERAL_TYPEREVEAL_LOCALSREVEAL_TYPE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
MemberExprMypyFileNamedTupleExprNameExprNewTypeExprOpExprOverloadedFuncDefParamSpecExprPlaceholderNodePromoteExprRefExpr
RevealExprSetComprehensionSetExpr	SliceExprStarExprStrExpr	SuperExpr
SymbolNodeTempNode	TupleExprr   TypeAliasExprTypeApplicationTypedDictExprTypeInfoTypeVarExprTypeVarTupleExpr	UnaryExprVar	YieldExprYieldFromExpr)PRECISE_TUPLE_TYPES)FunctionContextFunctionSigContextMethodContextMethodSigContextPlugin)
ENUM_BASES)state)find_memberis_equivalentis_same_type
is_subtypenon_method_protocol_members)has_await_expression)TypeTranslator)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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)(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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is_named_instanceremove_dupssplit_with_prefix_and_suffix)is_generic_instanceis_overlapping_noneis_self_type_likeremove_optional)
type_state)fill_typevars)split_module_names)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__     .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   exprr^   set[str]c                T   t                      }t          | j        t                    s| j        rwt          | j        t                    r!| j        r|                    | j                   t          | t                    rt          | j        t                    o| j        j        }t          | j        t                    r-|
                    t          | j        j                             n?d| j        v r6|s4|                    | j                            dd          d                    nzt          | t                    r#t          | j        t                     r| j        } n nBt#          dt%          |                      t          | j        t                    o| j        w|S )zRecursively extracts all module references from a reference expression.

    Note that currently, the only two subclasses of RefExpr are NameExpr and
    MemberExpr..   r   zUnknown RefExpr subclass: )setr   noderU   fullnameaddrW   rp   is_suppressed_importrl   updater   module_namersplitrT   r   r^   AssertionErrortype)r   outputr   s      r   extract_refexpr_namesr      s|   
 uuF
TY
)
) LT] Ldi** 	&t} 	& JJt}%%%dH%% 	L#-di#=#=#`$)B` $)X.. <01FGGHHHH%%.B%

4=//Q77:;;;j)) 	L$)W-- y !Jd4jj!J!JKKK- TY
)
) LT] L. Mr   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   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                  x   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<   ddZddZddZdddZdd!Z	dd%Z
ddd(Zdd+Zddd,Zdd-Zdd2Zdd3Zdd6Zdd7Zdd8ZddCZddGZddMZddPZddRZddSZddWZddXZddYZdd]Zd^gd_d`gdaZdbedc<   dddegidfdggidfdggidfdhdegidiZdjedk<   ddlZ ddoZ!ddrZ"ddy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Z/ddZ0ddZ1ddZ2ddZ3ddZ4ddZ5ddZ6ddZ7ddZ8	 	 dÐddZ9ddZ:ddZ;	 	 dÐddZ<ddĄZ=ddńZ>ddȄZ?ddʄZ@dd˄ZAdd̄ZB	 dddфZCdd҄ZDeEdd؄            ZFdd܄ZGdd݄ZH	 ddd߄ZIddZJddZKdddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYdd ZZddddddZ[	 dǐdd	Z\	 dǐdd
Z]ddZ^ddZ_	 dddZ`ddZaddZbd dZcddZdddZeddZf	 dǐdd Zgdd!Zhdd"Zidd%Zjdd(Zkdd)Zld	d*Zm	 dd
d-Zndd/Zodd1Zpdd3Zqdd5Zrdd6Zsdd9Ztdd<Zudd=dd@ZvddBZwddDZxddFZyddHZzddKZ{ddMZ|ddOZ}ddPZ~ddRZddTZddUZddXZddZZd d\Zd!d^Zd"d`Zd#daZd$dcZd%deZd&dgZ	 dǐd'dmZd(doZd)dqZdd*dsZ	 dd+dvZ	 	 	 	 d,d-dyZd.d{Zdd|Zdd}Zd/d~Zd0dZd1dZdd2dZ	 dd3dZdd4dZd5dZd6dZd7dZd8dZd9dZd:dZd;dZd<dZd=dZd>dZd?dZd?dZed@d            ZedAd            Z	 ddAdZdBdZdBdZdS (C  ExpressionCheckerz^Expression type checker.

    This class works closely together with checker.TypeChecker.
    mypy.checker.TypeCheckerchkr1   msgzlist[Type | None]type_contextzdict[Expression, ProperType]resolved_typer   strfrm_checkerrx   pluginper_line_checking_time_nsdict[int, int]r   Nonec                $   || _         || _        || _        || _        |j        j        du| _        d| _        dg| _        i | _	        t          | | j         | j                  | _        i | _        d| _        | j         j        j         t          _        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_polymorphic)selfr  r  r  r  s        r   __init__zExpressionChecker.__init__:  s     )B&+.;+JRV+V( #!F 794T48TXNN +/8+;+N'N
$$$r   c                    i | _         d S r   )r  r  s    r   resetzExpressionChecker.reset\  s    r   erW   r   c                    | j         j                            t          |                     |                     |          }|                     ||          S )z_Type check a name expression.

        It can be of any kind: local, member or global.
        )r  module_refsr   r   analyze_ref_exprnarrow_type_from_binder)r  r"  results      r   visit_name_exprz!ExpressionChecker.visit_name_expr_  sO    
 	##$9!$<$<===&&q))++Av666r   Fr^   lvaluer   c                   d }|j         }t          |t                    r |j        rt	          t
          j                  S t          |t                    rJ|                     ||          }t          |t                    r| j
                            ||||          }nt          |t                    r%t          ||                     d                    }ndt          |t                    rk|j        [| j
                                        r'|j        r | j
                            |j        |           t	          t
          j                  }n|j        }nt          |t,                    r|j        r|                     |          }nt3          || j                  }t          |t4                    r<t          |j        t8                    r"|j        |j        _        |j        |j        _        t          t?          | j         d                   tB                    rtE          j#        |          }n	t          |tH                    r| %                    |          }nt          |tL                    r|                     |j'        |          }nt          |tP                    r | )                    |||j*        p|          }nxt          |tV          tX          tZ          f          r| .                                }nAt          |t^                    rJ d|j0        d            t	          t
          j                  }|J |S )Nbuiltins.functionctxalias_definitionFzPlaceholderNode z leaked to checker)1r   r   rW   is_special_formr   r   special_formrp   analyze_var_refr   r  handle_partial_var_typerM   r   
named_typerZ   r   in_checked_functionr   handle_cannot_determine_typename
from_errorrl   typeddict_typetypeddict_callabler   r   ret_typer   linecolumnr   r  r   r   erase_typevarsrU   module_typerF   varr   alias_type_in_runtime_contextis_alias_rvaluerm   r[   rn   object_typer\   r   )r  r"  r)  r'  r   s        r   r%  z"ExpressionChecker.analyze_ref_exprh  s   "va"" 	3q'8 	391222dC   4	3))$22F&+.. S99&&$PQRRg&& /	3"49L)M)MNNFF/00 ,	3y 8//11 Hdj HH99$)QGGG !566h'' %	3" A0066)$@@&,// 2J5 5 2
 ()v$)*&/$*;B*?@@(KK : #1&99h'' 	3%%d++FFi(( 	3))$(A66FFi(( 	3 77!a.?.I6 8  FF {M;KLMM 	3%%''FF$00 UTTTTTTTT Y122F!!!r   r@  rp   contextrE   c                   |j         rzt          |j                   }t          |t                    rJ|                                 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 )N>   TrueFalserF  builtins.bool)r   r   r   r   is_literal_contextlast_known_valuer7  infer_literal_expr_typeis_readyr  r5  r6  r   r   r1  )r  r@  rD  var_types       r   r2  z!ExpressionChecker.analyze_var_ref  s    8 	3&sx00H(H-- ]**,, 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   rU   r   c                   	 |                      d          }n%# t          $ r |                      d          }Y nw xY wi }t                      }|j                                        D ]\  }}|j        st          |j        t                    r!|j        j	        r|
                    |           | j                            |          }|r|||<   jt          t          j                  ||<   t!          |||j                  |_        |S )Nztypes.ModuleTypebuiltins.object)r4  KeyErrorr   namesr   module_publicr   r   rp   is_finalr   r  determine_type_of_memberr   r   r1  r   r   extra_attrs)r  r   r'  module_attrs	immutabler7  ntyps           r   r?  zExpressionChecker.module_type  s   	8__%788FF 	8 	8 	8 __%677FFF		8
 EE	z'')) 	E 	EGD!? !&#&& $16? $d###(33A66C E%(T"" &-Y-C%D%DT""'iOOs    ::r@   allow_none_returnc                    |j         rat          |j         t                    r!|j         j        s|                     |           |                     |j         | j        d                   S |                     ||          S )zType check a call expression.r,  rZ  )analyzedr   rV   is_typedvisit_call_expr_inneracceptr  )r  r"  rZ  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   baserK   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   r^   r   rl   r9  r   r   targetr   )r  rb  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                    rfj        j        dv rWt!          j                  dk    r>t"          j                            j        d                   D ]}d }t          |t                    r1	  j                            |j                  }n# t,          $ r Y nw xY wt/          |          r' j                            j        j        d           |rmt          |j        t6                    rSt          t          |j        j                  t:                    r' j                            j        j        d           t          |t                    r!t          |j        t>          t@          f          s=t          |t                    rB|r@t          |j        t6                    r&|j        j!        s j        "                               t          |tF                    rt          |j        tH                    rf|j        j%        r( j                            j        j        d           |j        j&        r& j                            j        j        d	            '                               d }t          j        tP                    rtS          j        j        j        j        j        j         fd
           fdtU          t!          j        j                            D             }t          |j        j        j        j         +                                 ,                    d                    }t                               j        |dd                    }	d }
d }d t          j        tF                    r܉j        j-        pd t          j        j        t6                    r?t          j        j        j                  }t          |t\                    r|j/        j-        snt          j        t`                    rT j        1                    j        j2                  r0j        j        } j        3                    j        j2                  }
 j        j4        j5        r j        6                                rt          |	t                    rl|	j7        re||
J  8                    |
|          r*ts          fd j        j4        j:        D                       s j        ;                    |	            <                    |	|
|          }t          j        tF                    r`t!          j                  dk    rHj        j-        dv r =                               j        j-        dk    r >                               t          j        t`                    r%j        j        dk    r ?                               t          |          }t          |t                    rt          |jB                  }t          |t                    r%|jD        s j        jE        F                                 |sht          |t                    rS H                    j                  r9 j        j        I                    |	           t;          t          jK                  S |S )NTr  )r   
issubclassr  r   LiteralAny	TypedDictNewTypec                D                         j        |                    S r   r`  args)ir"  r  s    r   <lambda>z9ExpressionChecker.visit_call_expr_inner.<locals>.<lambda>   s    $++afQi00 r   c                ^    g | ])}t          j        fd |         D                       *S )c                P    g | ]"}                     j        |                   #S r   rn  )r   jr"  r  s     r   
<listcomp>zFExpressionChecker.visit_call_expr_inner.<locals>.<listcomp>.<listcomp>$  s+    $Y$Y$YT[[%;%;$Y$Y$Yr   )r   join_type_list)r   rp  r"  formal_to_actualr  s     r   ru  z;ExpressionChecker.visit_call_expr_inner.<locals>.<listcomp>#  sS        #$Y$Y$Y$Y$YEUVWEX$Y$Y$YZZ  r   r+  )r;  fallback)always_allow_anyr  c              3  T   K   | ]"}|k    p                     | d           V  #dS )r   N)
startswith)r   pr   s     r   r   z:ExpressionChecker.visit_call_expr_inner.<locals>.<genexpr>T  sT       ' ' A=!4!4WWW!=!=' ' ' ' ' 'r   )zbuiltins.isinstancebuiltins.issubclassr}  format)Lre  calleer   rO   rb  r   r`  r   r;  r   check_typeddict_call	arg_kinds	arg_namesro  rW   r7  lenmypycheckerflattenr  lookup_qualifiedrP  is_expr_literal_typer  cannot_use_function_with_typer   r   rd  r   r]  rj   ri   no_argstype_arguments_not_allowedr^   rl   r9  
is_newtypetry_infer_partial_typerQ   r   rangerC  r4  r   r   r   rT   has_typer   lookup_typer  disallow_untyped_callsr5  implicit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   r   	ambiguousbinderunreachabler   always_returns_nonedoes_not_return_valuer   r8  )r  r"  rZ  r:  r9  rY  r   r  	arg_typescallee_typerC  memberrd  r;  rw  r   s   ``            @@r   r_  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"49i88 #?493C#D#DgNN
 H::18=%QRSSSsI..	;"3</=1QRR	; sH--		;
 	; #49i88	; !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	? $		? 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                   t          |j        t                    sJ d}t          |j        j        t                    r|j        j        j        }n| j                            |j        j                  rgt          | j        	                    |j        j                            }t          |t                    r!t          |j        t                    r|j        }|| j                            ||           dS dS )z>More precise type checking for str.format() calls on literals.N)r   r  rT   r   rd   valuer  r  try_getting_literalr  r   strr  r  )r  r"  format_valuebase_typs       r   r  z'ExpressionChecker.check_str_format_callu  s    !(J/////ahmW-- 	.8=.LLXqx}-- 	.*48+?+?+N+NOOH(K00 .ZPS5T5T .'~#55aFFFFF $#r   rC  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_objr;  r   itemr   r   r   r   r   rx  get_containing_type_infor   r   )r  rC  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   r^   defn_returns_noner   rT   r   r  r  r   r   r   r   r  r;  getr7  )r  r   rY  r  r;  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   rM   r   r   r   r;  r   rZ   r   r   rp   is_inferredr   r  r  r   )r  r  rY  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  ro  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  ro  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]ro  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                .    g | ]}|t           t          fv S r   )r3   r6   )r   aks     r   ru  z:ExpressionChecker.check_typeddict_call.<locals>.<listcomp>  s"    JJJ"	955JJJr   c                4    g | ]}|t          |          nd S r   )rd   )r   rX  s     r   ru  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   r8  r  r4   r   rG   check_typeddict_call_with_dictr   r@   r]  r   r  r  r   INVALID_TYPEDDICT_ARGS)r  r  r  r  ro  rD  r  r  r'  validated_kwargsalways_present_keys
unique_args               r   r  z&ExpressionChecker.check_typeddict_call  s     	1CJJ	JJJKK 	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   listr   r`  r   r  r  r  r   $TYPEDDICT_KEY_MUST_BE_STRING_LITERALcodesLITERAL_REQr   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  r   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   ru  zBExpressionChecker.validate_star_typeddict_item.<locals>.<listcomp>X  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   r`  r   r   r   r   relevant_itemsr  valid_unpack_fallback_itemr  %unsupported_target_for_star_typeddictr   r   keysrg   
make_unionset_liner   r   )r  r  r  r'  r  inferredpossible_tdsr  all_keysr  argfirstr  s               @r   r  z.ExpressionChecker.validate_star_typeddict_item9  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   rY  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>w  s,      QQa:a))QQQQQQr   )r   r   r   r   has_baser-   r  lookup_typeinfor   r   ro  )r  rY  mappeds      r   r  z,ExpressionChecker.valid_unpack_fallback_itemq  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  r   r  r   )r  r  r  rD  r'  r  _s          r   match_typeddict_call_with_dictz0ExpressionChecker.match_typeddict_call_with_dicty  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  rD  r  r  )r  r  r   r   r8  )r  r  r  rD  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  rl   r   c           	        |j         J |j         j        }t          |t                    rt          |t                    sJ t          |j                                                  }t          j	        gt          |          z  }t          |j                                                  }t          |||||                     d          |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.
        Nbuiltins.type	variables)special_aliasrd  r   r   r   r  r   r  r;   r3   r  r  r   r4  r  	type_vars)r  r  rd  expected_typeskindsrQ  s         r   r:  z$ExpressionChecker.typeddict_callable  s     !---#*&*--S*V]2S2SSSSfl113344"#c.&9&99V\&&(())OOO,,i)
 
 
 	
r   c           	        t          t          |j                                                  t          j        gt          |j                  z  t          |j                                                  ||                     d                    S Nr  )	r   r  r   r  r;   r3   r  r  r4  )r  r  s     r   typeddict_callable_from_contextz1ExpressionChecker.typeddict_callable_from_context  sp    $$&&''#fl"3"33""$$%%OOO,,
 
 	
r   c                   |                                 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                                        5  |                     |d |                                D             t,          j        gt1          |          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          |	t2                    s}	|	j                                        D ]b\  }
}|
|v rY||
         }|D ]N}| j                            |||t7          t8          j        j        t>          j                   d|
 dd	
           Oc|S )Nc                .    g | ]}|j         v s|v |S r   r  )r   r  actual_keysr  s     r   ru  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s;     # # #&"666#:L:L :L:L:Lr   )expected_keysr  rD  c                &    g | ]}|j         v |S r   r  r   r  r  s     r   ru  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s-     # # # #cVEY>Y>Y>Y>Y>Yr   c                &    g | ]}|j         v |S r   r  r!  s     r   ru  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s-     ! ! ! #cVEY>Y>Y>Y>Y>Yr   c                    g | ]
}|d          S r   r   )r   ro  s     r   ru  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s    555Ta555r   r  zTypedDict item ""
expression)lvalue_typervaluerD  r  lvalue_namervalue_name)!r  r  r   r  unexpected_typeddict_keysr  r   r   r8  r   r   r   rx  r   r  r:  r  filter_errorsr  local_type_mapcheck_callable_callr  r;   r3   r  r   check_simple_assignmentr0   r   INCOMPATIBLE_TYPESr  r  TYPEDDICT_ITEM)r  r  r  rD  r  r  infer_calleeorig_ret_typer  r;  	item_nameitem_expected_typeitem_values
item_valuer  s    `            @r   r  z2ExpressionChecker.check_typeddict_call_with_kwargs  s    kkmm $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   -I A6I	=I 	I	I I	I  I$'I$r   rT   
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   rW   r   rp   is_selfr  scopeenclosing_classr7  rQ  r   r   )r  r   r  r  s       r   get_partial_self_varz&ExpressionChecker.get_partial_self_var  s     ty(++	49>3//	 	&	 4x~--// 	ty
224j#ch$$ 	CHM;)O)O 	8Otr   r  r   discard)builtins.listr   zClassVar[dict[str, list[str]]]	item_argsextendr?  r   builtins.dictr   )r?  rB  zcollections.OrderedDictr   z)ClassVar[dict[str, dict[str, list[str]]]]container_argsc                   t          |j        t                    sdS |j        }t          |j        t                    rU|                     |j                  }|dS |\  }}|                     ||j        |          }|||v r||_        ||= dS dS dS t          |j        t                    rt          |j        j
        t                    r|j        j        dS |j        j
        }|j        j        }|                     |          }|dS |\  }}t          |j                  }	|	|	j        dS |                     ||j        |          }
|
t|                     |          }t           j                            |          rB|	j        J |	j        j        }| j                            |||
g          |_        ||= dS dS dS dS dS )z-Try to make partial type precise from a call.N)r   r  rT   r   r^   get_partial_var&try_infer_partial_value_type_from_callr7  r   rO   rb  r]  indexget_partial_instance_type
value_typer`  r  r  is_valid_inferred_typer   r  named_generic_type)r  r"  r  retr@  partial_typesrY  rb  rG  partial_typerI  r  typenames                r   r  z(ExpressionChecker.try_infer_partial_type8  s   !(J// 	Ffk7++ !	+&&v{33C{!$C==acRRC3-#7#7!#&&& #7#7 Y// 	+Jv{?OQX4Y4Y 	+{#/;#DK%E&&t,,C{!$C4SX>>L#|'>'FDDQUXYYJ%;;u--<66x@@ +',888+09H#x::8hPZE[\\CH%c***-	+ 	+ 	+ 	+ &%+ +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   rT   r=  rp   r  find_partial_types)r  rP  r@  rM  s       r   rE  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 rn|j        t          gk    r]| 	                    |j
        d                   }t          j                            |          r| j                             ||g          S n|| j        v r|| j        |         v r|j        t          gk    rt!          | 	                    |j
        d                             }t#          |t$                    rm|j        j        }|| j        |         |         v rKt'          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  T   K   | ]#}t           j                            |          V  $d S r   )r  r  rJ  )r   	item_types     r   r   zKExpressionChecker.try_infer_partial_value_type_from_call.<locals>.<genexpr>  sF        % ;;IFF     r   )r  current_node_deferredrH  r   rI  r   r@  r  r4   r`  ro  r  r  rJ  rK  rC  r   r   r   r   r  r   r4  )	r  r"  rT  r@  rN  rO  rX  arg_typearg_typenames	            r   rF  z8ExpressionChecker.try_infer_partial_value_type_from_callk  s    8) 	40::4" 	2#.3<HH$000#(1H &&dnX666y((AF1I..I|229== 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] | Nonerw  list[list[int]]r   c
                   t          |j                  }
d t          |
          D             }d t          |
          D             }d t          |
          D             }d t          |
          D             }t          |          D ]\  }}|D ]}||                             ||                    ||                             ||                    |r!||                             ||                    ||                             ||                    |L| 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   r  s     r   ru  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>  s    -M-M-MQb-M-M-Mr   c                    g | ]}g S r   r   ra  s     r   ru  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>      3S3S3S1B3S3S3Sr   c                    g | ]}g S r   r   ra  s     r   ru  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>  rc  r   c                    g | ]}g S r   r   ra  s     r   ru  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>  s    0P0P0P0P0P0Pr   )r  r  r  	enumerater  r  get_function_hookrt   r  r;  r  get_method_hookr   rv   )r  r  r  r  r  rw  ro  r   rC  rD  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=== G$V,33If4EFFF (//	&0ABBBBC {44X>>H'''8$$$$O$H	 	   #k99(CCO"...)+66K"?$$$$O$H
 
  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   r`  rp  ro  r  s    r   rq  z8ExpressionChecker.apply_signature_hook.<locals>.<lambda>      $++d1g.. r   c                    g | ]}g S r   r   ra  s     r   ru  z:ExpressionChecker.apply_signature_hook.<locals>.<listcomp>  s    7W7W7Wq7W7W7Wr   )r   r   r  r  r   r  r  rf  r  r   r   apply_signature_hook)r  r  ro  r  r  rt  ri  rw  rk  rn  ro  rp  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   )ru   r  )ro  sigrD  r  r~  s     r   rq  zAExpressionChecker.apply_function_signature_hook.<locals>.<lambda>  s$    ~~.@sGUYU].^.^__ r   )r|  )r  r  ro  r  rD  r  r~  s   `   ` `r   apply_function_signature_hookz/ExpressionChecker.apply_function_signature_hook  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   )rw   r  )ro  r  rD  pobject_typer  r~  s     r   rq  z?ExpressionChecker.apply_method_signature_hook.<locals>.<lambda>!  s(    ..$\4gtxPP# # r   )r   r|  )	r  r  ro  r  rD  r  rC  r~  r  s	   `   `  `@r   apply_method_signature_hookz-ExpressionChecker.apply_method_signature_hook  s\     '{33((      

 

 
	
r   N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  ro  r  rD  r  rC  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                h   |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                                        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  )r  r  r  r   r   r   r;  r  r-  r  r,  r`  r   )r  r  ro  rZ  s       r   "is_generic_decorator_overload_callz4ExpressionChecker.is_generic_decorator_overload_callP  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+C9-D9C=	=D C=	DDD
overloadedr   r.  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.
        rY  N)r   rg   r  r,  
check_callr4   has_new_errorsr   r   r   r  r   )r  r  r  r.  r'  inferred_argsr  r  erritem_resultinferred_argp_item_resultp_inferred_args                r   handle_decorator_overload_callz0ExpressionChecker.handle_decorator_overload_callc  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           
     *   |||J |                      ||          }t          |          }|r+|                     |||j        |j        ||j        |          }n.|,t          |t                    r|                     |||          S | 	                    ||j        |j        ||j        |j
        ||          \  }}t          |          }t          |j
        t                    r-t          |t                    r|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  rC  )r  r   r  ro  r  r  r   r   check_union_call_exprr  r  r^   r   
type_guard)r  r  r"  r  rC  r  r;  proper_callees           r   r  z2ExpressionChecker.check_call_expr_with_callee_type  s3   &  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qx))	;=,77	; (4 #0":AHr   r   c                   g }|                                 D ]}| j                                        5  t          |||ddd| j        || 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)original_typer  in_literal_context	self_typeNT)skip_non_overlapping)r  r  r,  r   r  rI  r&  r  r  r  r  r   )
r  r"  rC  r  resrY  r  narrowedr  item_object_types
             r   r  z'ExpressionChecker.check_union_call_expr  s_   --// 	 	C''))  ,H"-'+'>'>'@'@!                 33AHdY]3^^H 00f==M&3=ssJJ55h=Rbcc    %S)))s   7A55A9	<A9	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| j        |	p|| j
        |                                 
  
        }|j        j        dz   }|                     |||||||          }|                     ||||||||          }|r| j
                            ||           |S t          |t0                    r|                     |j        |||||          S t          |t4                    r5|                     |j        |          }|                     ||||||          S t          |t:                    r+|                     t=          |          ||||||||	  	        S | j                            ||          t          t@          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)	is_lvalueis_superis_operatorr  r  r  r  z	.__call__r  )"r   r   r   r  r  r  r.  r   check_overload_callr   r  r5  check_any_type_callr   check_union_callr   r   r  rI  r   r   r  r  
store_typer   upper_boundr   analyze_type_type_calleer  r   r   not_callabler   r8  )r  r  ro  r  rD  r  r  r  rC  r  r  overloaded_resultcall_functionr'  r  s                  r   r  zExpressionChecker.check_call  s8   @ !((fl++ S	Y 	1!DDVTRR
) )-(K(K
G) )% )400++	 	 	 
++ =	Y++iM;PW   (( 9	Y0L0L0N0N 9	Y++D&999	** 7	Y((y)WUUU)) 5	Y1 H+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&&$ # 
 
 
 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}tS          |||j*        |j+         fd          }t          |j                  }	t          |	tX                    r@|	j-        r9t]          |j                  }t_          |           |0                    |          }|1                                rtE          d	 |j-        D                       }te          |          } 3                    ||          }|r!tS          |||j*        |j+         fd
          } 4                    ||||||          }|r!tS          |||j*        |j+         fd          }|5                                }||t>          tl          gk    r                      d                   }                      d                   }t          |tn                    rgt          |tn                    rR|j8        tr          j:        k    r=|j8        tr          j;        k    r(|j<        |j<        cxk    r|j<        k    rn n	|j        |fS  =                    |||          } >                    ||||||||            ?                    ||||||           |                                rit          |          dk    rVt          |j         B                    d                    r.|0                    t          jD        |d                             }|r j        E                    ||           |rk| jF        G                    |          s|M jF        H                    |          r3 I                    ||||||||	  	        }|0                    |          }|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  Tc                :                         |                    S r   rx  ry  s    r   rq  z7ExpressionChecker.check_callable_call.<locals>.<lambda>  s    dkk$q'** r   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   rx  ry  s    r   rq  z7ExpressionChecker.check_callable_call.<locals>.<lambda>      dkk$q'22 r   c                :                         |                    S r   rx  ry  s    r   rq  z7ExpressionChecker.check_callable_call.<locals>.<lambda>  r  r   r   r   rC  r  )Jwith_unpacked_kwargswith_normalized_var_argsr7  r   r;  r  r   r   r   r   r^   ry   r  r  from_type_typer  r  r   CANNOT_INSTANTIATE_PROTOCOLr~  is_abstractfallback_to_anyabstract_attributesr7   can_return_noner  !cannot_instantiate_abstract_classvar_argrY  r   r  r5   r`  r   r  r   r  CALL_ARGr   r   r8  r   r  r  r   r  r'   r   copy_modified
is_genericr(   +infer_function_type_arguments_using_contextr*   
param_specr6   r   flavorr   ARGSKWARGSidinfer_arg_types_in_contextcheck_argument_countcheck_argument_typesr  r|   r4  r   make_normalizedr  r  rg  rh  rs  )r  r  ro  r  rD  r  r  r  rC  r;  r   r  	attr_nameabstract_statusr  seen_unpackr  arg_kindrZ  rw  fresh_ret_typeneed_refreshr  arg1arg2r  new_ret_types   ` `                        r   r.  z%ExpressionChecker.check_callable_callH  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1*****
 
 #6?33h-- 	C(2D 	C<V_MMN 000))>)BBF 	  JPJZ    L 077FEEfgVVF 
 $:$$22222$ $  77i4DlT[ F  #9$$22222$ $  &&((
!iHi3H&H&H;;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)rz   strict_optionalmrorQ  r  r   r   rZ   implrF   funcrM   r   r   r~   r   r;  )r  r   r  rb  symnoder   s         r   r  z!ExpressionChecker.can_return_none  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  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  r  c                V    g | ]%}                     t          |                    &S r   )r  r   )r   r  rD  r  s     r   ru  z>ExpressionChecker.analyze_type_type_callee.<locals>.<listcomp>*  sA        11/"2E2EwOO  r   r  c                <    g | ]}|                                S )r  r  )r   cr  s     r   ru  z>ExpressionChecker.analyze_type_type_callee.<locals>.<listcomp>:  s'    $Z$Z$ZQ__d_%C%C$Z$Z$Zr   builtins.tuple)r   r   r   from_another_anyr   r   r   r4  r   r  r&   r   r  r<  r   r  r   r  r   r   r   r   r   r  unsupported_type_typer8  )r  r  rD  r  expandedr  s   ```   r   r  z*ExpressionChecker.analyze_type_type_callee  s<   
 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&&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.
        )r`  has_erased_componentr  r   )r  ro  r  r  rZ  s        r    infer_arg_types_in_empty_contextz2ExpressionChecker.infer_arg_types_in_empty_contextC  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_typeS  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  rf  is_starr  r  r`  r   r  r   r   r   r   )r  r  ro  r  rw  r  rp  ro  airZ  r   r   s               r   r  z,ExpressionChecker.infer_arg_types_in_contextc  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                r   | j         d         }|s|S t          |t                                }|j        }t	          |          r-t	          |          rt          |          }t          |          }t          |t                    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'.
        r,  Tskip_unsatisfiedN)r  r"   r   r;  r   r   r   r   r   r   r  r+   r  has_uninhabited_componentr  r  apply_generic_arguments)	r  r  r  r.  
erased_ctxr;  ro  new_argsr  s	            r   r  z=ExpressionChecker.infer_function_type_arguments_using_context  sg    # 	O 'sJLL99
$x(( 	5-@-E-E 	5 'x00H(44J h,, 	00 '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?          |          }|*tA          d |D                       rtC          |           |S t%                      d
_"        fd|D             }n/tG          tH          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   )rD  strictr  dictr   builtins.strc              3     K   | ][}|d u pRt          t          |          t                    p0t          t	          |                    t          j                  z  V  \d S r   )r   r   r   r   r   r  )r   r  r  s     r   r   zBExpressionChecker.infer_function_type_arguments.<locals>.<genexpr>%  s       ? ?  T	 Foa00/BBF}Q''((3{/D+E+EE? ? ? ? ? ?r   c                :                         |                    S r   rx  r  ro  r  s    r   rq  zAExpressionChecker.infer_function_type_arguments.<locals>.<lambda>4  s    $++d1g"6"6 r   T)rD  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>J  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>U  s    [[[aAD'[[[r   )r%   r  r  )r   r  r  	free_varsr  s     r   ru  zCExpressionChecker.infer_function_type_arguments.<locals>.<listcomp>S  sq     ! ! !  }  [[[[48M3N3NQZ3Z[[[   ! ! !r   )(r  r5  r  r,  r  get_arg_infer_passesr  rf  r  r*   argument_infer_context#infer_function_type_arguments_pass2special_sigr3   r6   r   r   r   r   r4  r~   r  r   &KEYWORD_ARGUMENT_REQUIRES_STR_KEY_TYPEr  r  r  r   r  r  r  
apply_polyr   r   r  r   r   unannotatedr  apply_inferred_arguments)r  r  ro  r  r  rw  r  rD  r  arg_pass_nums
pass1_argsrp  r  r  r  	first_argpoly_inferred_argspoly_callee_typeappliedr  r  s   ```                @@r   r*   z/ExpressionChecker.infer_function_type_arguments  sM     8'')) v	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 53 ? ? ? ? '	? ? ? < < 5   
 (>!!#-#-66666( ($ 1N$ 779987799&*	1 	1 	1-"I $(#?#?!3W$ $ 
 %%5yAA&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	           	     *    t          |          }	t          t          |	                    D ]5\  }
}t          |t          t
          f          st          |          rd|	|
<   6                     ||	|          }|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   rx  r  s    r   rq  zGExpressionChecker.infer_function_type_arguments_pass2.<locals>.<lambda>  rz  r   rD  )r  rf  r   r   r   r   r  r  r   r  r  r  r,  r  r*   r  )r  r  ro  r  r  rw  r+  r  rD  r  rp  r  r  r  s   ` `           r   r  z5ExpressionChecker.infer_function_type_arguments_pass2a  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   7CC #C r)   c                    t          | j                            d          | j                            d                    S )Nr  typing.Iterable)r)   r  r4  r   s    r   r  z(ExpressionChecker.argument_infer_context  s;    #H 011483F3FGX3Y3Y
 
 	
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  )rf  r  r   r   r   r  r   r{   r  rQ   r`  ArgInferSecondPassQuery)r  r  ro  r  rw  r3  r  rp  r  skip_param_specp_formalrt  p_actualcall_methods                 r   r  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          |          D ]_\  }}|rt          |          rI| j                            ||dz   |           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   )	rf  r  r  could_not_infer_type_argumentsr   r   r8  r  r  )r  r  r  rD  rp  inferred_types         r   r$  z*ExpressionChecker.apply_inferred_arguments  s     !*- 8 8 	U 	UA}  U$8$G$G U77QUGTTT!()=!>!> ?#mBTBT T ++KPPPr   actual_typesactual_kindsactual_namesContext | Nonec	                J   |&t          t          t          j                            }i }	|D ]#}
|
D ]}|	                    |d          dz   |	|<   $|                     |||||	|          \  }}t          |j                  D ]\  }}|                                r||         s|s~|	                                r<| j
                            |||           |r|rd|v r|                     |||           n+|j        |         pd}| j
                            |||           d}|                                st!          ||         ||          rm| j                                        s4t'          t)          |||         d                            t*                    r| j
                            |||           d}:|                                rQ||         rI|||         d                  t0          j        t0          j        fvr| j
                            ||           d}|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)rg   r   r   r1  r   check_for_extra_actual_argumentsrf  r  is_requiredis_positionalr  too_few_argumentsmissing_classvar_callable_noter  missing_named_argumentr  is_duplicate_mappingr  r5  r   r   r   duplicate_argument_valueis_namedr   r3   r6   too_many_positional_arguments)r  r  r@  rA  rB  rw  rD  rC  r  all_actualsro  r  okis_unexpected_arg_errorrp  kindargnames                    r   r  z&ExpressionChecker.check_argument_count  ss   $ ?wy'=>>??G
 ')' 	; 	;G ; ;!,A!6!6!:A; '+&K&KL,k7'
 '
##
 !!122 	 	GAt!! *:1*= F] %%'' NH..vwMMM" a} a9M9M;;KX_```$.q18SGH33FGWMMM\\^^ (< #\<) )  8//11 Z#L1A!1DQ1G$HII96 6  H55faIIIB$Q' !!1!!4Q!78RWRa@bbb 66vwGGG	r   rP  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   )rf  r   r5   is_non_empty_tupler6   r3   r  too_many_argumentsunexpected_keyword_argumentr  r   r   r   r   r  r  r   "too_many_arguments_from_typed_dict)r  r  r@  rA  rB  rP  rD  rR  rQ  rp  rS  act_nameact_typeactual_types                 r   rF  z2ExpressionChecker.check_for_extra_actual_arguments!	  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   )maxsplitr%  zN" is considered instance variable, to make it class variable use ClassVar[...])r   r   r   r   r   r  r   rp   r  is_classvarr  note)r  rC  r  rD  r  var_namer   s          r   rJ  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	          |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                    rUt          |j	                  !|j	        }t          gt          |          z  }n|j	                 }t          |t                    sJ t	          |j                  }t          |t                     r6|j	        }fd	t#          t          |j	                            D             }nMt          |t$                    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          |t                     r|g}t          g}nt          |t$                    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 t5          |||||          D ]\  }}}}}||t          j        k    r0|                     |          s| j                            ||           |t          j        k    rY|                     |          sDt?          || j                             d                    }| j        !                    |||           |	"                    |||j#        |
         |t          |t                              } ||||||dz   |
dz   ||||         |
  
         d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.
        Fc                     g | ]
}|         S r   r   )r   r  r  s     r   ru  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>	  s    :::QIaL:::r   r   r   c                     g | ]
}|         S r   r   r   r  r  s     r   ru  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>	  s    >a>a>aPQy|>a>a>ar   NTc                     g | ]
}|         S r   r   rh  s     r   ru  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>	  s    >>>	!>>>r   c                8    g | ]}|k    rt           nt          S r   )r4   r5   )r   rp  inner_unpack_indexs     r   ru  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>	  s8     4" 4" 4"() 014F/F/FGGH4" 4" 4"r   r   _typeshed.SupportsKeysAndGetItem)allow_unpack)$rc  r   r  rf  r   r  r  r   r   r   r   r   r5   r4   r   r   r   r  r   r   ro  r  r  r  rX  rI  r  is_valid_var_arginvalid_var_argr6   is_valid_keyword_var_argr~   r4  invalid_keyword_var_argexpand_actual_typer  )r  r  r  ro  r  rw  rD  rc  rC  mapperrp  ro  orig_callee_arg_typeexpanded_tuplerA  p_actual_typer@  p_callee_typecallee_arg_typescallee_arg_kindsunpacked_typeinner_unpackinner_unpacked_typerp  r]  actual_kindcallee_arg_typecallee_arg_kind
is_mappingexpanded_actualrk  s    ``                           @r   r  z&ExpressionChecker.check_argument_typesl	  s   " /	 !<!<!>!>??#$455 w	 w	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[/? &%.009N9N{9[9[0H,,['BBB%/11$:W:W; ;1 ",#TX%8%89[%\%\" "J H44[*gVVV"(";";$Q'#!+OZ!H!H #< # # 	##QJEL   -!mw	 w	r   caller_typeoriginal_caller_typecaller_kindr;   rX  mouter_contextc           
     V   t          |          }t          |          }t          |          }t          |t                    r| j                            ||	           dS |                     ||          r| j                            ||	           dS t          ||| j        j	                  sx| j        
                    |||||||	|
          }| j                            |||	|           | j                                        s!| j                            |||	|           dS dS dS )z.Check the type of a single argument in a call.)r  )rC  rD  r  r  N)r   r   r   r  deleted_as_rvaluehas_abstract_type_partconcrete_only_callr~   r  r  incompatible_argumentincompatible_argument_noteprefer_simple_messagescheck_possible_missing_await)r  r  r  r  r  rX  r  r  rC  rD  r  r  s               r   rc  zExpressionChecker.check_arg	  se    &k22./CDD%k22k;// 	_H&&{G<<<<<((kBB 	_H''W=====Kdh>NOOO 	_811$'+ 2 	 	D H//$k7 0    82244 _55k;PWY]^^^^^	_ 	__ _r   c                    |                                 }                     |          }                     ||||          }	d}
d}                     ||	          }d}t	           fd|D                       r	  j                                        5                       |	||||||||	  	        }ddd           n# 1 swxY w Y   |rVt          | \  }}t          t          |          |j        |j                                       t          |                    f}n# t          $ r d}Y nw xY w                     |	|||||||          }|L|Jt#          |d         |d                   r,t%          t'          |d                   t(                    s|s|S |S ||S ||S                      |	|||||          }
t-          |
          dk    r	|
d         }nUt)          t.          j                  }t3          |          sd}nt4          j        } j                            ||||                                |||||||          }|r'|s% j                            t@          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>A
  s/      99ts##999999r   Tr   r  r  rC  )"r  r  plausible_overload_call_targetspossible_none_type_var_overlapr  r  r,  union_overload_resultr  r   r  r<  r=  combine_function_signaturesr   r   infer_overload_return_typer~   r   r   r   overload_erased_call_targetsr  r   r8  is_operator_methodr  OPERATORno_variant_matches_argumentsr  r  r  r   TOO_MANY_UNION_COMBINATIONS)r  r  ro  r  r  r  rC  rD  r  plausible_targetserased_targetsunioned_resultnone_type_var_overlapunion_interruptedunioned_returnreturnsinferred_typesinferred_resultrd  r  r'  s   `                    r   r  z%ExpressionChecker.check_overload_call!
  sU    ,,..99$??	 @@y)V
 
 5937
 !% C CIO` a a!9999y99999 	X++--  %)%?%?)!!!%#-
& 
&N              " " 	.1>.B+G^ .d7mmW\7>ZZ889I.9Y9YZZ&N ! ) ) )$(!!!)" 99	
 	
 &>+E ?1-~a/@AA'"??13E#F#FPP' .'
 '&!!'!!("" ::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" B>2D" >CD" CD" "D10D1r   list[CallableType]c           
     B   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  | 	                    ||||d	          rS|r|j
        r|                    |           n4|	r|j        r|                    |           n|                    |           d	d	d	           n# 1 swxY w Y   ||z   S )a/  Returns all overload call targets that having matching argument counts.

        If the given args contains a star-arg (*arg or **kwarg argument), 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.rY  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   rp  r  s    r   rq  zCExpressionChecker.plausible_overload_call_targets.<locals>.<lambda>
  s    iXYl r   NrY  r   r   r   )r  r5   r6   r   r   r  r  r  r,  r  
is_var_argr  	is_kw_arg)r  r  r  r  r   r  matchesstar_matchesargs_have_var_argargs_have_kw_argrS  rY  rw  s    `           r   r  z1ExpressionChecker.plausible_overload_call_targets
  s   $	 	 	 	 ')+-! Y	22 	( 	(ID#x		#$(!y  3 #' > 	, 	,C59cmS]DZDZDZDZ    '')) 	, 	,,,Iy:JD  , ) ,S^ ,$++C0000) ,cm ,$++C0000s+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, g%%s   A.DD	D	r  c	                "   g }	g }
g }t          t          t          |                    }g }|D ]F}| j        | j        j        u sJ | j                                        5 }| 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||fc S t          |          }t          |t                    r|	                    |           n|	                    |           |
                    |           |                    |           |                    |           H|	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  ro  r  r  rD  r  rC  Nr   c                ,    g | ]}t          |          S r   )r    )r   rY  s     r   ru  z@ExpressionChecker.infer_overload_return_type.<locals>.<listcomp>  s     I I ISC I I Ir   )r  maphas_any_typer  r  r,  r-  r  r  r   r   r   r  any_causes_overload_ambiguityall_same_typesstore_typesr    r   r   r1  )r  r  ro  r  r  r  r  rC  rD  r  return_typesr  args_contain_any	type_mapsrY  wr  r;  
infer_typeis_matchp_infer_types                        r   r  z,ExpressionChecker.infer_overload_return_type
  s@   * ')#%%'s<;;<<24	$ 	$ 	$C8tx|++++'')) 
QX,,.. 	!+/??"!"+"+ '&3$/ ,; , ,(Hj	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ++---H $ ( 0#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;8 B$B;$B((B;+B(,B;;B?	B?	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  ro  rD  r  rY  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  rp  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>b  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>d  sL        MN
?1;q>::KHH     r   )r   r   r   r   r   minr  r  )r  r  r  has_optional_argrZ  r  
min_prefixrp  s          @r   r  z0ExpressionChecker.possible_none_type_var_overlapD  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   rf  r  type_overrides_setr  r   r   r   r   r  copyr  rA  r   r   r  )r  r  ro  r  r  r  r  rC  r  rD  r  idxrY  r  directfirst_union	res_itemsr  new_arg_types
sub_resultseenr'  pairs                          r   r  z'ExpressionChecker.union_overload_resultj  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  rY  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   rY  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>  s,      >>1:a..>>>>>>r   r  r   r   c                    g | ]}g S r   r   ra  s     r   ru  zAExpressionChecker.combine_function_signatures.<locals>.<listcomp>  s    %U%U%UQb%U%U%Ur   FTN)r  r  r  r;  r  r  )r  r  r;  r  r  )r   r   r   r1  r   r  #merge_typevars_in_callables_by_namer  r  r  r  rf  r  rH  r4   r  r;  r   r  r5   r6   )r  r   	callablesr  r  	new_kindsnew_returnstoo_complexrd  rp  new_kindtarget_kindr  union_returnr  
final_args	args_listnew_types                     r   r  z-ExpressionChecker.combine_function_signatures  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   rq  z?ExpressionChecker.erased_signature_similarity.<locals>.<lambda>@  s    PYZ[P\ r   NFr  r   original_ccaller_typer  r;   r  rX  r4  r  r  r   rC  r  rD  rE   r  r   r  c
                4    t          | |          st          d S r   )arg_approximate_similarityr   )
r  r  r  r  rX  r  r  rC  rD  r  s
             r   rc  z@ExpressionChecker.erased_signature_similarity.<locals>.check_argJ  s'     .k;GG   r   )rD  rc  T)r  r   r  r   r  r;   r  r   rX  r4  r  r4  r  r   rC  r  rD  rE   r  rE   r   r  )r   r  r  r  r,  r  r  r   )	r  r  r  r  ro  r  rD  rw  rc  s	    `       r   r  z-ExpressionChecker.erased_signature_similarity4  sg    2y&"2F4DF\F\F\F\
 
 X##%% 	 	,,	9i9I4   	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 		 	 	 	"	%% # &    4 	 	 	55	s#   A11A58A5B 
B-,B-r
  c                H    t          j        ||| j        j        ||          S )z=Simple wrapper around mypy.applytype.apply_generic_arguments.r	  )r   r  r  incompatible_typevar_value)r  r  r   rD  r
  s        r   r  z)ExpressionChecker.apply_generic_argumentsi  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  r1  )r  ro  r  s      r   r  z%ExpressionChecker.check_any_type_cally  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  ro  rD  r  s     r   ru  z6ExpressionChecker.check_union_call.<locals>.<listcomp>  s=        y'9MM  r   c                    g | ]
}|d          S r$  r   )r   r  s     r   ru  z6ExpressionChecker.check_union_call.<locals>.<listcomp>  s    &A&A&A#s1v&A&A&Ar   )r  disable_type_namesr  r   )r  r  ro  r  r  rD  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r  c                    | j         j                            t          |                     |                     ||          }|                     ||          S )z'Visit member expression (of form e.id).)r  r$  r   r   analyze_ordinary_member_accessr&  )r  r"  r  r'  s       r   visit_member_exprz#ExpressionChecker.visit_member_expr  sO    ##$9!$<$<===44Q	BB++Av666r   c                   |j         |                     |          S |                     |j        | j                  }|j        }d}t          |t                    r&t          |j        t                    r|j        j	        }t          |t                    r't          |j        t                    r|j        j        }nd}t          |j        |||dd| j        || j        |                                 ||          }|S )z+Analyse member expression or member lvalue.Nrg  F)r  r  r  module_symbol_tabler:  )rS  r%  r`  r   r  r   r^   r   rU   rQ  rp   r:  r   r7  r  r  rI  )r  r"  r  r  rb  r  r:  member_types           r   r  z0ExpressionChecker.analyze_ordinary_member_access  s    6((+++ !KK$.KIIM6D"&$(( 6Z	8-L-L 6&*io#$((  Z	3-G-G  )+/+H#'#:#:#<#<$7  K r   	base_typec                l    t          |||ddd| j        || j        |                                 
  
        S )z}Analyse member access that is external, i.e. it cannot
        refer to private definitions. Return the result type.
        Fr  r  r  )r   r  r  rI  )r  r  r  rD  s       r   analyze_external_member_accessz0ExpressionChecker.analyze_external_member_access  sI     %H##6688
 
 
 	
r   c                6    t          | j        d                   S )Nr,  )r   r  r   s    r   rI  z$ExpressionChecker.is_literal_context  s    #D$5b$9:::r   r  r   fallback_namec                    |                      |          }|                                 rt          ||          S |                    t          |||j        |j                            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  rx  )r  rx  r<  r=  )rJ  )r4  rI  r   r  r<  r=  )r  r  r  rY  s       r   rK  z)ExpressionChecker.infer_literal_expr_type  sx    " oom,,""$$ 	US9999$$!,#CHSZ" " " %   r   leftr   rightc                    t          |j                  rt          |j                  rJ t          |j        |j        z   |                     d                    S )z$Concatenate two fixed length tuples.r  )r   rx  )r   r   r   r4  )r  r  r  s      r   concat_tupleszExpressionChecker.concat_tuples  sZ    '
33Y8KEK8X8XYYY*u{*T__EU5V5V
 
 
 	
r   rP   c                8    |                      |j        d          S )z(Type check an integer literal (trivial).builtins.intrK  r  r  r"  s     r   visit_int_exprz ExpressionChecker.visit_int_expr      ++AG^DDDr   rd   c                8    |                      |j        d          S )z&Type check a string literal (trivial).r  r  r  s     r   visit_str_exprz ExpressionChecker.visit_str_expr  r  r   r?   c                8    |                      |j        d          S )z%Type check a bytes literal (trivial).r   r  r  s     r   visit_bytes_exprz"ExpressionChecker.visit_bytes_expr  s    ++AG5EFFFr   rL   c                ,    |                      d          S )z%Type check a float literal (trivial).zbuiltins.floatr4  r  s     r   visit_float_exprz"ExpressionChecker.visit_float_expr  s    /000r   rC   c                ,    |                      d          S )zType check a complex literal.zbuiltins.complexr  r  s     r   visit_complex_exprz$ExpressionChecker.visit_complex_expr  s    1222r   rI   c                ,    |                      d          S )zType check '...'.zbuiltins.ellipsisr  r  s     r   visit_ellipsisz ExpressionChecker.visit_ellipsis
  s    2333r   rY   c                F   |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  |rB  )r  r  rD  allow_reverseFzUnknown operator )0r]  r`  opcheck_boolean_opr   r  rS   check_list_multiplyr?   r  check_str_interpolationr  rd   r   r   partial_fallbackr   r  r   r   r   r  rs   r  r  enable_incomplete_featurer   type_is_iterableiterable_item_typerK  r  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_methodrX  r  use_reversemethodr'  r8  s                r   visit_op_exprzExpressionChecker.visit_op_expr  sF   : 	+;;qz***45==ADDLL((A...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   rB   c                $   d}t          |j        |j        dd         |j                  D ]_\  }}}|                     |          }|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|                     |          }| 
                                }	|                     ||          r;tI          |          }tI          |          }| j                            ||d|           |j                            d           ntK          d|           ||	}JtM          j'        ||	          }a|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__)r@  r  ro  r  rD  r  r+  )original_containerprefer_literal	container)r,  )z==z!=equalityiszis notidentityzUnknown comparison operator )(r  operandsr   r`  find_partial_type_ref_fast_pathr   r   r   r  r  	bool_typer  r,  check_method_call_by_namer4   r  analyze_container_item_typer   r  rn  -analyze_iterable_item_type_without_expression
add_errorsfiltered_errorsr   r   r4  method_typesr  r  r~   unsupported_operand_typesdangerous_comparisonr5  r#   errorsr6  r  r9  r   
join_types)r  r"  r'  r  r  operatorr:  
right_type
item_typesr  container_typesiterable_types
failed_outencountered_partial_typerX  container_errorsr  r8  	cont_typeiterable_errorsitertypeiterable_typecontainer_typer@  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
CC 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   r^   r   rp   r2  r   r   r  r  r   )r  r   r'  s      r   rN  z1ExpressionChecker.find_partial_type_ref_fast_path  s     $(( 	4di%% 	))$)T::F&+.. 6;3J##D*<V*D*DEEEtr   T)rG  
seen_typesrH  rG  ri  set[tuple[Type, Type]] | NonerH  c               T   | j         j        j        sdS |t                      }||f|v rdS |                    ||f           t          ||f          \  }}t          |d          st          |d          rdS |rt          |          }t          |          }| j         j        	                                rdS 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 |t0          v r|t0          v rdS t          |t2                    rKt          |t2                    r6t          |j        t6                    rt          |j        t6                    rdS t9          ||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   )ri  r  r   )r?  r  )ignore_promotions)r  r  strict_equalityr   r   r   r   r  r  !is_unreachable_warning_suppressedr   r   r   r   has_bytes_componentr   r   r   r   r
  r-   rW  ro  r	  r   r   r  r   r.   )
r  r  r  rG  ri  rH  	left_name
right_nameabstract_setabstract_maps
             r   rW  z&ExpressionChecker.dangerous_comparison   s   0 x/ 	5J%=J&&5e}%%%&e}55e
 !x00 	4I%QY4Z4Z 	5 	/
 't,,D'..E8?<<>> 	 5dH%% 	E8)D)D 	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'euMMMMMr   r@  c                $   |p|}t          |          }t          |t                    r|                     ||||||          S t	          |||ddd| j        || j        |                                 
  
        }|                     ||||||          S )zType 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.
        FTr	  )	r   r   r   check_union_method_call_by_namer   r  r  rI  check_method_call)r  r@  r  ro  r  rD  r  r8  s           r   rP  z+ExpressionChecker.check_method_call_by_name  s     &2#I..	i++ 	77	4G]   ,H'#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  r  rP  r  r   )r  r@  r  ro  r  rD  r  r  meth_resrY  r  	meth_items               r   rv  z1ExpressionChecker.check_union_method_call_by_name  s     !++-- 	' 	'C ,,..  "&"@"@Cy'=# #i               JJtOOI&&&&$S))+@+J+JJJs   AA"	%A"	r8  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  r8  ro  r  rD  r  rC  s	            r   rw  z#ExpressionChecker.check_method_call  s     ,,YDD#0#<ii$ 00;ik 1 
 
 '!  
 
 	
r   op_namer:  	left_exprr[  
right_exprc           
     $    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          ||          rst          |t                    r^t          |t                    rI|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                4                        ||           sdS j                                        5 }t          | |ddd|j        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)
r7  rY  r  r  r  r  rD  r  r  r  )
has_memberr  r,  r   r  rI  r  )r|  r  r  r  rD  r  s       r   lookup_operatorz>ExpressionChecker.check_op_reversible.<locals>.lookup_operator  s     ??9g66 t'')) >Q. !#" $"+#'+'>'>'@'@    !//11=ttv> > > > > > > > > > > > > > > > > >s   ABBBrY  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  rQ  r  r   )rY  r  clss      r   lookup_definerz=ExpressionChecker.check_op_reversible.<locals>.lookup_definer  sE     x| ( (9==++ (<'''(4r   r  c                $    g | ]\  }}}||||fS r   r   )r   r-  objr  s       r   ru  z9ExpressionChecker.check_op_reversible.<locals>.<listcomp>h  s%    XXX~CRcNr   TrD  r   r   )r|  r  r  r   r   r  )rY  r   r  r  r   r  )r   r   r   r   r  r   r7  op_methods_that_shortcutr}   r~   r   r   alt_promoter  r,  rw  r4   r  r  rT  r  r1  rP  rS  r  r8  )r  r|  r:  r}  r[  r~  rD  r  r  any_typerev_op_nameleft_opright_opvariants_rawvariantsrX  r   r@  r  r  local_errorsr'  	error_anys   `     `                r   check_op_reversiblez%ExpressionChecker.check_op_reversible  s   	> 	> 	> 	> 	> 	> 	>4	 	 	 	  $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 %i<=LLz9--	a9h//	a :x00	a
 *6N.3zFFy'22nnZQ\6]6]]] &z9=T^?_`LL
 %i<xU^>_`L YXXXX  ( 	 	FC''T'BB al//fsegYX_``a a a a a a a a a a a a a a a**,, 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	-!KK!Kr  r,  c                X   |r|g}t          |          }t          |t                    r+d t          |                                          D             }|                     |          }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t0          g          S )zType check a binary operation which maps to a method call.

        Return tuple (result type, inferred operator method type).
        c                    g | ]}|S r   r   )r   r  s     r   ru  z.ExpressionChecker.check_op.<locals>.<listcomp>  s%     ! ! !!D! ! !r   r0  )r|  r:  r}  r[  r~  rD  Nc                6    g | ]}|t          |           fS )r0  )rg   )r   r  rD  s     r   ru  z.ExpressionChecker.check_op.<locals>.<listcomp>  s;     " " " 8D':::;" " "r   TrD  r,  r  LeftRight)r@  r  ro  r  rD  )r   r   r   r   r  r`  r  r,  r  rg   r  r  r   rS  rT  r   r<  r=  r  "warn_both_operands_are_from_unionswarn_operand_was_from_unionr  r   rP  r4   )r  r@  r  r  rD  r,  left_variantsr[  all_resultsall_inferredr  left_possible_typer'  r  results_finalinferred_finalright_variantsright_possible_typer~  r  recent_contexts       `                r   r6  zExpressionChecker.check_op  s     b	&KM'	22I)Y// ! !%:9;S;S;U;U%V%V! ! ! 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C33C7:C7)A%HH"Hc                   | j         d         }|                     |j        |          }t          |                     |j        |          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                            |du           5  |                     ||j        |          }ddd           n# 1 swxY w Y   ||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').r,  rH  )r$  r%  Nr$  r%  )r,  )r  r`  r  r   r-  right_alwaysright_unreachabler  find_isinstance_checkr  REDUNDANT_EXPRr  enabled_error_codesr  redundant_left_operand should_report_unreachable_issuesunreachable_right_operandr  r,  analyze_cond_branchr   r   can_be_truer   can_be_falser   r   )r  r"  rD  r.  r:  expanded_left_typeleft_map	right_mapr[  restricted_left_typeresult_is_lefts              r   r.  z"ExpressionChecker.check_boolean_op  s    #KK,,	<KK$$o
 
 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===
 X##)t2C#DD 	Z 	Z11)QWFXYYJ	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	 1"$$$'''(((45==#-.@#A#A !3!??NNTT\\#,-?#@#@ !3!@@N*O<< 	M 	M(*>
)KLLLs   ?F((F,/F,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.
        r  r,  r  __mul__)r`  r  r~   r4  r  r  r6  r8  )r  r"  r[  r:  r'  r8  s         r   r/  z%ExpressionChecker.check_list_multiplyc  s    
 [[))
j$//."A"ABB 	, AF9J29NOOIIAF++I"mmIy!'1MM#r   r=   c                J   |                      |j                  }| j                            |j        |j                   | j                            |           t          |          s | j                            |j        |           |                     |j                   |S r   )	r`  r  r  check_assignmentrd  check_finalr  r  rN  )r  r"  r  s      r   visit_assignment_exprz'ExpressionChecker.visit_assignment_exprs  s    AG$$!!!(AG444Q(// 	1 H%000,,QX666r   ro   c                    |                      |j                  }|j        }|dk    r|                                 }n5t          j        |         }|                     ||g g |          \  }}||_        |S )z7Type check an unary operation ('not', '-', '+' or '~').not)r`  r   r-  rO  r   unary_op_methodsrP  r8  )r  r"  operand_typer-  r'  r@  r8  s          r   visit_unary_exprz"ExpressionChecker.visit_unary_expr~  sr    {{16**T;;>>++FF/3F"&"@"@WY[]_`"a"aFK'AMr   rO   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   rI  r   r   rJ  )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   )r]  r`  rb  visit_index_with_type)r  r"  r:  s      r   r  z)ExpressionChecker.visit_index_expr_helper  sI    : 	+;;qz***KK''	)))Q777r   ProperType | Nonec                n    j         }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                   S t          |t:                    r[|                                rG|                                j         r. !                    |                                j                   S t          |tD                    r7 #                    |j$        d          s %                    |j$                  S  &                    d|j         gtN          g	          \  }
}|_(        |
S )
zAnalyze 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).
        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   rY  r"  r  r  s     r   ru  z;ExpressionChecker.visit_index_with_type.<locals>.<listcomp>  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>  s,      RRQz!Z88RRRRRRr   zVariadic tuple can have length __getitem__r  ))rG  r   r`  r   r   r  r   r%   r   r   r  r  r5  rb   visit_tuple_slice_helpertry_getting_int_literalsvisit_tuple_index_helperr  r  r   TUPLE_INDEX_OUT_OF_RANGEmin_tuple_lengthra  r   r   r8  nonliteral_tuple_index_helperr   visit_typeddict_index_exprr   r  r  is_enumvisit_enum_index_exprr   r  r  r  rP  r4   r8  )r  r:  r"  r  rG  nsoutrX  r  min_lenr'  r8  s   ` ``        r   r  z'ExpressionChecker.visit_index_with_type  sp    #I..	 	Ei++ 	3 4
 4
1:4
 4
 4
 1
 1
 	3 $Ir22Ii++ 1	)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FFy,//	%%''	 %%''/	
 --i.C.C.E.EqwPQRRR	;// 		!=9
 9
 		 --i.CQVVV"&"@"@y17)gYQ^ #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  r  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   r   ro  r  r  r   r  maxr<  r=  r  )	r  r  rX  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   slicrb   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  rx  )begin_indexr  r  	end_indexstride	itertoolsproductslicer4  r  r  r   !AMBIGUOUS_SLICE_OF_VARIADIC_TUPLEr   r   r8  r  r   )r  r:  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   rG  list[int] | Nonec                   t          |t                    r|j        gS t          |t                    r2|j        dk    r'|j        }t          |t                    rd|j        z  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
        -r,  N)r   rP   r  ro   r-  r   r   r`  r   rJ  r   r4  r   r   r   r  )r  rG  operandrY  r  r  s         r   r  z*ExpressionChecker.try_getting_int_literalsA  sM    eW%% 	0K= y)) 	0x3*gw// 0.//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  r0  r  )rP  r4   union_tuple_fallback_itemr   rb   r  rK  )r  r:  rG  unions       r   r  z/ExpressionChecker.nonliteral_tuple_index_helperc  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   r   r  ro  NotImplementedErrorr   )r  r:  r   r  rz  s        r   r  z+ExpressionChecker.union_tuple_fallback_itemk  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setitemc                r   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                  c S g }|D ]k}	|j                            |	          }
|
8| j                            ||	||           t'          t(          j                  c S |                    |
           lt1          |          S )Nr   )r   rd   r  r   r`  r   r  r   r   r   rJ  r   r  rx  r   r   r  r  $typeddict_key_must_be_string_literalr   r   r8  r  typeddict_key_not_foundr   )r  r  rG  r  	key_namesrY  	key_typesr  value_typeskey_namerI  s              r   r  z,ExpressionChecker.visit_typeddict_index_expr~  s    eW%% 	9II!$++e"4"455C#y)) "(,SY		 E	I,Y77 9 9h11 9h6O6['8H x559"8>3779 !).7;KKK$$X^4444HAA'5QQQ"9#788888! 	/ 	/H **844J!00(E7SSSy344444"":....$[111r   	enum_typec                    |                      d          }| j                            |                     |          ||dd           t	          |g           S )Nr  zEnum index should be a stringzactual index type)r4  r  check_subtyper`  r   )r  r  rG  rD  string_types        r   r  z'ExpressionChecker.visit_enum_index_expr  s\     !OON;;KK+	
 	
 	
 	2&&&r   rA   c                   |                      |j        t          t          j                  dd          }|j        }| j        j        }|j        rCt          t          |          t                    s!||k    r| j                            ||           |j        r+t          |          r| j                            d||           t!          || j        j        | j        j        | j        |           |S )zType check a cast expression.Tr  rZ  ry  zTarget type of castr0  )r`  r   r   r   r1  r   r  r  warn_redundant_castsr   r   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_expr  s    kkI !788"!	 " 
 
 i("(	7{;;WEE	7 {**H##K666* 	[/KK/X/X 	[H001FUYZZZ)48+DdhX\	
 	
 	
 	
 r   r<   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 )Nr,  Tr
  zC"assert_type" expects everything to be "Any" in unchecked functions)r`  r   r  r  rY  r   r   r   r  r   r   rJ  r}   r5  r  ra  assert_type_fail)r  r   r  r  proper_source_types        r   visit_assert_type_exprz(ExpressionChecker.visit_assert_type_expr  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   r_   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.Nr,  Tr  rZ  z9'reveal_type' always outputs 'Any' in unchecked functionsc                (    i | ]}|j         |j        S r   )r7  r   )r   var_nodes     r   r  z7ExpressionChecker.visit_reveal_expr.<locals>.<dictcomp>  s    SSShX]HMSSSr   )rS  r:   r   r`  r  r  rY  r  reveal_typer5  ra  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  r  zName "z" is not definedr  )      typingtyping_extensionszXDid you forget to import it from "{module}"? (Suggestion: "from {module} import {name}"))moduler7  )r  UNIMPORTED_REVEALr  r  r  rS  r9   r:   is_importedr  python_versionr~  ra  )r  r   r7  r(  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   tapprj   c                   t          |j        t                    rt          |j        j        t                    rnt          |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                            t.          j        |           t3          t4          j                  S t          |                     |j                            }t          |t:          t<          f          rU|                                s%| j                            t.          j        |           |                     ||j        |          S t          |t2                    rt3          t4          j         |          S t3          t4          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   r^   r   r   r   r   r  r  r  r  r   r   r   r   r4   apply_type_arguments_to_callablero  r   r1  r  r   r  r   ONLY_CLASS_APPLICATIONr   r   r8  r`  r   r   r  r  r1  )r  r-  r  r  s       r   visit_type_applicationz(ExpressionChecker.visit_type_application  s    di)) 	5j.S.S 	5)	
	&  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   aliasri   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`.
        Tr-  )rA  r   )r  r2  s     r   visit_type_alias_exprz'ExpressionChecker.visit_type_alias_expr@  s"     11%*%Z^1___r   )r/  r   r/  c          
        t          |j        t                    r%|j        j        rt	          t
          j                  S | j        j        j	        o| j
        }t          t          ||j        |j        | j        j        || j        j                            }t          |t                    r?t#          |j        | j                  }|j        r|S |                     ||j        |          S t          |t.                    rDt1          |          j        j        dk    r't#          t1          |          j        | j                  S t          |t4                    r|                     |          S t          |t                    rt	          t
          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  r  ztyping._SpecialForm)r   rd  r   invalidr   r   r8  r  r  disallow_any_genericsr  r   r   r<  r=  r  r  r   r   r4  r  r/  ro  r   r   r   r   r  r  r1  )r  r2  r.  r/  r6  r  r  s          r   rA  z/ExpressionChecker.alias_type_in_runtime_contextN  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===g&& 	:95$GGGG 7y5666??#8999r   r   c                   |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                  }t/          || j	        j
        d          sFt1          || j	        j
        | j	        j        d| j	        j                   t#          |j                  }t7          d t9          |          D                       }	t          |          |	z
  d	z
  }
||	         }t          |t:                    sJ t=          t?          |          |	|
          \  }}}t#          |          tA          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>  s-      MM1z!-=>>MMMMMMr   )r<  r=  T)empty_tuple_indexF)r6  r  c              3  J   K   | ]\  }}t          |t                    |V  d S r   r;  )r   rp  r  s      r   r   z7ExpressionChecker.split_for_callable.<locals>.<genexpr>  s6      YYFQAGW9X9XYaYYYYYYr   r   )"r  r   r  r   r   r   r   r   r   r  r  r2   r  r   r8  r  r  r  r  r  r   r<  r=  r   r   ra  ro  nextrf  r   r   tupler   r   )r  r   ro  r.  varstvr  r  fakeprefixsuffixtvtstartr  r  s                  r   split_for_callablez$ExpressionChecker.split_for_callable  sR    {$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                    rt          |j                  t                    k    rt          d |j        D                       s|                                r|                                j        dk    r|S  j	        
                    t          |j                  t                               t          t          j                  S                      |                     |                    S t          |t                     r|j        D ]}t          |j                  t                    k    rtt          d |j        D                       sV j	        
                    t          |j                  t                               t          t          j                  c S t!           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   | ]}t          |t                    V  d S r   r;  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s>       : :45
1.//: : : : : :r   r  c              3  @   K   | ]}t          |t                    V  d S r   r;  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s>       > >89Jq"233> > > > > >r   c           
     h    g | ].}                     |                    |                    /S r   )r  rG  )r   r   ro  r.  r  s     r   ru  zFExpressionChecker.apply_type_arguments_to_callable.<locals>.<listcomp>  sP        00T5L5LRQUWZ5[5[]`aa  r   )r   r   r   r  r  r  r  r  r   r  incompatible_type_applicationr   r   r8  r  rG  r   r   r1  )r  r  ro  r.  r   s   ` `` r   r/  z2ExpressionChecker.apply_type_arguments_to_callable  s    R  b,'' 		a2<  CII--c : :9;: : : 7 7- >>## (8(8(AEU(U(UI66s2<7H7H#d))UXYYYy3444//D4K4KBPTVY4Z4Z\_```b*%% 	h 9 9r|$$D		11# > >=?\> > > ; ;1 H::3r|;L;LcRViiY\]]]"9#788888      h     y-...r   rS   c                0    |                      |dd          S )z#Type check a list expression [...].r?  z<list>check_lst_exprr  s     r   visit_list_exprz!ExpressionChecker.visit_list_expr  s    ""1ox@@@r   ra   c                0    |                      |dd          S )Nr   z<set>rN  r  s     r   visit_set_exprz ExpressionChecker.visit_set_expr  s    ""1ng>>>r   ListExpr | SetExpr | TupleExprcontainer_fullnamec                   | j         d         }|rdS | j                            |d          }|t          |t                    r|ndS g }|j        D ]X}t          |t                    rt                      | j        |<    dS |                    | 	                    |                     Yt          j        |          }t          |          st                      | j        |<   dS | j                            ||g          }|| j        |<   |S )aY  
        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
         - no star expressions
         - the joined type of all entries must be an Instance or Tuple type
        r,  N)r  r  r  r   r   r   rc   r   r  r`  r   rv  r   r  rK  )	r  r"  rT  r.  rtr  r  vtcts	            r   fast_container_typez%ExpressionChecker.fast_container_type  s    # 	4##At,,>#B11;22t;G 	- 	-D$)) (0

"1%ttMM$++d++,,,, ((+B// 	$,JJDq!4X(();bTBB "1	r   tagc           
        |                      ||          }|r|S t          d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Tr,  r  r  r  defaultr+  r7  r  c                J    g | ] }t          |t                    r|j        n|!S r   )r   rc   r   r   rp  s     r   ru  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   rc   r   r5   r4   ra  s     r   ru  z4ExpressionChecker.check_lst_expr.<locals>.<listcomp>'  s0    ]]]PQ
1h 7 7JennU]]]]r   r   )rY  r   rC  r   r   from_omitted_genericsr   r   r5   r  rK  r4  r  r   r!   )r  r"  r   rZ  r   rA  constructorr  s           r   rO  z ExpressionChecker.check_lst_expr	  s   $$Q11 	H ((**I;<<
 
 
 #D^FH''2$77OO/00d
 
 
 ooIIIII]]UVU\]]]	
 

  1555r   rh   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   rc   r   r"  s     r   ru  z;ExpressionChecker.tuple_context_matches.<locals>.<listcomp>1  s'    MMMaZ85L5LMMMMr   c                <    g | ]}t          |t                    |S r   rg  rh  s     r   ru  z;ExpressionChecker.tuple_context_matches.<locals>.<listcomp>4  s'    AAAaAx)@)@AAAAr   r   Fc              3  J   K   | ]\  }}t          |t                    |V  d S r   rg  )r   rp  lvs      r   r   z:ExpressionChecker.tuple_context_matches.<locals>.<genexpr>6  s7      ``UQzRTV^G_G_`q``````r   )r   r   r  r>  rf  )r  r   r.  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.r,  Nc                    g | ]D}t          |t                    r                    |          st          |t                    B|ES r   )r   r   rn  r   r   )r   r   r"  r  s     r   ru  z6ExpressionChecker.visit_tuple_expr.<locals>.<listcomp>?  sh     ! ! !q),,! 261K1KAq1Q1Q! %Q(ABB	!! ! !r   r   r   Fr  z<tuple>T)"r   r  r   r   r   r   r  r   rn  r   r   r   ro  r   rs   r  r  r2  r  rc   r   r   r`  r   rO  rA  r3  r4  rK  r  r   r   r1  r%   )r  r"  r  type_context_itemstuples_in_contextunpack_in_contextseen_unpack_in_itemsallow_precise_tuplesr   rt  rp  r  ctx_itemr.  ttrX  r  fallback_itemr'  s   ``                 r   visit_tuple_exprz"ExpressionChecker.visit_tuple_expr9  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   rG   c                   | j         d         }|rdS | j                            |d          }|t          |t                    r|ndS g }g }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 |                    |                     |                     |                    |                     |                     t          j        |          }
t          j        |          }t!          |
          rt!          |          st                      | j        |<   dS |r0|d         |
k    s|d         |k    rt                      | j        |<   dS | j                            d|
|g          }|| j        |<   |S )a~  
        Fast path to determine the type of a dict literal,
        based on the list of entries. This mostly impacts large
        module-level constant definitions.

        Limitations:
         - no active type context
         - only supported star expressions are other dict instances
         - the joined types of all keys and values must be Instance or Tuple types
        r,  NrB  r  r   r   )r  r  r  r   r   r   r   r`  r   r   r  ro  r   r  r   rv  r   r  rK  )r  r"  r.  rV  r  r  stargsr  r  stktrW  dts                r   fast_dict_typez ExpressionChecker.fast_dict_type  s    # 	4##At,,>#B11;22t;+/' 	2 	2JC{$T[[%7%788r8,, (O;;BG)) gaj"'!*5FF,4JJD&q)44DKK,,---dkk%001111 && ((,R00 	5QRT5U5U 	$,JJDq!4 	vayB&)r//$,JJDq!4X((2r(CC "1	r   typeddict_contextc                    |                      ||j        |d           }t          |          }t          |t                    r|                                S |                                S )N)r  r  rD  r  )r  r   r   r   r   r  )r  r"  r  r3  r;  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|                     ||d                   S |D ]}| j                                        5 }| 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 | j        
                    ||           |                     |          }|r|S t          dddg |                                 t          t          j                            }t          d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        |_        |
                    |           |                    t3          ||	g|                     d
                               t7          |t8          j        gt          |          z  dgt          |          z  | j                            d||	g          |                     d          d||	g          }|                     ||
t8          j        gt          |
          z  |          d         S )zoType check a dict expression.

        Translate it into a call to dict(), with provisions for **expr.
        r,  r   r   NKTr]  VTrl  r  rB  r+  z<dict>r_  )find_typeddict_contextr  r  r  r  r,  r  r-  r  r  typeddict_context_ambiguousr  r   rC  r   r   rc  r   r  rK  rh   r<  r=  end_line
end_columnr   r4  r   r   r4   r  )r  r"  typeddict_contextsr  r  tmapr;  r~  r}  rW  ro  r  r  r  tuprd  s                   r   visit_dict_exprz!ExpressionChecker.visit_dict_expr  s    "889J29NPQRR 	H%&&!++>>qBTUVBWXXX%7    !X++-- ]dh6M6M6O6O ]SW#FFqJ[\\H] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]%%'' $$T***H001CQGGG   ## 	I ((**I;<<
 
 
 ((**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   0C
B-!C-B11C4B15CC	C		dict_exprlist[TypedDictType]c                2   t          |          }t          |t                    r|gS t          |t                    rZg }|j        D ]N}|                     ||          }|D ]3}|                     ||j        |          r|                    |           4O|S g S r   )r   r   r   r   r   r  r  r  )r  rD  r  r   r  item_contextsitem_contexts          r   r  z(ExpressionChecker.find_typeddict_context.  s     "'**g}-- 	9++ 		E 3 3 $ ; ;D) L L$1 3 3L::$ioy  3 \222	3
 L	r   rQ   c                   | j                             |d           |                     |          \  }}|s| j         j                            t          t          j                             | j         j        	                    |          5  |j
        j
        dd         D ]}|                    | j                    |                     |                                d          }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                             |                                          s)|                     |                                d           | j                             |                                          }| j         j                                         t-          ||          S )	zType check lambda expression.F)body_is_trivialNr,  Tr\  r+  )type_override)r  check_default_argsinfer_lambda_type_using_contextr  r  r   r   r1  r;  push_functionbodyr`  r   r4  popr   r;  tscopefunction_scopecheck_func_itemr  r  replace_callable_return_type)r  r"  r?  r  stmtr;  rx  s          r   visit_lambda_exprz#ExpressionChecker.visit_lambda_exprA  s   ##Au#==='+'K'KA'N'N$} 	IH!((1G)H)HIII --a00 	I 	I FK, * *DKK))))  ;;qvvxx4;HH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I ':;;HH!%%''' 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.. >AFFHH===x++AFFHH55HH!%%'''/xHHHs%   AC44C8;C8F//F36F3/tuple[CallableType | None, CallableType | None]c                0  	 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        dS d |j        D             }|j        s|                                X|                    dt5          t6          j                  gt          |          z  ||j                                                  }t>          |v s	t@          |v r|dfS |j!        |k    r'| j        "                    tF          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.
        r,  c                <    g | ]}t          |t                    |S r   r  r  s     r   ru  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>n  s9       ZPQS_E`E`  r   r   r   NNc                D    g | ]}|j                                         |S r   )r  is_meta_var)r   rA  s     r   ru  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s+    XXXBBEDUDUDWDWXRXXXr   c                    g | ]}|v|	S r   r   )r   rA  
extra_varss     r   ru  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s#    "R"R"R"Rz=Q=Q2=Q=Q=Qr   )r;  r  r+  r  Nc                    g | ]	}|j         
S r   )rS  )r   r  s     r   ru  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   rA  r  r"   r;  r   r  r  r   r4  r  	argumentsr  r  r   r   r1  r  r  r5   r6   r  r  r   CANNOT_INFER_LAMBDA_TYPE)
r  r"  r.  r  r  	meta_varscallable_ctxr  r  r  s
            @r   r  z1ExpressionChecker.infer_lambda_type_using_contextb  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``". :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   re   c                l   |                      |          }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    rw|j        r3|j        j        r'|
|d         k    rt          t          j                  c S t7          |j        |ddd||
|| j        | j        |                                           c S J d            )	z+Type check a super expression (non-lvalue).N)is_classmethodr,  r   FT)r7  rY  r  r  r  r  override_inforD  r  r  r  r  )_super_arg_typesr   r?  type_info_from_typer  r  r   UNSUPPORTED_ARG_1_FOR_SUPERr   r   r8  UNSUPPORTED_ARG_2_FOR_SUPERr  rG  r;  top_functionr   is_classr  r  !SUPER_ARG_2_NOT_INSTANCE_OF_ARG_1r  TARGET_CLASS_HAS_NO_BASE_CLASSr7  rQ  r  r1  r   r  rI  )r  r"  r   	type_typeinstance_type	type_infoinstance_infor  rG  r@  rb  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^0022F !&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  r5  r   r   r#  r  callro  r  r8  r;  active_classr  r   %SUPER_OUTSIDE_OF_METHOD_NOT_SUPPORTEDr   r   r  r  variabler   (SUPER_ENCLOSING_POSITIONAL_ARGS_REQUIREDr5   r  SUPER_VARARGS_NOT_SUPPORTEDr   r4   SUPER_POSITIONAL_ARGS_REQUIRED#SUPER_WITH_SINGLE_ARG_NOT_SUPPORTEDr   r`  TOO_MANY_ARGS_FOR_SUPERr   r  r  r   r  r  %first_argument_for_super_must_be_type)r  r"  current_typer  r@  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^0022F%%% 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          |          }|j        |j        |j        fD ]@}|r<|                     |          }| j                             |||t          j
                   A|                     d          S )Nztyping_extensions.SupportsIndexr  zbuiltins.slice)r  r4  rP  r   r  r  r  r`  r  r   INVALID_SLICE_INDEX)r  r"  supports_indexexpectedrG  r   s         r   visit_slice_exprz"ExpressionChecker.visit_slice_exprU  s    	A!X001RSSNN 	A 	A 	A!X00@@NNN	A%n55mQ[!(; 	a 	aE aKK&&&&q(E;K;_```/000s    $AArR   c                :    |                      |j        dd          S )Nr?  z<list-comprehension> check_generator_or_comprehension	generatorr  s     r   visit_list_comprehensionz*ExpressionChecker.visit_list_comprehensiona  s$    44K*@
 
 	
r   r`   c                :    |                      |j        dd          S )Nr   z<set-comprehension>r  r  s     r   visit_set_comprehensionz)ExpressionChecker.visit_set_comprehensionf  s$    44K)>
 
 	
r   rN   c                    t          |j                  st          |j                  rd}t	                      g}nd}t	                      t	                      g}|                     ||d|          S )Nztyping.AsyncGeneratortyping.Generatorz<generator>)additional_args)r  is_asyncr   r}  r   r  )r  r"  rY  r  s       r   visit_generator_exprz&ExpressionChecker.visit_generator_exprk  su     qz?? 	721;?? 	7)C+3::,OO$C'zz8::6O44sM? 5 
 
 	
r   genr  id_for_messagesr  list[Type] | Nonec                8   |pg }| j         j                            dd          5  |                     |           t	          d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   can_skipfall_throughr\  r,  r]  Nr+  r_  )r  r  frame_contextcheck_for_compr   rC  r   r   rc  r   r   r4   rK  r4  r  r}  )r  r  r  r  r  rA  tv_listrd  s           r   r  z2ExpressionChecker.check_generator_or_comprehensionz  s~    */RX_**Dq*II 	Z 	Z$$$  ,,..	 ?@@  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rH   c                   | j         j                            dd          5  |                     |           t	          dddg |                                 t          t          j                            }t	          d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  r,  r]  r  r  NrB  r+  z<dictionary-comprehension>r_  )r  r  r  r  r   rC  r   r   rc  r   r   r4   rK  r4  r  r  r  )r  r"  ktdefvtdefrd  s        r   visit_dictionary_comprehensionz0ExpressionChecker.visit_dictionary_comprehension  s   X_**Dq*II  	  	"""   ,,..	 ?@@  E   ,,..	 ?@@  E '.t++OeU^LL##$7881 %.  K ??aeQW-u}/Mq = 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	s   D6E%%E),E)'GeneratorExpr | DictionaryComprehensionc                p   t          |j        |j        |j        |j                  D ]\  }}}}|r| j                            |          \  }}n| j                            |          \  }}| j                            ||d|           |D ]}| 	                    |           | j        
                    |          \  }	}
|	r| j                            |	           t          j        | j        j        j        v r;|	| j                            d|           |
| j                            d|           d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.
        TNF)r  indices	sequences	condlistsr  r   analyze_async_iterable_item_typeanalyze_iterable_item_typeanalyze_index_variablesr`  r  push_type_mapr  r  r  r  r  $redundant_condition_in_comprehension)r  r"  rG  sequence
conditionsr  r  sequence_type	conditiontrue_map	false_maps              r   r  z ExpressionChecker.check_for_comp  s[    69Iq{AK6
 6
 	W 	W1E8Z  Q#'8#L#LX#V#V ==#'8#F#Fx#P#P =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   rD   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                            |          sQ|}	t          t          |	                    p|	}
|t'          |
|          s|                     ||j        |
|          }n'||k    r|}	n|                     ||j        ||          }	t)          t          | j        d                   t*                    rt-          ||g          }nt/          j        ||	          }|S )Nr,  FT)rD  rZ  )r`  condr  r  r  r  r  r  r  r  redundant_condition_in_ifr  if_exprr   r   	else_exprr  r  rJ  r|   r   r   r   r   rY  )r  r"  rZ  r.  if_mapelse_mapif_typeif_type_fallbackfull_context_else_type	else_typeelse_type_fallbackr  s               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27;; $	.I "5_Y5O5O!P!P!]T] {-0BC"H"H{ 22I.&7	 3   $$ /II 00("3	 1  I od&7&;<<iHH 	6-w8N.OPPCC/'955C
r   r  dict[Expression, Type] | Nonec                D   | j         j                            dd          5  |2|                     |||           t	                      cd d d            S | j                             |           |                     |||          cd d d            S # 1 swxY w Y   d S )NTr   r  r  )r  r  r  r`  r   r  )r  r  r   rD  rZ  s        r   r  z%ExpressionChecker.analyze_cond_branch)  s     X_**Dq*II 	` 	`{ DwJ[\\\&((	` 	` 	` 	` 	` 	` 	` 	` H""3''';;t'M^;__	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	`s   (B1BBBry  r  c                n   || j         v r| j         |         S d}| j        r#| j        st          j                    }d| _        d}| j                            |           | j        }|| _        	 |r-t          |t                    r| 
                    |d          }	n|r-t          |t                    r|                     |d          }	ns|r-t          |t                    r|                     |d          }	nD|r-t          |t                    r|                     |d          }	n|                    |           }	nR# t$          $ rE}
t'          |
| j        j        j        |j        | j        j        | j        j                   Y d}
~
nd}
~
ww xY w|| _        | j                                         |	J | j                            ||	           | j        j        j        r]|s[| j        j        sO| j                                        r6t=          |	          r'| j        j        s| j         !                    |	|           | j                                        r| j        j        rtE          tF          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.
        FTr\  N)&r  r  r  timeperf_counter_nsr  r  r  r   r@   ra  rr   visit_yield_from_exprrD   r
  r>   visit_await_exprr`  	Exceptionr$   r  rX  filer<  r  r  r  disallow_any_expris_stubr5  r  rY  r  disallowed_any_typer   r   r#  r  )r  r   r  rZ  ry  r  record_timet0old_is_calleerY  r  r'  s               r   r`  zExpressionChecker.accept=  s    4&&&&t,,+ 	D4F 	%''B!%DK  ..."	  	(Zh%?%? 	(**44*HH" (z$'F'F (000NN" (z$'H'H (11$$1OO" (z$	'B'B (++DD+II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   ,CD> >
F;FFr7  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  r4  )r  r7  s     r   r4  zExpressionChecker.named_type|  s     x""4(((r   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?r2  )r   r   r   r   r   r   r~   r  rK  r   r1  r  s     r   rn  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?rl  r  )
r~   r  rK  r4  r   r   r1  r   r   r   r  s     r   rp  z*ExpressionChecker.is_valid_keyword_var_arg  s     ++6__^44gi>T6U6UV   . ++69J9JOL]L]8^  . #}--	
r   c                &    t          |          }t          |t                    rt          |j                  }t          |t                    rt          |          }t          |t                    r|j        }t          |t                    r|j	        
                              S t          |t                    r3|                                r|j        j	        
                              S t          |t                    rdS t          |t                    r0t           fd|                                D                       }|S t          |t"                    r|j        }t          |t                    rt          |j                  }t          |t                    rt          |          }t          |t                    r,|j	        j                              |j	        j                  S t          |t                    rdS dS dS )z*Does type have member with the given name?Tc              3  D   K   | ]}                     |          V  d S r   )r  )r   xr  r  s     r   r   z/ExpressionChecker.has_member.<locals>.<genexpr>  s1      RRF33RRRRRRr   NF)r   r   r   r  r   r   r   rx  r   r   has_readable_memberr   r  r   r   r   r  r   r  metaclass_typer  )r  rY  r  r'  r  s   ` `  r   r  zExpressionChecker.has_member  s    c""c;'' 	3!#/22Cc9%% 	& %%Cc;'' 	,Cc8$$ 	88//777c<(( 	S__->-> 	<$88@@@W%% 	4Y'' 	RRRRRS=O=O=Q=QRRRRRFMX&& 	 8D$,, 9&t'788$	** ,%d++$)) Idi.F.Rty'?HHH$(( t55r   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  r6  )r  r7  rD  s      r   not_ready_callbackz$ExpressionChecker.not_ready_callback  s"     	--dG<<<<<r   rq   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 )Nr,  Factual typeexpected type)r  r  get_generator_yield_typer   r   r   r   r   r5  r  r   YIELD_VALUE_EXPECTEDr`  r  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_expr  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   r>   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 )Nr,  typing.Awaitabler  )r  r  rK  r   r`  r   r   r   r   r  check_awaitable_exprr   INCOMPATIBLE_TYPES_IN_AWAITr   r  r  )r  r"  rZ  expected_typer]  rL  s         r   r  z"ExpressionChecker.visit_await_expr  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`.
        r0  r%  r&  	__await__r   F)r  r  r4  r   r   r1  rP  get_generator_return_typer   r   r   r  r  r  )r  r   r.  r  r5  r  r;  s          r   r1  z&ExpressionChecker.check_awaitable_expr  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   rr   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          |          }t          |t.                    r,|j        j        dk    r| j                             |d          }nNt          |
          }
t          |
t                    rt          t          j        |
          }nt7                      }|sBt          t          |          t6                    r | j         j                            d |           |S )	Nr,  r  r  __iter__r0  Fr%  r&  )r  r  r   r`  r   r   r   r   r  r3  is_async_defhas_coroutine_decoratorr  yield_from_invalid_operand_typer1  rK  rP  r8  r1  r    INCOMPATIBLE_TYPES_IN_YIELD_FROMr'  r  r   r   r   r8  r   r  )r  r"  rZ  r+  subexpr_type	iter_typer  generic_generator_typer  r,  r-  	expr_types               r   r  z'ExpressionChecker.visit_yield_from_expr  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& &"  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..	i** 
	'y~/FJ\/\/\::9eLLII  //?@@*G44 '#I$>K[\\\		 %JJ	  	8Z	0J0JH%U%U 	8HL..tQ777r   rg   c                    |j         S r   r   r  s     r   visit_temp_nodez!ExpressionChecker.visit_temp_nodeJ  	    vr   rm   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  $   K   | ]
}|k    V  d S r   r   )r   r  	p_defaults     r   r   z8ExpressionChecker.visit_type_var_expr.<locals>.<genexpr>U  s(      #M#M5I$6#M#M#M#M#M#Mr   z3TypeVar default must be one of the constraint types)r   r^  r   r   type_of_anyr   rc  r~   r  r  r  r  r  r1  )r  r"  rI  s     @r   visit_type_var_exprz%ExpressionChecker.visit_type_var_exprM  s    #AI..	y'**	X%)HHHi77 XSUVWWWx X#M#M#M#MAH#M#M#M M M XSUVWWWy-...r   r[   c                4    t          t          j                  S r   r   r   r1  r  s     r   visit_paramspec_exprz&ExpressionChecker.visit_paramspec_exprY      y-...r   rn   c                4    t          t          j                  S r   rM  r  s     r   visit_type_var_tuple_exprz+ExpressionChecker.visit_type_var_tuple_expr\  rO  r   rX   c                4    t          t          j                  S r   rM  r  s     r   visit_newtype_exprz$ExpressionChecker.visit_newtype_expr_  rO  r   rV   c                "   |j         j        }|ri| j        j        j        r+t          |          r| j                            d||           t          || j        j        | j        j	        | j        |           t          t          j                  S )NzNamedTuple typer0  )r  
tuple_typer  r  r  r   r  r  r   r  r   r   r1  )r  r"  rU  s      r   visit_namedtuple_exprz'ExpressionChecker.visit_namedtuple_exprb  s    V&
 	x7 W<X= = W 445F
TUVVV"DH,dh.G[\    y-...r   rJ   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  r`  r   r   r   r  rQ  r   rp   r   r  r   r1  )r  r"  r7  r  rY  r@  s         r   visit_enum_call_exprz&ExpressionChecker.visit_enum_call_exprn  s    qw11 	/ 	/KD% kk%((!/#"6"6@@ /&,t,1C!#s++ /
 $'*.y-...r   rk   c                4    t          t          j                  S r   rM  r  s     r   visit_typeddict_exprz&ExpressionChecker.visit_typeddict_expr}  rO  r   r]   c                    |j         S r   rD  r  s     r   visit__promote_exprz%ExpressionChecker.visit__promote_expr  rF  r   rc   c                6    |                      |j                  S r   )r`  r   r  s     r   visit_star_exprz!ExpressionChecker.visit_star_expr  s    {{16"""r   c                ,    |                      d          S )zReturn instance type 'object'.rO  r  r   s    r   rC  zExpressionChecker.object_type  s    0111r   c                ,    |                      d          S )zReturn instance type 'bool'.rH  r  r   s    r   rO  zExpressionChecker.bool_type  s    ///r   
known_typec                    d S r   r   )r  r   rb  s      r   r&  z)ExpressionChecker.narrow_type_from_binder  s    r   r  c                    d S r   r   )r  r   rb  r  s       r   r&  z)ExpressionChecker.narrow_type_from_binder  s	     	r   c                    t          |          t          k    ru| j        j                            |          }|rTt          t          |          t                    r| j        j        s&|rt          ||d          sdS t          ||          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)r,   r8   r  r  r  r   r   r   rY  r.   r/   )r  r   rb  r  restrictions        r   r&  z)ExpressionChecker.narrow_type_from_binder  s     4==L(((/--d33K  E?:66@@EEIXEcE (  0D41 1 1    4+JDDD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   rj  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_callrl  s      r   rj  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   )
r  r
  r  r1   r  rx   r  r  r   r  r   r  )r"  rW   r   r   F)r"  r^   r)  r   r   r   )r@  rp   rD  rE   r   r   )r   rU   r   r   )r"  r@   rZ  r   r   r   )rb  rK   r   r   )r"  r@   r   r  )rC  r   r  r  r   r  r   rK   r   r   )r  r  r   r   )r  r   r  r  r  r  ro  r  rD  rE   r  r  r   r   )r  r  r  r   r   r  )
r  rK   r  r   r'  r  r  r   r   r   rY  r   r   r   )r  r   r  r  rD  rE   r   r   )
r  r   r  r  rD  rE   r  r  r   r   )r  rl   r   r   )r  r   r   r   )r  r   r  r  rD  rE   r  r  r  r   r   r   )r   rT   r   r8  )rP  r^   r   rQ  )r"  r@   rT  r  r@  rp   r   rU  )r  r   r  r  r  r\  r  r]  rw  r^  ro  r  r   r  rC  r  rD  rE   r   r   )r  r   ro  r  r  r  r  r]  rt  ru  r   r   )r  r   ro  r  r  r  rD  rE   r  r]  r~  r  r   r   )r  r   ro  r  r  r  rD  rE   r  r]  rC  r   r~  r  r   r   r  )r  r  r  r   ro  r  r  r  rD  rE   r  r]  rC  r  r   r   )r  r   ro  r  r   r  )r  r   r  r   r.  rE   r   r  r   )r  r   r"  r@   r  r  rC  r  r  r  r   r   )r"  r@   rC  r   r  r  r   r   )NNNNN)r  r   ro  r  r  r  rD  rE   r  r]  r  r  r  r  rC  r  r  r  r   r  )r  r   ro  r  r  r  rD  rE   r  r]  r  r  r  r  rC  r  r   r  )r   rl   r  r  r   r   )r  r   rD  rE   r   r   )ro  r  r   r\  )r  r   r   r   )
r  r   ro  r  r  r  rw  r^  r   r\  )r  r   r  rE   r   r   )r  r   ro  r  r  r  r  r]  rw  r^  r  r   rD  rE   r   r   )r  r   ro  r  r  r  r  r]  rw  r^  r+  r,  r  r   rD  rE   r   r-  )r   r)   )r  r   ro  r  r  r\  rw  r^  r3  r4  r   r5  )r  r   r  r,  rD  rE   r   r   )r  r   r@  r\  rA  r  rB  r]  rw  r^  rD  rC  rC  r  r  r  r   r   )r  r   r@  r\  rA  r  rB  r]  rP  r  rD  rE   r   rU  )rC  r   r  r  rD  rE   r   r  )r  r\  r  r  ro  r  r  r   rw  r^  rD  rE   rc  rd  rC  r  r   r  )r  r   r  r   r  r;   r  r   rX  r4  r  r4  r  r   rC  r  rD  rE   r  rE   r   r  )r  r   ro  r  r  r  r  r]  r  r  rC  r  rD  rE   r   r  )
r  r\  r  r  r  r]  r   r   r   r  )r  r  ro  r  r  r\  r  r  r  r]  r  r  rC  r  rD  rE   r   r  )r  r  r  r\  r  r  r  r]  ro  r  rD  rE   r   r  )r  r\  r  r  r   r   r$  )r  r  ro  r  r  r\  r  r  r  r]  r  r  rC  r  r  r   rD  rE   r  r4  r   r  r  )r  r  r  r  r   r  )r   r  r   r  )r  r\  r  r  r  r]  ro  r  r  r   rD  rE   r   r   )
r  r   r   r,  rD  rE   r
  r   r   r   )ro  r  r  r   r   r  )r  r   ro  r  r  r  r  r]  rD  rE   r   r  )r"  rT   r  r   r   r   )r  r  r  r   rD  rE   r   r   )r   r   )r  r   r  r  r   r   )r  r   r  r   r   r   )r"  rP   r   r   )r"  rd   r   r   )r"  r?   r   r   )r"  rL   r   r   )r"  rC   r   r   )r"  rI   r   r   )r"  rY   r   r   )r"  rB   r   r   )r   rK   r   r  )r  r   r  r   rG  r  ri  rj  rH  r   r   r   )r@  r  r  r   ro  r  r  r  rD  rE   r  r  r   r  )r@  r  r  r   ro  r  r  r  rD  rE   r  r  r   r  )r  r  r  r   r8  r   ro  r  r  r  rD  rE   r   r  )r|  r  r:  r   r}  rK   r[  r   r~  rK   rD  rE   r   r  )r@  r  r  r   r  rK   rD  rE   r,  r   r   r  )r"  rY   rD  rE   r   r   )r"  r=   r   r   )r"  ro   r   r   )r"  rO   r   r   )r:  r   r"  rO   r  r  r   r   )r  r   r   r4  )r  r   rX  r4  r   r  )r:  r   r  rb   r   r   )rG  rK   r   r  )r:  r   rG  rK   r   r   )r:  r   r   r   )r  r   rG  rK   r  r   r   r   )r  rl   rG  rK   rD  rE   r   r   )r   rA   r   r   )r   r<   r   r   )r   r_   r   r   )r   r_   r   r  )r-  rj   r   r   )r2  ri   r   r   )r2  r   r.  rE   r/  r   r   r   )r   r   ro  r  r.  rE   r   r\  )r  r   ro  r  r.  rE   r   r   )r"  rS   r   r   )r"  ra   r   r   )r"  rS  rT  r  r   r  )r"  rS  r   r  rZ  r  r   r   )r   rh   r.  r   r   r   )r"  rh   r   r   )r"  rG   r   r  )r"  rG   r  r   r   r   )r"  rG   r   r   )rD  r  r  rG   r   r  )r"  rQ   r   r   )r"  rQ   r   r  )r"  re   r   r   )r"  re   r   r  )r"  rb   r   r   )r"  rR   r   r   )r"  r`   r   r   )r"  rN   r   r   )
r  rN   r  r  r  r  r  r  r   r   )r"  rH   r   r   )r"  r  r   r  )r"  rD   rZ  r   r   r   )
r  r  r   rK   rD  r  rZ  r   r   r   )NFFF)r   rK   r  r  rZ  r   ry  r   r  r   r   r   )r7  r  r   r   )rY  r   r  r  r   r   )r7  r  rD  rE   r   r  )r"  rq   r   r   )r"  r>   rZ  r   r   r   )
r   r   r.  rE   r  r4  r5  r   r   r   )r"  rr   rZ  r   r   r   )r"  rg   r   r   )r"  rm   r   r   )r"  r[   r   r   )r"  rn   r   r   )r"  rX   r   r   )r"  rV   r   r   )r"  rJ   r   r   )r"  rk   r   r   )r"  r]   r   r   )r"  rc   r   r   )r   r   )r   rK   rb  r   r   r   )r   rK   rb  r   r  r   r   r  )r  r   r  r   r   r   )r   r   r   r   __annotations__r  r!  r(  r%  r2  r?  ra  re  r_  r  r  r  r  r  r  r  r  r  r  r  r  r:  r  r  r=  r@  rC  r  rE  rF  rs  r|  r  r  r  r  r  r  r  r  r.  r  r  r  r  r  r  r*   r  r  r  r$  r  rF  rJ  r  rc  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r
  rI  rK  r  r  r  r  r  r   r"  rA  rg  rN  rW  rP  rv  rw  r  r6  r.  r/  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r  r1  r4  rA  rG  r/  rP  rR  rY  rO  rn  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r`  r4  rn  rp  r  r#  r.  r  r1  r  rE  rK  rN  rQ  rS  rV  rY  r[  r]  r_  rC  rO  r   r&  r  rj  r   r   r   r	  r	  '  s#          "!!!#### 0///****NNN O  O  O  OD       7 7 7 7> > > > >@3 3 3 3   2	R 	R 	R 	R 	R
 
 
 
N N N N N`G G G G   8   ,   ,	M 	M 	M 	M_ _ _ _(- (- (- (-T0+ 0+ 0+ 0+d6 6 6 6pR R R R   1 1 1 1(
 
 
 
0
 
 
 
Y Y Y Yv   0 #	*1 1I    
 #_$56"_$56$,.?#@!NO#DE	A AN    &+ &+ &+ &+P	" 	" 	" 	") ) ) )VE E E EN% % % %@
 
 
 
$
 
 
 
> 26#'' ' ' ' 'R   &= = = =H "1 1 1 1 1f* * * *F 26+/$(#'%)uY uY uY uY uYnu' u' u' u'n   0*- *- *- *-X        #% #% #% #%JN
 N
 N
 N
`GR GR GR GRR6* 6* 6* 6*p
 
 
 

- - - -^Q Q Q Q8 $($(> > > > >@;+ ;+ ;+ ;+z   , (,#'K K K K KZ&_ &_ &_ &_PD D D DL3& 3& 3& 3&jQ6 Q6 Q6 Q6f   *$ $ $ $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 7 7 7 7 7! ! ! !F
 
 
 
(; ; ; ;   6
 
 
 
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#oN oN oN oN oN oNp &*"` "` "` "` "`V &*K K K K K8
 
 
 
<r r r rt $o o o o obMM MM MM MM^    	 	 	 	
 
 
 
    8 8 8 8 QUD D D D DL! ! ! !.
 .
 .
 .
`, , , ,@       D   , , , ,( JO#2 #2 #2 #2 #2J' ' ' '   .   4   >D D D D.'/ '/ '/ '/R` ` ` ` KP8: 8: 8: 8: 8: 8:t1W 1W 1W 1Wf#/ #/ #/ #/JA A A A? ? ? ?       D!6 !6 !6 !6FY Y Y Yg g g gR- - - -^	1 	1 	1 	1PU PU PU PUd   &I I I IBKO KO KO KOZR$ R$ R$ R$hP( P( P( P(d
1 
1 
1 
1
 
 
 


 
 
 


 
 
 
( .2 Z  Z  Z  Z  ZD" " " "HW W W W:J J J J Jb #(` ` ` ` `. %)"'!&= = = = =~) ) ) )
 
 
 

 
 
 
&% % % %N= = = =G G G G*     UZ    .C C C C CJ   
/ 
/ 
/ 
// / / // / / // / / /
/ 
/ 
/ 
// / / // / / /   # # # #2 2 2 20 0 0 0    X    X PU    0@ @ @ @	
 	
 	
 	
 	
 	
r   r	  Fignore_in_type_objc                F    |                      t          |                    S )zWhether t contains an Any type)r`  
HasAnyType)r   rt  s     r   r  r    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 )rv  rt  r   r   r  c                l    t                                          t          j                   || _        d S r   )superr  r   ANY_STRATEGYrt  )r  rt  	__class__s     r   r  zHasAnyType.__init__  s,    +,,,"4r   r   r   c                ,    |j         t          j        k    S r   )rJ  r   r1  r  r   s     r   	visit_anyzHasAnyType.visit_any  s    }	 666r   r   c                    | j         r|                                rdS t                                          |          S )NF)rt  r  ry  visit_callable_typer  r   r{  s     r   r  zHasAnyType.visit_callable_type  s:    " 	q}} 	5ww**1---r   r   c                    |                                 r|j        gng }|                     |j        g||j        z             S r   )has_defaultr^  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                x    |                                 r|j        gng }|                     |j        g|          S r   r  r^  r  r  r  s      r   visit_param_speczHasAnyType.visit_param_spec  :    !"819++b 9 9:::r   r   c                x    |                                 r|j        gng }|                     |j        g|          S r   r  r  s      r   visit_type_var_tuplezHasAnyType.visit_type_var_tuple  r  r   )rt  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   rv  rv    s        5 5 5 5 5 57 7 7 7. . . . . .
F F F F; ; ; ;; ; ; ; ; ; ; ;r   rv  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   r   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   r   r  ro  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   rW  rW    s,    Aa##5QW5r   mappingr5  r@  r\  rA  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   r6   r   r   r   )r   r  rA  r@  s     r   r   z'is_duplicate_mapping.<locals>.<genexpr>  sf       
 
  Ou. P|A??OOO
 
 
 
 
 
r   )r  r   r5   r6   r   )r  r@  rA  s    ``r   rL  rL    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   r  
poly_tvarsSequence[TypeVarLikeType]CallableType | Nonec                    	 |                      fd| j        D             | j                            t	                              g           S # t
          $ r Y dS w xY w)a  Make free type variables generic in the type if possible.

    This will translate the type `tp` while trying to create valid bindings for
    type variables `poly_tvars` while traversing the type. This follows the same rules
    as we do during semantic analysis phase, examples:
      * Callable[Callable[[T], T], T] -> def [T] (def (T) -> T) -> T
      * Callable[[], Callable[[T], T]] -> def () -> def [T] (T -> T)
      * List[T] -> None (not possible)
    c                T    g | ]$}|                     t                              %S r   )r`  PolyTranslator)r   r   r  s     r   ru  zapply_poly.<locals>.<listcomp>2  s-    RRRqxxz : :;;RRRr   )r  r;  r  N)r  r  r;  r`  r  PolyTranslationError)r  r  s    `r   r"  r"  &  s    RRRRR\RRR[''z(B(BCC   
 
 	

     tts   AA 
AAc                      e Zd ZdS )r  N)r   r   r   r   r   r   r  r  :  s        Dr   r  c                       e Zd ZdZ e             e            fdd
ZddZd fdZd fdZd  fdZ	d! fdZ
d"dZd# fdZ xZS )$r  zoMake free type variables generic in the type if possible.

    See docstring for apply_poly() for details.
    r  Iterable[TypeVarLikeType]bound_tvarsfrozenset[TypeVarLikeType]seen_aliasesfrozenset[TypeInfo]r   r  c                J    t          |          | _        || _        || _        d S r   )r   r  r  r  )r  r  r  r  s       r   r  zPolyTranslator.__init__D  s'     j//&(r   r   CallableType | Parameterslist[TypeVarLikeType]c           
     :   g }|j         D ]}t          |          D ]q}t          |t                    r1|                    t
          j        t          g g g                     }n|}|| j        v r|| j	        vr|
                    |           rt          |          S )N)r  rC  )r  r   r   r   r  r   BAREr   r  r  r  r   )r  r   
found_varsr  rA  
normalizeds         r   collect_varszPolyTranslator.collect_varsO  s    
; 		2 		2C',, 2 2b-00 $242B2B.3Jr2r<R<R 3C 3 3JJ "$J00ZtGW5W5W%%j1112 :&&&r   r   r   c                x   |                      |          }| xj        t          |          z  c_        t                                          |          }| xj        t          |          z  c_        t          |t                    rt          |t                    sJ t          |j	                  |z   |_	        |S r   )
r  r  r   ry  r  r   r   r   r  r  )r  r   r  r'  r{  s       r   r  z"PolyTranslator.visit_callable_type]  s    &&q))
C
OO+,,Q//C
OO+&*--R*V\2R2RRRR 011J>r   r   c                    || j         v r|| j        vrt                      t                                          |          S r   )r  r  r  ry  r  r  s     r   r  zPolyTranslator.visit_type_varg  sA    AT-=$=$=&(((ww%%a(((r   r   c                    || j         v r|| j        vrt                      t                                          |          S r   )r  r  r  ry  r  r  s     r   r  zPolyTranslator.visit_param_specl  sA    AT-=$=$=&(((ww''***r   r   c                    || j         v r|| j        vrt                      t                                          |          S r   )r  r  r  ry  r  r  s     r   r  z#PolyTranslator.visit_type_var_tupleq  sA    AT-=$=$=&(((ww++A...r   r   c                    |j         s|                                S |j        s"t          |                              |           S t                      r   )ro  r  r   r   r`  r  r}  s     r   visit_type_alias_typez$PolyTranslator.visit_type_alias_typev  sP    v 	%??$$$~ 	3"1%%,,T222 #$$$r   r   c                    |j         j        r9t          d t          |j         j        j                  D                       }t          |j        |                   }t          |t                    rՉ 
                    |          } xj        t          |          z  c_         fd|j        D             } xj        t          |          z  c_        ||         }t          |t                    rt          |t                    sJ t          |j                  t          |          z   |_        |                    |          S |j        r|j         j        r|j         j        dgk    ro|j          j        v rt)                      t+          d||d          }|J |                    t/           j         j         j        |j         hz                      S t3                                          |          S )Nc              3  J   K   | ]\  }}t          |t                    |V  d S r   )r   r   )r   rp  rA  s      r   r   z0PolyTranslator.visit_instance.<locals>.<genexpr>  sK       $ $q"ZPRTaEbEb$$ $ $ $ $ $r   c                :    g | ]}|                               S r   rx  )r   r  r  s     r   ru  z1PolyTranslator.visit_instance.<locals>.<listcomp>  s#    ;;;qAHHTNN;;;r   )ro  r  Tr7  )r   has_param_spec_typer>  rf  r  r  r   ro  r   r   r  r  r   r   r  r  r  r  protocol_membersr  r  r{   r`  r  r  ry  visit_instance)	r  r   param_spec_indexr|  r  r  replr  r{  s	   `       r   r  zPolyTranslator.visit_instance  s   6% 	6  $ $ $!*16;+@!A!A$ $ $      '7 899A!Z(( 	6!..q11
  C
OO3  ;;;;AF;;;  C
OO3   01!$
33T
48T8TTTT!%dn!5!5Z8H8H!HH555 6 	af( 	QV-D-T-Tv****,,,z1aTBBBD###;;t0@$BSWXW]V^B^__   ww%%a(((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   r   	frozensetr  r  r  r  r  r  r  r  r  r  s   @r   r  r  >  s         3<)++,5IKK		) 	) 	) 	) 	)' ' ' '     ) ) ) ) ) )
+ + + + + +
/ / / / / /
% % % %) ) ) ) ) ) ) ) ) )r   r  c                  ,     e Zd ZdZd	 fdZd
dZ xZS )r8  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   ry  r  r   rz  r  r{  s    r   r  z ArgInferSecondPassQuery.__init__  $    +,,,,,r   r   r   r   c                x    |                      |j                  p |                    t                                S r   )r  r  r`  HasTypeVarQueryr}  s     r   r  z+ArgInferSecondPassQuery.visit_callable_type  s/    ,,K9J9J0K0KKr   ro  r  )r   r   r   r   r  r  r  r  s   @r   r8  r8    sc         - - - - - -L L L L L L L Lr   r8  c                  <     e Zd ZdZd fdZddZdd
ZddZ xZS )r  zBVisitor for querying whether a type has a type variable component.r   r  c                ^    t                                          t          j                   d S r   r  r  s    r   r  zHasTypeVarQuery.__init__  r  r   r   r   r   c                    dS rX  r   r}  s     r   r  zHasTypeVarQuery.visit_type_var      tr   r   c                    dS rX  r   r}  s     r   r  z HasTypeVarQuery.visit_param_spec  r  r   r   c                    dS rX  r   r}  s     r   r  z$HasTypeVarQuery.visit_type_var_tuple  r  r   ro  r  r  r  )	r   r   r   r   r  r  r  r  r  r  s   @r   r  r    s        LL- - - - - -             r   r  r  c                L    | d uo |                      t                                S r   )r`  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 rX  r   r}  s     r   visit_erased_typez*HasErasedComponentsQuery.visit_erased_type  r  r   ro  )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   )r`  HasUninhabitedComponentsQueryr   s    r   r  r    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 rX  r   r}  s     r   visit_uninhabited_typez4HasUninhabitedComponentsQuery.visit_uninhabited_type  r  r   ro  )r   r   r   r   )r   r   r   r   r  r  r  r  s   @r   r  r    sW        OO- - - - - -       r   r  rp  rn  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.
    rY  r   r   r   c                    t          | t                    pMt          | t                    o|                                 p$t          | t                    o| j        j        dk    S r  )r   r   r   r  r   r   r   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  rn  s     r   r   z-arg_approximate_similarity.<locals>.<genexpr>  s.      ``-dF;;``````r   c              3  8   K   | ]}t          |          V  d S r   r  )r   r  rp  s     r   r   z-arg_approximate_similarity.<locals>.<genexpr>  s.      ``-fd;;``````r   r   rr  )r   r   r   r   r   r   r   r   r  r  r   r  rx  r   r   r   r   r   r  r~   r   r    )rp  rn  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   rq  z:any_causes_overload_ambiguity.<locals>.<listcomp>.<lambda>4  s    IVWL r   )r   r  r  )r   r  r  r  r  s     r   ru  z1any_causes_overload_ambiguity.<locals>.<listcomp>2  sN         	y$.$.BXBXBXBX	
 	
  r   T)rt  c                :    g | ]\  }}|         ||         fS r   r   )r   item_idxlookuparg_idxs      r   ru  z1any_causes_overload_ambiguity.<locals>.<listcomp>>  s@     + + +$Hf'?+6'?++ + +r   )r  rf  r  r  r;  r  )r   r  r  r  r  actual_to_formalrZ  matching_formals_unfilteredmatching_returnsmatching_formalsr  formalsmatched_callablern  r  s     ```         @r   r  r    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   N)r}   )r   r   r   s     r   r   z!all_same_types.<locals>.<genexpr>Y  s1      <<Q|AuQx((<<<<<<r   r   )r   )r   s   `r   r  r  V  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(   r  r   r   r   r   r   r  r  r%   )r  r   unique_typevarsr  rd  renamerA  r7  s           r   r  r  \  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   rY  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   rJ  r  s    r   r  r    s7    
#

C#x   $S%9%E##Jr   r   rK   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   rO   rb  r^   r   r   rW   r   r   r   rd  r   )r   rb  
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   )rp  r  s     r   r   z&has_bytes_component.<locals>.<genexpr>  s+      ==a&q))======r   TF)r   r   r   r  r   r   r   r   )rY  
byte_typess     r   rp  rp    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   r   r  c                    | sdS |                      d          d         }|t          j                                        v p?|t          j                                        v p|t          j                                        v S )NFr   r,  )splitr   r5  r  r7  r  )r   
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   rH  rH    s%    y
1k22yafntHr   )r   r   r   r   )r   r^   r   r   rp  )r   r   rt  r   r   r   )r  r5  r@  r\  rA  r  r   r   )r  r   r  r   r   r   )r  r   r  r  r   r  )r   r  r   r   )rp  r   rn  r   r   r   )r   r  r  r\  r  r\  r  r  r  r]  r   r   )r   r\  r   r   )r  r  r   r  )rY  r   r   r   rq  r  )rY  r   r   r  )r   r  r   r   )r   r  r   r  (   r   
__future__r   enumr  r  collectionsr   
contextlibr   r&  r   r   r   r	   r
   r   r   r   r   r'  r   r   r   r   mypy.checkerr  mypy.errorcodes
errorcodesr  r   r   r   r   r   r   r   mypy.argmapr   r   r   mypy.checkmemberr   r   r   mypy.checkstrformatr   mypy.erasetyper    r!   r"   mypy.errorsr#   r$   mypy.expandtyper%   r&   r'   r(   
mypy.inferr)   r*   r+   mypy.literalsr,   mypy.maptyper-   	mypy.meetr.   r/   mypy.message_registryr0   mypy.messagesr1   r2   
mypy.nodesr3   r4   r5   r6   r7   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   mypy.optionsrs   mypy.pluginrt   ru   rv   rw   rx   mypy.semanal_enumry   
mypy.staterz   mypy.subtypesr{   r|   r}   r~   r   mypy.traverserr   mypy.type_visitorr   mypy.typeanalr   r   r   r   r   r   r   mypy.typeopsr   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   mypy.types_utilsr   r   r   r   mypy.typestater   mypy.typevarsr   	mypy.utilr   mypy.visitorr   r4  r   rs  r   r   r   r  r   r   r   r   uniqueEnumr   r  r  r  r  r  r  r	  r  BoolTypeQueryrv  r<  r;  rW  rL  r  r"  r  r  r8  r  r  r  r  r  r  r  r  r  r  r  rp  r  r  rH  r   r   r   <module>r'     si   M M M " " " " " "       # # # # # # % % % % % % ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` M M M M M M M M M M           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 Z Z Z Z Z Z Z Z Z Z 6 6 6 6 6 6 [ [ [ [ [ [ [ [ [ [ ; ; ; ; ; ; ; ;            a ` ` ` ` ` ` ` ` ` ! ! ! ! ! ! 2 2 2 2 2 2 @ @ @ @ @ @ @ @ . . . . . . 5 5 5 5 5 5 5 5B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B BF - , , , , ,              ) ( ( ( ( (                    0 / / / / / , , , , , ,                                                  ") ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )T            & % % % % % ' ' ' ' ' ' ( ( ( ( ( ( * * * * * * "	4$S,QXY[__
     
    
	& 	& 	&  	 	 	 	& & &         I         @O O O O Oy O O O         (/  / / / /&-  - - - -%+  + + + +\Z
 \Z
 \Z
 \Z
 \Z
)$/ \Z
 \Z
 \Z
~t4 4 4 4 4
; ; ; ; ;$ ; ; ;4V V V VM M M M06 6 6 6
   22 2 2 2
   (	 	 	 	 	9 	 	 	`) `) `) `) `)^ `) `) `)FL L L L Le1 L L L     e)    B B B B    u2   G G G G    E$7   <R <R <R <R~7 7 7 7t= = = =* * * *Z   
 
 
 
      &        r   