
    hi                   j   U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
mZ ddlmZmZ ddlmZmZmZmZmZmZ ddlmZmZ ddlZddlmZ dd	lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% dd
l&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@mAZA ddlBmCZC ddlDmEZE ddlFmGZGmHZH ddlImJZJ ddlKmLZLmMZM ddlNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dd lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dd!lmZmZmZmZ dd"lmZ dd#lmZ dd$lmZ dd%lmZ eeeeXeeeeee         ebebg
df         Zd&ed'<   d(Zd)ed*<   g d+Zd)ed,<   h d-Zd)ed.<    G d/ d0e          Zdd5Zdd;Z G d< d=e          Z ej         G d> d?ej                              Zej        Zd)ed@<   ej        Zd)edA<   ej        Z	d)edB<    G dC dDee         e+          Z
dddGZ G dH dIe%j                  ZddJZddKZddLZddSZddWZ G dX dYe%j                  Zdd[Z G d\ d]e%j                  Zdd^Z G d_ d`e%j                  ZddcZddkZddmZddqZddtZddwZddxZddzZdd}Z ddZ!ddZ"dS )zGExpression type checker. This file is conceptually part of TypeChecker.    )annotationsN)defaultdict)IterableIteratorSequence)contextmanagernullcontext)CallableClassVarFinalOptionalcastoverload)	TypeAliasassert_never)	applytype	erasetypejoinmessage_registrynodes	operatorstypes)ArgTypeExpandermap_actuals_to_formalsmap_formals_to_actuals)ExpressionCheckerSharedApi)analyze_member_accesshas_operator)StringFormatterChecker)
erase_type!remove_instance_last_known_valuesreplace_meta_vars)	ErrorInfoErrorWatcherreport_internal_error)expand_typeexpand_type_by_instancefreshen_all_functions_type_varsfreshen_function_type_vars)ArgumentInferContextinfer_function_type_argumentsinfer_type_arguments)literal)map_instance_to_supertype)is_overlapping_typesnarrow_declared_type)ErrorMessage)MessageBuilderformat_type)C	ARG_NAMEDARG_POSARG_STAR	ARG_STAR2IMPLICITLY_ABSTRACTLAMBDA_NAME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TypeVarLikeExpr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)check_for_explicit_anyfix_instancehas_any_from_unimported_typeinstantiate_type_aliasmake_optional_typeset_any_tvarsvalidate_instance)callable_typecustom_special_methoderase_to_union_or_bound
false_onlyfixup_partial_typefreeze_all_type_varsfunction_typeget_all_type_varsget_type_varsis_literal_type_likemake_simplified_unionsimple_literal_type	true_onlytry_expanding_sum_type_to_uniontry_getting_str_literalstuple_fallbacktype_object_type))LITERAL_TYPE_NAMESTUPLE_LIKE_INSTANCE_NAMESAnyTypeCallableTypeDeletedType
ErasedType
ExtraAttrsFunctionLikeInstanceLiteralTypeLiteralValueNoneType
Overloaded
ParametersParamSpecFlavorParamSpecTypePartialType
ProperType	TupleTypeTypeTypeAliasTypeTypedDictType	TypeOfAnyTypeType	TypeVarIdTypeVarLikeTypeTypeVarTupleTypeTypeVarTypeUnboundTypeUninhabitedType	UnionType
UnpackTypefind_unpack_in_listflatten_nested_tuplesflatten_nested_unionsget_proper_typeget_proper_typeshas_recursive_typeshas_type_varsis_named_instancesplit_with_prefix_and_suffix)is_generic_instanceis_overlapping_noneis_self_type_likeremove_optional)
type_state)fill_typevars)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__     ^/var/www/html/Pagina-Ingenieria-Requisitos/venv/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`   outputset[str]Nonec                @   t          | j        t                    s| j        r{t          | 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                    dS t          | t                    r$t          | j        t                    r| j        } n!dS t!          dt#          |                      t          | j        t                    q| j        ydS d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: N)r   noderW   fullnameaddrY   rs   is_suppressed_importrn   updater   module_namersplitrV   r   r`   AssertionErrortype)r   r   r   s      r   extract_refexpr_namesr     s   
 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:;;;Ej)) 	L$)W-- y !Jd4jj!J!JKKK- TY
)
) LT] L L L L Lr   c                      e Zd ZdZdS )FinishedzDRaised if we can terminate overload argument check early (no match).Nr   r   r   r   r  r    s        NNNNr   r  c                      e Zd ZdZdZdZdZdS )
UseReversezCUsed in `visit_op_expr` to enable or disable reverse method checks.r   r      N)r   r   r   r   DEFAULTALWAYSNEVERr   r   r   r  r    s#        MMGFEEEr   r  USE_REVERSE_DEFAULTUSE_REVERSE_ALWAYSUSE_REVERSE_NEVERc                     e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ddZddZddZdddZddd dd(Z	dd,Z
dd/Zddd2Zdd5Zddd6Zdd7Zdd<Zdd=Zdd@ZddAZddBZddMZddQZddWZddZZdd\Zdd]ZddaZ	 dΐddeZddfZddjZdkgdldmgdnZdoedp<   dqdrgidsdtgidsdtgidsdudrgidvZ dwedx<   ddyZ!dd|Z"ddZ#ddZ$ddZ%ddZ&ddZ'	 	 dؐddZ(ddZ)ddZ*	 dΐddZ+ddZ,	 	 	 	 	 dސddZ-ddZ.ddZ/ddZ0ddZ1ddZ2ddZ3ddZ4ddZ5ddZ6ddZ7ddZ8ddZ9	 	 dؐddZ:ddÄZ;ddĄZ<	 	 dؐddǄZ=ddτZ>ddЄZ?ddӄZ@ddՄZAddքZBddׄZC	 ddd܄ZDdd݄ZEeFdd            ZGddZHddZI	 dddZJddZKddZLdddZM	 dΐd dZNddZOddZPddZQddZRddZSddZTdd ZUddZVd	dZWd
dZXddZYdd
ZZddZ[dbdbdddddZ\	 	 dؐddZ]	 dΐddZ^ddZ_ddZ`	 ddd!Zadd"Zbdd#Zcdd%Zddd'Zedd)Zfdd*Zg	 	 dؐdd,Zhdd-Zidd.Zjdd1Zkdd4Zldd5Zmdd6Zn	 ddd:Zodd<Zpd d>Zqd!d@Zrd"dBZsd#dCZtd$dFZud%dIZvddJd&dMZwd'dOZxd(dQZyd)dSZzd*dUZ{d+dXZ|d,dZZ}d-d\Z~d.d^Zd/d_Zd0daZd1dcZd2ddZd3dgZd4diZd5dkZd6dmZd7doZd8dpZd9drZd:dtZd;dvZ	 dΐd<d|Zd=d~Zd>dZdd?dZ	 	 d@dAdZdBdZ	 	 	 	 dCdDdZdΐdEdZdFdZdGdZddZddZdHdZdIdZddJdZ	 ddKdZddLdZdMdZdNdZdOdZdPdZdQdZdRdZdSdZdTdZdUdZdVdZdGdZdGdZedWd            ZedXd            Z	 ddXdZdYdZdYdZdbS (Z  ExpressionCheckerz^Expression type checker.

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

        It can be of any kind: local, member or global.
        )r  r  module_refsanalyze_ref_exprnarrow_type_from_bindercheck_deprecatedr   )r'  r-  resultnarroweds       r   visit_name_exprz!ExpressionChecker.visit_name_exprp  s`    
 	a!5666&&q))//6::!!!&!,,,r   Fr`   lvaluer   c                   d }|j         }t          |t                    r |j        rt	          t
          j                  S t          |t                    rJ|                     ||          }t          |t                    r| j
                            ||||          }n>t          |t                    r|                     |j        |          }nt          |t                    ri|j        Z| j
                                        r'|j        r | j
                            |j        |           t	          t
          j                  }n|j        }nt          |t*          t,          t.          t0          t2          f          r|                     |||j        p|          }nAt          |t8                    rJ d|j        d            t	          t
          j                  }t          |t,                    rt          |t<                    r<t          |j        t@                    r"|j!        |j        _!        |j"        |j        _"        tG          | j$        d                   rtK          j&        |          }|J |S )NFzPlaceholderNode z leaked to checker)'r   r   rY   is_special_formr   r   special_formrs   analyze_var_refr   r  handle_partial_var_typerH   varr\   r  in_checked_functionr   handle_cannot_determine_typename
from_errorrO   rn   r   rW   rp   analyze_static_referenceis_alias_rvaluer^   r   r   ret_typer   linecolumnis_type_type_contextr  r   erase_typevars)r'  r-  r6  r3  r   s        r   r0  z"ExpressionChecker.analyze_ref_expr{  s?   "va"" 	3q'8 	391222dC   	3))$22F&+.. S99&&$PQRRi(( 	3))$(A66FF/00 	3y 8//11 Hdj HH99$)QGGG !566w)XWXX 	3224A<M<WQWXXFF$00 UTTTTTTTT Y122FdH%% 	:&,// 2J5 5 2
 ()v$)*&#D$5b$9:: : #1&99!!!r   Tinclude_modulessuppress_errorsr   rh   ctxrG   	is_lvaluerJ  rK  c                  t          |t          t          t          f          r |j        pt          t          j                  S t          |t                    r#t          || 
                    d                    S t          |t                    rW|j        r|                     |          S |j        dk    rt          t!                                S t#          || j
                  S t          |t$                    rZ|r| j                                        nt+                      5  |                     |||          cddd           S # 1 swxY w Y   nt          |t.                    r| 
                    d          S t          |t0          t2          f          r|                                 S t          |t6                    r0|r|                     |          nt          t          j                  S t          t          j                  S )a  
        This is the version of analyze_ref_expr() that doesn't do any deferrals.

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

+++'do>>>i(( 	b .=O'')))+--  99cI :                   k** 	b??#3444}.>?@@ 	b##%%%h'' 	b-<a4##D)))')J`BaBaay+,,,s   %E

EEr=  rs   contextc                   |j         rt          |j                   }t          |t                    rj|j        dk    r|                     d          S |                                 r|j        |j        S |j        dv r| 	                    |j        dk    d          S |j         S |j
        s9| j                                        r | j                            |j        |           t          t          j                  S )Nz
typing.Anytyping._SpecialForm>   TrueFalser\  builtins.bool)r  r   r   r   r   rR  is_literal_contextlast_known_valuer@  infer_literal_expr_typeis_readyr  r>  r?  r   r   r:  )r'  r=  rY  var_types       r   r;  z!ExpressionChecker.analyze_var_ref  s    8 	3&sx00H(H-- ]<<//??+@AAA**,, 51J1V#44800077F8JO\\\8O< IDH$@$@$B$B I55chHHH91222r   rW   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        t          t          j                  ||<   l|                     |j        |j        ddd          ||<   t          |||j                  |_        |S )Nztypes.ModuleTypebuiltins.objectFTrI  )rR  KeyErrorsetnamesr   module_publicr   r   rs   is_finalr   r   r   rA  rB  r   r   extra_attrs)r'  r   r3  module_attrs	immutabler@  ns          r   rX  zExpressionChecker.module_type  s.   	8__%788FF 	8 	8 	8 __%677FFF		8
 )+EE	z'')) 	 	GD!? !&#&& $16? $d###v~%,Y-A%B%BT"" &*%B%BFAFE5RV &C & &T"" (iOOs    ::rB   allow_none_returnc                    |j         rat          |j         t                    r!|j         j        s|                     |           |                     |j         | j        d                   S |                     ||          S )zType check a call expression.r8  ro  )analyzedr   rX   is_typedvisit_call_expr_inneracceptr  )r'  r-  ro  s      r   visit_call_exprz!ExpressionChecker.visit_call_expr  s{    : 	B!*n55 .aj>Q . **1---;;qz4+<R+@AAA))!?P)QQQr   baserM   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   rn   rS  r   r   targetr   )r'  rw  s     r   refers_to_typeddictz%ExpressionChecker.refers_to_typeddict  ss    $(( 	5di** 	ty/G/S4$)Y// 
JDI,--}5
 5
 	
r   c           	                               j                  s9t          j        t                    r                      j        j                  rt                               j        d                    }t          |t                    rTt          |j                  }t          |t                    sJ  
                    |j        j        j        |          S t          j        t                    rɉj        j        dv rt!          j                  dk    rt"          j                            j        d                   D ]u}d }t          |t                    r1	  j                            |j                  }n# t,          $ r Y nw xY wt/          |          r' j                            j        j        d           |rt          |j        t6                    rlt          |j        j                  }t          |t:                    r' j                            j        j        d           t          |t<                    r	t          |t                    r!t          |j        t@          tB          f          st          |t                    r|rt          |j        t6                    rp|j        j"        sdt          t          |j        j                  x}tF                    r|j$        s/ j        j%        j&        dk    s j        '                               t          |tP                    rt          |j        tR                    rf|j        j*        r( j                            j        j        d	           C|j        j+        r& j                            j        j        d
           w ,                               d }	t          j        tZ                    rt]          j        j        j        j        j        j         fd           fdt_          t!          j        j                            D             }
t          |
j        j        j        j         0                                 1                    d                    }	t                               j        |	dd                    }d }d }d t          j        tP                    r܉j        j2        pd t          j        j        t6                    r?t          j        j        j                  }t          |tf                    r|j4        j2        snt          j        tj                    rT j        6                    j        j7                  r0j        j        } j        8                    j        j7                  } j        j%        j9        r j        :                                rt          |t                    r||j;        ru|j        tx          k    re||J  =                    ||          r*t}          fd j        j%        j?        D                       s j        @                    |            A                    |||          }t          j        tP                    r`t!          j                  dk    rHj        j2        dv r B                               j        j2        dk    r C                               t          j        tj                    r%j        j        dk    r D                               t          |          }t          |tF                    rt          |jF                  }t          |t                    r%|jH        s j        jI        J                                 |sht          |t<                    rS K                    j                  r9 j        j        L                    |           t;          t          jN                  S |S )NTr   )r   
issubclassr  r   LiteralAny   
   	TypedDictNewTypec                D                         j        |                    S r   ru  args)ir-  r'  s    r   <lambda>z9ExpressionChecker.visit_call_expr_inner.<locals>.<lambda>[  s    $++afQi00 r   c                ^    g | ])}t          j        fd |         D                       *S )c                P    g | ]"}                     j        |                   #S r   r  )r   jr-  r'  s     r   
<listcomp>zFExpressionChecker.visit_call_expr_inner.<locals>.<listcomp>.<listcomp>_  s+    $Y$Y$YT[[%;%;$Y$Y$Yr   )r   join_type_list)r   r  r-  formal_to_actualr'  s     r   r  z;ExpressionChecker.visit_call_expr_inner.<locals>.<listcomp>^  sS        #$Y$Y$Y$Y$YEUVWEX$Y$Y$YZZ  r   rO  )rD  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>  sT       ' ' A=!4!4WWW!=!=' ' ' ' ' 'r   )zbuiltins.isinstancebuiltins.issubclassr  format)Orz  calleer   rQ   rw  r   ru  r   rD  r   check_typeddict_call	arg_kinds	arg_namesr  rY   r@  lenmypycheckerflattenr  lookup_qualifiedrf  is_expr_literal_typer  cannot_use_function_with_typer   r   ry  r   r   rr  rl   rk   no_argsr   uses_pep604_syntaxr  python_versiontype_arguments_not_allowedr`   rn   rS  
is_newtypetry_infer_partial_typerS   r   rangerW  rR  r   r   r  rV   has_typer   lookup_typedisallow_untyped_callsr>  implicitr9   method_fullnameanyuntyped_calls_excludeuntyped_function_call check_call_expr_with_callee_typecheck_runtime_protocol_testcheck_protocol_issubclasscheck_str_format_callr   r   r   	ambiguousbinderunreachablealways_returns_nonedoes_not_return_valuer   rA  )r'  r-  ro  rT  rS  typr   ry  union_targetr  	arg_typescallee_typerW  memberrD  r  r   s   ``             @@r   rt  z'ExpressionChecker.visit_call_expr_inner  s   $$QX..	!(I..	 ((77	
 "1QXQU1V1V!W!W,l;; !01C1L!M!M!.-@@@@@00"AKafaI[   qx**,	\!===AFq  |++AF1I66 '\ '\c8,, #x88BB#    (,, H::18=)UVWWW !Jty)<< !,TY-=>>F!&'22 !>>qx}eUVWWW !&(33 ! sI..;"3</=1QRR; sH--	;
 ; #49i88; !I-; #?49CS3T3T#T<V_``; );;  $x/>'II H77:::c7++ \
38X0N0N \x. \>>qx}k[\]]]], \>>qx}iYZ[[[##A&&&ah
++ 	5""00000        s18#56677  I (""))++)<==  L &KK,QUKVV
 

 ah(( 	B x(0DH!(-33 4()=>>fh// 4%{3H Bqx44B H%%ahm44B
 "h2218=AA H3	?,,..	? ;55	? $		?
  K//F$6"...//VDD ?3 ' ' ' ')?' ' ' $ $ ? ..{A>>>88Hk6
 
 ah(( 	2S[[A-=-=x $RRR00333x $999..q111ah
++ 	*0I0I&&q)))"8,,h	** 	=,X^<<Hh00 	*9K 	*HO'')))
 "	18X..	1 ((22	1
 HL..{A>>>9/000s   2F
FFc                X   t          |j        t                    sJ d}t          |j        j        t                    r|j        j        j        }n:| j                            |j        j                  rt          | j        	                    |j        j                            }t          |t                    r|j        j        r~t          |j        t                    rdt          |j        j        t                    rE|j        j        |j        j                 j        }t          |t"                    rt          |          }t%          |          }t          |t                    r!t          |j        t                    r|j        }|| j                            ||           dS dS )z>More precise type checking for str.format() calls on literals.N)r   r  rV   r   rf   valuer  r  r   r  r   r  is_enumr`  r   strrh  r   try_getting_literalr  r  )r'  r-  format_valuer  
value_typebase_typs         r   r  z'ExpressionChecker.check_str_format_call  so   !(J/////ahmW-- 	.8=.LLXqx}-- 	.!$("6"6qx}"E"EFFC3))6H$6 s3[AA6 s393??	6 !X^C,@,FGL
j$// 6)*55C*3//H(K00 .ZPS5T5T .'~#55aFFFFF $#r   rW  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_objrD  r   itemr   r  r   r   r   r  get_containing_type_infor   r   )r'  rW  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   rV   r   r  r  r   r   r  r   r  rD  getr@  )r'  r   r  r  rD  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   rO   r  r   r   rD  r   r\   r   r   rs   is_inferredr   r  r  r   )r'  r  r  r  s   `   r   r  z#ExpressionChecker.defn_returns_none  s8   dG$$ 	di66 :	 233X< <  d-.. 	LKKKK
KKKKKKdC   	 !$),,C$sL11 s|<<hGG
 t#x((  hll:..  411#(;;  4ur   c                   t           j                            |j        d                   D ]}t	          | j                            |                    }t          |t                    rk|	                                rW|
                                j        r>|
                                j        s%| j                            t          j        |           d S Nr   )r  r  r  r  r   r  r  r   r   r  type_objectis_protocolruntime_protocolfailr   RUNTIME_PROTOCOL_EXPECTED)r'  r-  r   tps       r   r  z-ExpressionChecker.check_runtime_protocol_test  s    L((33 	M 	MD !5!5d!;!;<<B2|,,MNN$$M NN$$0M ((9	M .H!LLL	M 	Mr   c                   t           j                            |j        d                   D ]}t	          | j                            |                    }t          |t                    r|	                                ro|
                                j        rVt          |
                                          }|r3| j        j                            |
                                ||           d S r  )r  r  r  r  r   r  r  r   r   r  r  r  r   r  report_non_method_protocol)r'  r-  r   r  attr_memberss        r   r  z+ExpressionChecker.check_protocol_issubclass  s    L((33 	_ 	_D !5!5d!;!;<<B"l++ _0@0@ _R^^EUEUEa _:2>>;K;KLL _HL;;BNN<L<Ll\]^^^	_ 	_r   r  r   r  list[ArgKind]r  Sequence[str | None]r  list[Expression]orig_calleeType | Nonec                4   |rt          d |D                       rjt          d |D             |          }|                     ||          }||\  }	}
|                     ||	|||
          S t	          t
          j                  S t          |          dk    r|d         t          k    r|d         }t          |t                    r|                     ||j        ||          S t          |t                    r<t          |j        t                    r"|                     ||j        j        ||          S |s%|                     |i ||t                                S | j                            t$          j        |           t	          t
          j                  S )Nc              3  6   K   | ]}|t           t          fv V  d S r   )r4   r7   )r   aks     r   r   z9ExpressionChecker.check_typeddict_call.<locals>.<genexpr>,  s,      IIy)44IIIIIIr   c                4    g | ]}|t          |          nd S r   )rf   )r   rn  s     r   r  z:ExpressionChecker.check_typeddict_call.<locals>.<listcomp>0  s&    SSSA'!***4SSSr   kwargsr  r   r   )r   zipvalidate_typeddict_kwargs check_typeddict_call_with_kwargsr   r   rA  r  r5   r   rI   check_typeddict_call_with_dictr   rB   rr  rg  r  r  r   INVALID_TYPEDDICT_ARGS)r'  r  r  r  r  rY  r  r  r3  validated_kwargsalways_present_keys
unique_args               r   r  z&ExpressionChecker.check_typeddict_call#  s     	1CIIyIIIII 	1 SSSSSUYZZF336&3QQF!8>5 "5<<,g{DW   9/000t99>>ilg55aJ*h// ::J,g{   *h// Jz?RT\4]4] ::J/5w    	b88Wk[^[`[`aaa&=wGGGy+,,,r   r  .Iterable[tuple[Expression | None, Expression]]3tuple[dict[str, list[Expression]], set[str]] | Nonec                   t          t                    }t                      }d }|D ]\  }}|r|                     |          }t	          ||          }	d }
|	rt          |	          dk    r|	d         }
|
8|p|}| j                            t          j	        |t          j                    d S |g||
<   |                    |
           |}|                     ||||          s d S | j        j        j        rM|Kg }|j        D ]$}||j        vr||vr|                    |           %|r| j                            ||           ||fS )Nr   r   code)r   listrg  ru  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  r3  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_kwargsM  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  r3  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   r  zBExpressionChecker.validate_star_typeddict_item.<locals>.<listcomp>  s(    %^%^%^cUWU]oobhsmooor   c              3  *   K   | ]}|j         v V  d S r   r  r  s     r   r   zAExpressionChecker.validate_star_typeddict_item.<locals>.<genexpr>  s+      BBr3"**BBBBBBr   r   T)r   ru  r   r   r   r   relevant_itemsr  valid_unpack_fallback_itemr  %unsupported_target_for_star_typeddictrg  r   keysri   
make_unionset_liner   r   )r'  r  r  r3  r  inferredpossible_tdsr  all_keysr  argfirstr  s               @r   r   z.ExpressionChecker.validate_star_typeddict_item  sJ    #4;;xf;#M#MNNh.. 	$:LL),, 		()@)@)B)BCC ! !dM22 ! ''----88>> !HBB4RRR 55!! 00:: 	H::8XNNN5 UU 	( 	(B'HH 	( 	(C$%^%^%^%^l%^%^%^__ C LL"""BBBB\BBBBB (#'',,,
 #; 	("3KNE%eX66 , (-cls'*es#&%F3KK s""3''''tr   r  r   c                8   t          |t                    rdS t          |t                    r|j                            d          sdS t          || j                            d                    }t          d t          |j
                  D                       S )NTtyping.MappingFc              3  @   K   | ]}t          |t                    V  d S r   )r   r   r   as     r   r   z?ExpressionChecker.valid_unpack_fallback_item.<locals>.<genexpr>  s,      QQa:a))QQQQQQr   )r   r   r   r  has_baser.   r  lookup_typeinfor   r   r  )r'  r  mappeds      r   r  z,ExpressionChecker.valid_unpack_fallback_item  s    c7## 	4#x(( 	0A0ABR0S0S 	5*30H0HIY0Z0Z[[QQ3CFK3P3PQQQQQQr   *list[tuple[Expression | None, Expression]]c                    |                      ||          }|]|\  }}|j        t          |                                          cxk    o)t          |j                                                  k    nc S dS )Nr  F)r  r  rg  r  r   )r'  r  r  rY  r3  r  _s          r   match_typeddict_call_with_dictz0ExpressionChecker.match_typeddict_call_with_dict  s     //vf/MM"(a'3/?/D/D/F/F+G+Gcccc3v|O`O`ObObKcKcccccc5r   c                    |                      ||          }||\  }}|                     |||||          S t          t          j                  S )Nr  )r  rY  r  r  )r  r  r   r   rA  )r'  r  r  rY  r  r3  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  rn   r   c                    |j         J |j         j        }t          |t                    rt          |t                    sJ |                     ||j        j                  S )a  Construct a reasonable type for a TypedDict type in runtime context.

        If it appears as a callee, it will be special-cased anyway, e.g. it is
        also allowed to accept a single positional argument if it is a dict literal.

        Note it is not safe to move this to type_object_type() since it will crash
        on plugin-generated TypedDicts, that may not have the special_alias.
        )special_aliasry  r   r   r   typeddict_callable_from_contextr  	type_vars)r'  r  ry  s      r   rT  z$ExpressionChecker.typeddict_callable  s^     !---#*&*--S*V]2S2SSSS33FDI<OPPPr   N	variables Sequence[TypeVarLikeType] | Nonec           	        t          t          j                                                  fdj        D             t          j                                                  |                     d          |d          S )Nc                R    g | ]#}|j         v rt          j        nt          j        $S r   )r  r=   r4   ARG_NAMED_OPT)r   r@  r  s     r   r  zEExpressionChecker.typeddict_callable_from_context.<locals>.<listcomp>  sA        &*V-A%A%A!!wG\  r   builtins.typeT)r3  is_bound)r   r  r   r	  r  rR  )r'  r  r3  s    ` r   r1  z1ExpressionChecker.typeddict_callable_from_context  s     $$&&''   "L   ""$$%%OOO,,
 
 
 	
r   c                b   |                                 j        r(j        z  }|r| j                            ||           j        |k    rj                                         k    sj                                         k    sO| j                            fdj                                         D             t                    |           j        |k    sM| j                            fdj                                         D             fd|D             |           j        k    rt          t          j                  S t          |          }t          |t                    r|}nFj        j        j         |                     j        j                  }n|                               }| j                                        5  | j        j        5  |                     |d |                                D             t2          j        gt7          |          z  |t          |                                           d d d           \  }}	d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          |          }
t          |
t8                    s}
|
j                                        D ]b\  }}||v rY||         }|D ]N}| j                            |||t=          t>          j         j!        tD          j#                  d| d	d
           Oc|S )NrY  c                .    g | ]}|j         v s|v |S r   r  )r   r  actual_keysr  s     r   r  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s;     # # #&"666#:L:L :L:L:Lr   )expected_keysr=  rY  c                &    g | ]}|j         v |S r   r  r   r  r  s     r   r  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s-     # # # #cVEY>Y>Y>Y>Y>Yr   c                &    g | ]}|j         v |S r   r  r@  s     r   r  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>  s-     ! ! ! #cVEY>Y>Y>Y>Y>Yr   c                    g | ]
}|d          S r   r   )r   r  s     r   r  zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>=  s    555Ta555r   r  zTypedDict item ""
expression)lvalue_typervaluerY  r  lvalue_namervalue_name)$r  to_be_mutatedreadonly_keysr  readonly_keys_mutatedr  r   unexpected_typeddict_keysr  r   r   rA  r   r   r   r  r  r0  rT  r1  rU  r  local_type_mapcheck_callable_callr	  r=   r4   r  r   check_simple_assignmentr1   r   INCOMPATIBLE_TYPESr  r  TYPEDDICT_ITEM)r'  r  r  rY  r  r  assigned_readonly_keysinfer_calleeorig_ret_typer,  rD  	item_nameitem_expected_typeitem_values
item_valuer=  s    `             @r   r  z2ExpressionChecker.check_typeddict_call_with_kwargs  s&    kkmm 	X%063G%G"% X../Ew.WWW $777K6<K\K\K^K^<^<^6<#4#4#6#66622# # # # ##)<#4#4#6#6# # #
 !%[ 1 1# 3 	 	 	 (,???22# # # #'-|'8'8':':# # #! ! ! !':! ! ! $ 3 	 	 	 #k11 y3444%k22k<00 	L&LL #1=#66v7KLL  $CCFKK X##%% 	 	tx'> 	 	#77 65V]]__555"#c&kk1V[[]]##   M1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 #=11(M22 	 H-5^-A-A-C-C 	 	)I)F""$Y/"- 
 
JH44$6) *(,?EEL`   %Dy$C$C$C$0 5 	 	 	 	 s7   J)A6I+J+I/	/J2I/	3JJ	Jr   rV   
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   rY   r   rs   is_selfr  scopeenclosing_classr@  rh  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extendra  r   builtins.dictr   )ra  rd  zcollections.OrderedDictr   z)ClassVar[dict[str, dict[str, list[str]]]]container_argsc                   t          |j        t                    sdS |j        }t          |j        t                    rg|                     |j                  }|dS |\  }}|                     ||j        |          }|"||v r | j        	                    |||           dS dS dS t          |j        t                    r0t          |j        j        t                    r|j        j        dS |j        j        }|j        j        }|                     |          }|dS |\  }}t          |j                  }	|	|	j        dS |                     ||j        |          }
|
|                     |          }t$          j                            || j        j                  rV|	j        J |	j        j        }| j                            |||
g          }| j        	                    |||           dS dS dS dS dS )z-Try to make partial type precise from a call.N)r   r  rV   r   r`   get_partial_var&try_infer_partial_value_type_from_callr@  r  replace_partial_typerQ   rw  rr  indexget_partial_instance_typer  r  ru  r  r  is_valid_inferred_typer  r   named_generic_type)r'  r-  r  retr=  partial_typesr  rw  rj  partial_typer  r  typenamenew_types                 r   r  z(ExpressionChecker.try_infer_partial_type  s#   !(J// 	Ffk7++  	P&&v{33C{!$C==acRRC3-#7#7--c3FFFFF #7#7Y// 	PJv{?OQX4Y4Y 	P{#/;#DK%E&&t,,C{!$C4SX>>L#|'>'FDDQUXYYJ%;;u--<66xAQRR P',888+09H#x::8hPZE[\\HH11#xOOOOO-	P 	P 	P 	P &%P Pr   ref%tuple[Var, dict[Var, Context]] | Nonec                    |j         }|*t          |t                    r|                     |          }t          |t                    sd S | j                            |          }|d S ||fS r   )r   r   rV   r_  rs   r  find_partial_types)r'  rs  r=  ro  s       r   rg  z!ExpressionChecker.get_partial_var  sq    h;:c:66;++C00C#s## 	433C88 4M!!r   
methodnameInstance | Nonec                     j         j        rdS t          |j                  }|dS |j        r|j        j        j        }n|j        J |j        j        }| j        v r| j        |         v ry|j        t          gk    rh 	                    |j
        d                   }t          j                            | j         j                  r j                             ||g          S n
| j        v r | j        |         v r|j        t          gk    rt#           	                    |j
        d                             }t%          |t&                    ro|j        j        }| j        |         |         v rMt)           fd|j
        D                       r- j                             |t+          |j
                            S n/t%          |t,                    r j                             |          S dS )zCTry to make partial type precise from a call such as 'x.append(y)'.Nr   c              3  l   K   | ].}t           j                            |j        j                  V  /d S r   )r  r  rl  r  r  )r   	item_typer'  s     r   r   zKExpressionChecker.try_infer_partial_value_type_from_call.<locals>.<genexpr>  sN        % ;;ItxGWXX     r   )r  current_node_deferredrk  r  r  r   rb  r  r5   ru  r  r  r  rl  r  rm  re  r   r   r   r   r  r   rR  )	r'  r-  rw  r=  rp  rq  r{  arg_typearg_typenames	   `        r   rh  z8ExpressionChecker.try_infer_partial_value_type_from_call  s    8) 	40::4" 	2#.3<HH$000#(1H &&dnX666y((AF1I..I|229dh>NOO Jx228i[IIIJ +++d1(;;;y((&t{{16!9'='=>>H(H-- 	5'}54#6x#@#LLL    )1     Z  $x::8T(-EXEXYYYHg.. 5x**8444tr   r  
list[Type]Sequence[str | None] | Noner  list[list[int]]r   c
                   t          |j                  }
d t          |
          D             }d t          |
          D             }d t          |
          D             }d t          |
          D             }t          |          D ]\  }}|D ]}||                             ||                    ||                             ||                    |r"||                             ||                    n||                             d           ||                             ||                    |M| j                            |          }|J  |t          |||j        ||j	        ||	| j
                            S | j                            |          }|J t          |          } |t          ||||j        ||j	        ||	| j
        	  	                  S )a  Use special case logic to infer the return type of a specific named function/method.

        Caller must ensure that a plugin hook exists. There are two different cases:

        - If object_type is None, the caller must ensure that a function hook exists
          for fullname.
        - If object_type is not None, the caller must ensure that a method hook exists
          for fullname.

        Return the inferred return type.
        c                    g | ]}g S r   r   r   r,  s     r   r  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>  s    -M-M-MQb-M-M-Mr   c                    g | ]}g S r   r   r  s     r   r  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>      3S3S3S1B3S3S3Sr   c                    g | ]}g S r   r   r  s     r   r  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>  r  r   c                    g | ]}g S r   r   r  s     r   r  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>  s    0P0P0P0P0P0Pr   N)r  r  callee_arg_namesr  default_return_typer  rY  api)	r  r  r  r  r  r  r  rY  r  )r  r  r  	enumerater  r  get_function_hookrw   r  rD  r  get_method_hookr   ry   )r'  r  r  r  r  r  r  r   rW  rY  num_formalsformal_arg_typesformal_arg_exprsformal_arg_namesformal_arg_kindsformalactualsactualcallbackmethod_callbacks                       r   apply_function_pluginz'ExpressionChecker.apply_function_plugin  s=   . &*++-M-M%:L:L-M-M-M3S3Sk@R@R3S3S3S3S3Sk@R@R3S3S3S0P0PU;=O=O0P0P0P()9:: 	C 	COFG! C C (//	&0ABBB (//V=== :$V,33If4EFFFF$V,33D999 (//	&0ABBBBC {44X>>H'''8..%+%5.(.)#	 	 	   #k99(CCO"...)+66K"?$..%+%5.(.)#
 
 
  r   r   hook>Callable[[list[list[Expression]], CallableType], FunctionLike]c                H    t          |t                    rt          |j                  }t	          |||j        |j         fd          }d t          |          D             }t          |          D ]+\  }	}
|
D ]#}||	                             |                    $, |||          S t          |t                    sJ g }|j
        D ]G}                     ||||          }t          |t                    sJ |                    |           Ht          |          S )z@Helper to apply a signature hook for either a function or methodc                :                         |                    S r   ru  r  r  r'  s    r   r  z8ExpressionChecker.apply_signature_hook.<locals>.<lambda>5      $++d1g.. r   c                    g | ]}g S r   r   r  s     r   r  z:ExpressionChecker.apply_signature_hook.<locals>.<listcomp>7  s    7W7W7Wq7W7W7Wr   )r   r   r  r  r   r  r  r  r  r   r   apply_signature_hook)r'  r  r  r  r  r  r  r  r  r  r  r  r   r  adjusteds   ` `            r   r  z&ExpressionChecker.apply_signature_hook%  sa    fl++ 	%f.//K5  .....    8X7WE+DVDV7W7W7W#,-=#>#> B B% B BF$V,33DLAAAAB4(&111fj11111E ' '44T4IW[\\!(L99999X&&&&e$$$r   signature_hook,Callable[[FunctionSigContext], FunctionLike]c           	     D                           |||| fd          S )zKApply a plugin hook that may infer a more precise signature for a function.c                D     t          | |j                            S r   )rx   r  )r  sigrY  r'  r  s     r   r  zAExpressionChecker.apply_function_signature_hook.<locals>.<lambda>T  s$    ~~.@sGUYU].^.^__ r   )r  )r'  r  r  r  rY  r  r  s   `   ` `r   apply_function_signature_hookz/ExpressionChecker.apply_function_signature_hookE  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   )rz   r  )r  r  rY  pobject_typer'  r  s     r   r  z?ExpressionChecker.apply_method_signature_hook.<locals>.<lambda>i  s(    ..$\4gtxPP# # r   )r   r  )	r'  r  r  r  rY  r  rW  r  r  s	   `   `  `@r   apply_method_signature_hookz-ExpressionChecker.apply_method_signature_hookW  s\     '{33((      

 

 
	
r   callable_namec           	     2   t          |          }|t          |t                    rp|8| j                            |          }|r|                     |||||||          S n6| j                            |          }	|	r|                     ||||||	          S |S )a6  Attempt to determine a more accurate signature for a method call.

        This is done by looking up and applying a method signature hook (if one exists for the
        given method name).

        If no matching method signature hook is found, callee is returned unmodified. The same
        happens if the arguments refer to a non-method callable (this is allowed so that the code
        calling transform_callee_type needs to perform fewer boilerplate checks).

        Note: this method is *not* called automatically as part of check_call, because in some
        cases check_call is called multiple times while checking a single call (for example when
        dealing with overloads). Instead, this method needs to be called explicitly
        (if appropriate) before the signature is passed to check_call.
        )r   r   r   r  get_method_signature_hookr  get_function_signature_hookr  )
r'  r  r  r  r  rY  r  rW  method_sig_hookfunction_sig_hooks
             r   transform_callee_typez'ExpressionChecker.transform_callee_typeo  s    0 !(($FL)I)I$&"&+"G"G"V"V" ;;i)[Ra  
 %)K$K$KM$Z$Z!$ ==i)EV   r   r  Overloaded | Nonec                N   |j         sJ t          |j                  dk    st          |          dk    rdS t          t	          |j        d                   t
                    sdS t          t	          |j                  t
                    sdS | j        j        5  | j	        
                                5  t	          |                     |d         d                    }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          |t                    r|S dS )zSCheck if this looks like an application of a generic function to overload argument.r   Nr   r  )r3  r  r  r   r   r   rD  r  rN  r  rU  ru  r   )r'  r  r  r}  s       r   "is_generic_decorator_overload_callz4ExpressionChecker.is_generic_decorator_overload_call  s    $$$${$%%**c$ii1nn4/+*?*BCC\RR 	4/+*>??NN 	4X$ 	T 	T'')) T T*4;;tAwT;+R+RSST T T T T T T T T T T T T T T	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T h
++ 	Ots6   D5+C, D,C0	0D3C0	4DD
D
overloadedr   tuple[Type, Type] | Nonec                >   g }g }|j         D ]}t          |          }| j                                        5 }|                     ||gt
          g|          \  }	}
ddd           n# 1 swxY w Y   |                                rzt          |	          }t          |t                    st          |
          }t          |t                    s|
                    |           |
                    |           |r|sdS t          |          t          |          fS )a  Type-check application of a generic callable to an overload.

        We check call on each individual overload item, and then combine results into a new
        overload. This function should be only used if callee_type takes and returns a Callable.
        r  N)r   ri   r  rU  
check_callr5   has_new_errorsr   r   r   r  r   )r'  r  r  rL  r3  inferred_argsr  r   erritem_resultinferred_argp_item_resultp_inferred_args                r   handle_decorator_overload_callz0ExpressionChecker.handle_decorator_overload_call  s|    $ 	) 	)Dt$$$C'')) `S,0OOK#QXPY[^,_,_)\` ` ` ` ` ` ` ` ` ` ` ` ` ` `!!## +K88Mm\:: ,\::Nnl;;   000MM-(((( 	] 	4&!!:m#<#<<<s   #A&&A*	-A*	r  c           
     Z   |||J |                      ||          }t          |          }|r+|                     |||j        |j        ||j        |          }n.|,t          |t                    r|                     |||          S | 	                    ||j        |j        ||j        |j
        ||          \  }}t          |          }t          |j
        t                    rEt          |t                    r0|j        |j        |j
        _        |j        |j        |j
        _        |S )a?  Type check call expression.

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

        The 'member', 'callable_name' and 'object_type' are only used to call plugin hooks.
        If 'callable_name' is None but 'member' is not None (member call), try constructing
        'callable_name' using 'object_type' (the base type on which the method is called),
        for example 'typing.Mapping.get'.
        N)callable_noder  rW  )r  r   r  r  r  r  r   r   check_union_call_exprr  r  r`   r   
type_guardtype_is)r'  r  r-  r  rW  r  rD  proper_callees           r   r  z2ExpressionChecker.check_call_expr_with_callee_type  sD   &  V%7*** 00fEEM%k22 	F44{AFAKAKQ\ KK J{I$F$F--afEEE $FKK('# !0 	!
 	!
+ (44ah(( 	9Z|-T-T 	9'3&3&>#$0#0#8 r   r   c                   g }|                                 D ]}| j                                        5  t          |||ddd|| j        |                                 |
  
        }ddd           n# 1 swxY w Y   |                     |j        |d          }||                     ||          }|r|nd}	|	                    | 
                    ||||	                     t          |          S )zFType check calling a member expression where the base type is a union.F)rM  is_superis_operatororiginal_typer  in_literal_context	self_typeNT)skip_non_overlapping)r  r  rU  r   r  r_  r1  r  r  r  r  r   )
r'  r-  rW  r  resr  r  r4  r  item_object_types
             r   r  z'ExpressionChecker.check_union_call_expr  sZ   --// 	 	C''))  ,#" %"-'+'>'>'@'@!                 33AHdY]3^^H 00f==M&3=ssJJ55h=Rbcc    %S)))s   1A//A3	6A3	r  Expression | Noner  tuple[Type, Type]c
                   t          |          }t          |t                    rV|j        r3|                     ||          }
|
|                     ||
|          }||S |                     ||||||||          S t          |t                    r|                     |||||||          S t          |t                    s| j
                                        s|                     ||          S t          |t                    r|                     |||||          S t          |t                    rt!          d||ddd|	p|| j
        |                                 	  	        }|j        j        dz   }|                     |||||||          }|                     ||||||||          }|r| j
                            ||           |S t          |t.                    r|                     |j        |||||          S t          |t2                    r5|                     |j        |          }|                     ||||||          S t          |t8                    r+|                     t;          |          ||||||||	  	        S t          |t<                    rt=                      }|j        |_        ||fS | j         !                    ||          t          tD          j#                  fS )a  Type check a call.

        Also infer type arguments if the callee is a generic function.

        Return (result type, inferred callee type).

        Arguments:
            callee: type of the called value
            args: actual argument expressions
            arg_kinds: contains nodes.ARG_* constant for each argument in args
                 describing whether the argument is positional, *arg, etc.
            context: current expression context, used for inference.
            arg_names: names of arguments (optional)
            callable_node: associate the inferred callable type to this node,
                if specified
            callable_name: Fully-qualified name of the function/method to call,
                or None if unavailable (examples: 'builtins.open', 'typing.Mapping.get')
            object_type: If callable_name refers to a method, the type of the object
                on which the method is being called
        Nr  FTrM  r  r  r  r  r  z	.__call__)r  )$r   r   r   r3  r  r  rO  r   check_overload_callr   r  r>  check_any_type_callr   check_union_callr   r   r_  r  r   r  r  
store_typer   upper_boundr   analyze_type_type_calleer  r   r   r   r  r  not_callabler   rA  )r'  r  r  r  rY  r  r  r  rW  r  r  overloaded_resultcall_functionr3  r  rn  s                   r   r  zExpressionChecker.check_call  sf   @ !((fl++ V	Y 	1!DDVTRR
) )-(K(K
G) )% )400++	 	 	 
++ @	Y++iM;PW   (( <	Y0L0L0N0N <	Y++D&999	** :	Y((y)WUUU)) 8	Y1 +5vH#'#:#:#<#<
 
 
M #K0;>M 66}dIw	SY M __	 	F  ; ##M6:::M,, 	Y??"D)Wi   )) 	Y00gFFD??4y'9m\\\	** 	Y??v&&$ # 
 
 
 00 	Y!##C",CM3;8((9979CW;X;XXXr   c	                    |                                                                 }||j        r|j        }t          |j                  }	|                                r!t          |	t                    r|	j        j	        }t          |t                    r|j	        t          v r	|j        |fS |                                rp|                                j        rW|j        sP j                            t"          j                            |                                j                  |           n|                                r|                                j        r|j        s|                                j        s|                                }
i }|
j        D ]/\  }}|t.          k    r                     |
|          ||<   *d||<   0 j                            |                                j        ||           |                                }|rt          |j        t:                    rd}t=          |          D ]\  }}|t>          k    rt                                |                    }t          |tB                    rtE          d |j#        D                       rH|rD j                            d|tH          j%                   tM          tN          j(                  |fc S d}t          |j                  }	t          |	tR                    r@|	j*        r9tW          |j                  }tY          |           |-                    |          }|.                                r%t_          |          } 0                    ||          }tc          |||j2        |j3         fd          }|.                                r\tE          d	 |j*        D                       } 4                    ||||||          }|r!tc          |||j2        |j3         fd
          }|5                                }||t>          tl          gk    rto          |          dk    r                      d                   }                      d                   }t          |tp                    rgt          |tp                    rR|j9        tt          j;        k    r=|j9        tt          j<        k    r(|j=        |j=        cxk    r|j=        k    rn n	|j        |fS  >                    |||          } ?                    ||||||||            @                    ||||||           |                                rito          |          dk    rVt          |j         B                    d                    r.|-                    t          jD        |d                             }|r j        E                    ||           |rk| jF        G                    |          s|M jF        H                    |          r3 I                    ||||||||	  	        }|-                    |          }|j        |fS )zxType check a call that targets a callable value.

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

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

        Overloads are only checked if there is an implementation.
        F)r}   strict_optionalmrorh  r  r   r   r\   implrH   funcrO   r  r   r   r   rD  )r'  r  r  rw  symnoder   s         r   r  z!ExpressionChecker.can_return_noneF  s    
 $ 	 5H 	F 	FDjnnY//G<D$ 122 !y$	** !y$(( F9(%di>>>>>%hjj$)2DEEEEEur   r  c                    t          t                    rt          t          j                  S t          t                    rt          j         j                  }t          |t                    r|	                    d          }t          |          }t          |t                    r|	                    g           }|S t          t                    r4t           fd                                D             j                  S t          t                    r                     t!          j                            }t!          |          }t          |t                    r|	                              }n5t          |t$                    r t%          fd|j        D                       }|S t          t(                    r@t+                    j        j        dk    r#                     t+                              S t          t.                    r                               S  j                                       t          t          j                  S )	zzAnalyze the callee X in X(...) where X is Type[item].

        Return a Y that we can pass to check_call(Y, ...).
        
source_anyT)r  )r3  c                V    g | ]%}                     t          |                    &S r   )r  r   )r   r  rY  r'  s     r   r  z>ExpressionChecker.analyze_type_type_callee.<locals>.<listcomp>q  sA        11/"2E2EwOO  r   r  c                <    g | ]}|                                S )r  r  )r   cr  s     r   r  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  rR  r   r  r'   r   r  rE  r   r  r   r  r   r   r   r   r   r   r1  r  unsupported_type_typerA  )r'  r  rY  r  expandedr  s   ```   r   r  z*ExpressionChecker.analyze_type_type_callee^  sb   
 dG$$ 	H95$GGGGdH%% 		"49do>>C#|,, =''t'<<.sD99H(L11 @ $11B1??OdI&& 	    "1133   	   dK(( 	
 22?4CS3T3TV]^^F$V,,F&,// \--t-<<FJ// \#$Z$Z$Z$ZV\$Z$Z$Z[[MdI&& 	P>$+?+?+D+MQa+a+a001E1EwOOOdM** 	>77===&&tW555y+,,,r   c                    g }|D ]]}|                      |          }t          |          r"|                    t                                 H|                    |           ^|S )zInfer argument expression types in an empty context.

        In short, we basically recurse on each argument without considering
        in what context the argument was called.
        )ru  has_erased_componentr  r   )r'  r  r  r   r}  s        r    infer_arg_types_in_empty_contextz2ExpressionChecker.infer_arg_types_in_empty_context  sl      	% 	%C{{3''H#H-- %

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

8$$$$
r   c                T    t           j        }t          |          rdt           _        |S )ax  Adjust type inference of unions if type context has a recursive type.

        Return the old state. The caller must assign it to type_state.infer_unions
        afterwards.

        This is a hack to better support inference for recursive types.

        Note: This is performance-sensitive and must not be a context manager
        until mypyc supports them better.
        T)r   infer_unionsr   )r'  r  olds      r   $infer_more_unions_for_recursive_typez6ExpressionChecker.infer_more_unions_for_recursive_type  s)     %|,, 	+&*J#
r   c                
   dgt          |          z  }t          |          D ]q\  }}|D ]i}||                                         sM|j        |         }	|                     |	          }
|                     ||         |	          ||<   |
t          _        jrt          |          D ]%\  }}|s|                     ||                   ||<   &t          d |D                       sJ t          t          t                   |          S )a  Infer argument expression types using a callable type as context.

        For example, if callee argument 2 has type List[int], infer the
        argument expression with List[int] type context.

        Returns the inferred types of *actual arguments*.
        Nc              3     K   | ]}|d uV  	d S r   r   )r   r  s     r   r   z?ExpressionChecker.infer_arg_types_in_context.<locals>.<genexpr>  s&      00b2T>000000r   )r  r  is_starr  r$  ru  r   r"  r   r   r  r   )r'  r  r  r  r  r  r  r  air}  r#  r   s               r   r   z,ExpressionChecker.infer_arg_types_in_context  s    #'#d))!3#$455 	2 	2JAw 2 2 },,.. 
2%/2H CCHMMC"kk$r(H==CG.1J+2 cNN 	. 	.DAq .T!W--A00C00000000DJ$$$r   callableerror_contextc                   | j         d         }|s|S t          |t                                }|j        }t	          |          r-t	          |          rt          |          }t          |          }t          |          }t          |t                    s3t          |t                    rPt          d |j        D                       r2t          |          s#t          |          s|                                S t          |j        ||d          }g }|D ]K}	t#          |	          st%          |	          r|                    d           6|                    |	           L|                     |||d          S )a  Unify callable return type to type context to infer type vars.

        For example, if the return type is set[t] where 't' is a type variable
        of callable, and if the context is set[int], return callable modified
        by substituting 't' with 'int'.
        r8  c              3  Z   K   | ]&}t          t          |          t                    V  'd S r   )r   r   r   r   us     r   r   zPExpressionChecker.infer_function_type_arguments_using_context.<locals>.<genexpr>  s4      ZZAJq11;??ZZZZZZr   Tskip_unsatisfiedN)r  r"   r   rD  r   r   r   r   r   r   r   r   r   r   r  r,   r3  has_uninhabited_componentr  r  apply_generic_arguments)
r'  r)  r*  rL  
erased_ctxrD  
proper_retr  new_argsr   s
             r   r  z=ExpressionChecker.infer_function_type_arguments_using_context  s    # 	O 'sJLL99
$x(( 	5-@-E-E 	5 'x00H(44J %X..
z;//	0*i00	0 ZZIYZZZZZ	08 's++ 04H4M4M 0--///#*t
 
 
 ') 	% 	%C(-- %1Ec1J1J %%%%%$$$$ ++h , 
 
 	
r   r	  c           
          j                                         r j                                        5                       ||          }ddd           n# 1 swxY w Y                        ||t                              }	g }
t          |          D ]<\  }}|	|         dk    r|
                    d           '|
                    |           =t          |
||| 
                                 j                                                   \  }}d|	v r                     ||||||          \  }j        dk    rt          |          dk    rt          |v s	t          |v rt          |d                   }t!          |t"          t$          f          r                     d          |d<   nJ|r#t)                               d          |          s% j                             t,          j        |            j         j        j        st5          fd|D                       r|r!t7          ||j        j         fd	          }t          |||| 
                                 j                                         d
          \  }                     ||          }t?          j         |          }|*tC          d |D                       rtE          |           |S t%                      d
_#        fd|D             }n/tI          tJ          j&                  gt          j'                  z  } (                    ||          S )zInfer the type arguments for a generic callee type.

        Infer based on the types of arguments.

        Return a derived callable type that has the arguments applied.
        Nr   )rY  strictr  dictr   builtins.strc              3     K   | ][}|d u pRt          t          |          t                    p0t          t	          |                    t          j                  z  V  \d S r   )r   r   r   rg  r   r3  )r   r&  r  s     r   r   zBExpressionChecker.infer_function_type_arguments.<locals>.<genexpr>s  s       ? ?  T	 Foa00/BBF}Q''((3{/D+E+EE? ? ? ? ? ?r   c                :                         |                    S r   r  r&  r  r'  s    r   r  zAExpressionChecker.infer_function_type_arguments.<locals>.<lambda>  s    $++d1g"6"6 r   T)rY  r7  allow_polymorphicc              3  d   K   | ]+}|d uo"t          t          |          t                     V  ,d S r   )r   r   r   r%  s     r   r   zBExpressionChecker.infer_function_type_arguments.<locals>.<genexpr>  sT       / / TMY*_Q5G5G*Y*Y&Y/ / / / / /r   c           	     z    g | ]7}|1t          |fdt          j                  z   D                       nd 8S )Nc                     i | ]
}|j         S r   )r  )r   r  unknowns     r   
<dictcomp>zNExpressionChecker.infer_function_type_arguments.<locals>.<listcomp>.<dictcomp>  s    ___!g___r   )r&   r  r3  )r   r&  r  	free_varsrA  s     r   r  zCExpressionChecker.infer_function_type_arguments.<locals>.<listcomp>  sq     	! 	! 	!  = $____tK<Q7R7RU^7^___   "	! 	! 	!r   ))r  r>  r  rU  r   get_arg_infer_passesr  r  r  r+   argument_infer_context#infer_function_type_arguments_pass2special_sigr4   r7   r   r   r   r   rR  r   r  r   &KEYWORD_ARGUMENT_REQUIRES_STR_KEY_TYPEr  r!  r  r   r  r  r2  r   
apply_polyr   r   r  r   r   unannotatedr3  apply_inferred_arguments)r'  r  r  r  r  r  r	  rY  r  arg_pass_nums
pass1_argsr  r   r  r,  	first_argpoly_inferred_argspoly_callee_typeappliedrC  rA  s   ```                @@r   r+   z/ExpressionChecker.infer_function_type_arguments&  sP     8'')) x	Z
 ''))   ;;y2B 	              
 !55T9.>D		 M -/J#I.. + +3 #a''%%d++++%%c****< 3355x3355     M1 M!!/3/W/W$! 	0 	0,m '611&&!++)++yI/E/E ,M!,<==	i(O)DEE d'+~'F'FM!$$" d*T__^5T5TV_*`*` dHMM"2"Y[bccc8#6 73 ? ? ? ? '	? ? ? < < 7   
 (>!!#-#-66666( ($ 1N$ 779987799&*	1 	1 	1-"I $(#?#?!3W$ $ 
 $./?KK&3 / /// / / , ,& )111"N)++$(!	! 	! 	! 	! 	! 	! 0	! 	! 	! %Y%:;;<s;CX?Y?YYM,,[-QQQs   AA"%A"old_inferred_argsSequence[Type | None]&tuple[CallableType, list[Type | None]]c	           	     Z    t          |          }	t          t          |	                    D ]5\  }
}t          |t          t
          f          st          |          rd|	|
<   6                     ||	|          }|                                s|g fS |r!t          |||j
        |j         fd          } j                                        5                       |||          }ddd           n# 1 swxY w Y   t          |||||                                           \  }	}||	fS )a^  Perform second pass of generic function type argument inference.

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

        Return (the callee with type vars applied, inferred actual arg types).
        Nc                :                         |                    S r   r  r<  s    r   r  zGExpressionChecker.infer_function_type_arguments_pass2.<locals>.<lambda>  r  r   r;  )r  r  r   r   r   r   r  r2  r  r   r  r  r  rU  r   r+   rE  )r'  r  r  r  r  r  rR  r	  rY  r  r  r   r  r,  s   ` `           r   rF  z5ExpressionChecker.infer_function_type_arguments_pass2  s   2 .// 0 ? ?@@ 	( 	(FAs#/:;; (?STW?X?X (#'a 22;wWW%%'' 	#?" 	5%%.....    X##%% 	 	77T9.> I	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 9//11
 
 
q M))s   C44C8;C8r*   c                    | j         Et          | j                            d          | j                            d                    | _         | j         S )Nr#  typing.Iterable)r  r*   r  rR  r+  s    r   rE  z(ExpressionChecker.argument_infer_context  sO    (0,@##$455tx7J7JK\7]7]- -D) ,,r   num_actualsint	list[int]c                b   dg|z  }t          |j                  D ]\  }}d}	t          |j        |                   }
t          |
t                    r|
                                r||         D ]}t          ||                   }t          |t                    r$t          d||d          }|t          |          }t          |t                    r&|j        st          ||         t                    sd}	 n|	s1|
                    t                                r||         D ]}d||<   |S )a  Return pass numbers for args for two-pass argument type inference.

        For each actual, the pass number is either 1 (first pass) or 2 (second
        pass).

        Two-pass argument type inference primarily lets us infer types of
        lambdas more effectively.
        r   Fr  T)r  Nr  )r  r  r   r   r   r  r   r~   r3  rS   ru  ArgInferSecondPassQuery)r'  r  r  r  r  rY  r  r  r   skip_param_specp_formalr  p_actualcall_methods                 r   rD  z&ExpressionChecker.get_arg_infer_passes  sZ     cK 011 	 	FAs#O&v'7':;;H(L11 h6I6I6K6K )!,  A.y|<<H "(H55 D&1*h^b&c&c&c&2'6{'C'CH"8\:: ( 2 !+47J ? ?
 +/" szz2I2K2K'L'L )!,  ACFF
r   r  c                   t          ||j                  D ]\\  }}|rt          |          rF| j                            |||           t          t          j                  gt          |          z  }]| 	                    |||          S )zApply inferred values of type arguments to a generic function.

        Inferred_args contains the values of function type arguments.
        )
r  r3  r  r  could_not_infer_type_argumentsr   r   rA  r  r2  )r'  r  r  rY  inferred_typetvs         r   rK  z*ExpressionChecker.apply_inferred_arguments$	  s     "%]K4I!J!J 	U 	UM2  U$8$G$G U77RQQQ!()=!>!> ?#mBTBT T ++KPPPr   actual_typesactual_kindsactual_namesContext | Nonec	                   |&t          t          t          j                            }i }	|D ]#}
|
D ]}|	                    |d          dz   |	|<   $|                     ||||	|          \  }}t          |j                  D ]x\  }}||         }|                                r|s|s~|	                                r<| j
                            |||           |r|rd|v r|                     |||           n+|j        |         pd}| j
                            |||           d}|                                sxt!          ||          rg| j                                        s.t'          t)          |d                            t*                    r| j
                            |||           d}0|                                rG|rE||d                  t0          j        t0          j        fvr| j
                            ||           d}|                                |s+|j        dk    r | j
                            |||           d}t=          |          dk    rt?          fd|D                       }||d                  t0          j         k    r#|dk    r| j
        !                    d	|           d}||d                  t0          j        k    r#|dk    r| j
        !                    d
|           d}z|S )aO  Check that there is a value for all required arguments to a function.

        Also check that there are no duplicate values for arguments. Report found errors
        using 'messages' if it's not None. If 'messages' is given, 'context' must also be given.

        Return False if there were any errors. Otherwise return True
        Nr   r   r   ?Fpartialc              3  h   K   | ],}t          t          |                   t                    V  -d S r   )r   r   r   )r   krf  s     r   r   z9ExpressionChecker.check_argument_count.<locals>.<genexpr>|	  sM       , , #?<?#C#C]SS, , , , , ,r   z)ParamSpec.args should only be passed oncez+ParamSpec.kwargs should only be passed once)"ri   r   r   r:  r   check_for_extra_actual_argumentsr  r  is_requiredis_positionalr  too_few_argumentsmissing_classvar_callable_noter  missing_named_argumentr'  is_duplicate_mappingr  r>  r   r   r   duplicate_argument_valueis_namedr   r4   r7   too_many_positional_argumentsr  rG  r  sumr6   r  )r'  r  rf  rg  rh  r  rY  rW  r  all_actualsr  r&  okis_unexpected_arg_errorr  kindmapped_argsargnameparamspec_entriess     `                r   r  z&ExpressionChecker.check_argument_count8	  sq   $ ?wy'=>>??G
 ')' 	; 	;G ; ;!,A!6!6!:A; '+&K&KL,k7'
 '
##
 !!122 *	# *	#GAt*1-K!! (#+ (#>U (#%%'' NH..vwMMM" a} a9M9M;;KX_```$.q18SGH33FGWMMM\\^^ #(<\<) ) # 8//11 Z#LQ$@AA96 6  H55faIIIB## !Q0%/8ZZZ 66vwGGG""$$0" #v'9Y'F'FH..vwMMMBB%%))(+ , , , ,!,, , , ) )% $KN3u~EEJ[^_J_J_&QSZ[[["#KN3uFFK\_`K`K`&SU\]]]"	r   rz  tuple[bool, bool]c                p   d}d}t          |          D ]\  }	}
|	|vr|
t          j        k    st          ||	                   r~|
t          j        k    rnd}|
t          j        k    r| j                            ||           m|s
J d            ||	         }|J ||	         }| j                            ||||           d}|
t          j        k    rt          j        |j	        vs|
t          j        k    rt          ||	                   }t          |t          t          f          r|                    |	d          t          |j                  k     ra|
t          j        k    st          |t                    s| j                            ||           n| j                            |||           d}d}||fS )zCheck for extra actual arguments.

        Return tuple (was everything ok,
                      was there an extra keyword argument error [used to avoid duplicate errors]).
        FTz/Internal error: named kinds without names givenNr   )r  r   r6   is_non_empty_tupler7   r4   r  too_many_argumentsunexpected_keyword_argumentr  r   r   r   r   r  r  r   "too_many_arguments_from_typed_dict)r'  r  rf  rg  rh  rz  rY  r|  r{  r  r}  act_nameact_typeactual_types                 r   ro  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   )maxsplitrD  zN" is considered instance variable, to make it class variable use ClassVar[...])r   r   r   r   r  r  r   rs   r  is_classvarr  note)r'  rW  r  rY  r,  var_namer   s          r   rs  z0ExpressionChecker.missing_classvar_callable_note	  s     k:.. 		:k83T3T 		'..sQ.??KAx#''11DJty#$>$>y, TY5J HMMGH G G G    		 		 		 		     r   	check_argArgChecker | Nonec	                    |p| j         }t          |                                           }	t                    D ]\  }
}t	          |
          }
|t
          j        k    r0|                     |
          s| j        	                    |
|           |t
          j
        k    rY|                     |
          sDt          |
| j                            d                    }| j                            |
||           t!          |          D ]S\  }}t	          |j        |                   }d}fd|D             }t%          |          dk    rCt	          |d                            }t'          |t(                    rt%          |j                  dk    rt'          |j        d         t,                    r|t
          j        gt
          j        gt%          |          dz
  z  z   k    r|j        d         gfd|dd         D             z   }t'          |t,                    rnt	          |j                  }t'          |t(                    rE|j        sJ |j        }t
          j        gt
          j        gt%          |j                  dz
  z  z   }d}|sUfd	|D             }t'          |t,                    r t	          |j                  }t'          |t(                    rUt3          |j                    !|j        }t.          gt%          |          z  }n|j                  }t'          |t,                    sJ t	          |j                  }t'          |t4                    r6|j        } fd
t7          t%          |j                            D             }nMt'          |t8                    sJ |j        j        dk    sJ |j        d          |j        d         gt%          |          t%          |j                  z
  dz   z  z   |j         dz   d         z   }t.          gt%          |          z  }nt'          |t4                    r|g}t          g}nt'          |t8                    sJ |j        j        dk    sJ |j        d         gt%          |          z  }t.          gt%          |          z  }n1|gt%          |          z  }|j        |         gt%          |          z  }t%          |          t%          |          cxk    rt%          |          k    sn J t%          |          t%          |          k    rdt%          |          t%          |          k    r!| j        j                             ||           n!| j        j        !                    ||d           t%          |          t%          |          k    sJ t%          |          t%          |          k    sJ t          |||||          D ]`\  }}}}}|	"                    |||j#        |         |t'          |t,                              } ||||||dz   |dz   ||||         |
  
         aUdS )zCheck argument types against a callable type.

        Report errors if the argument types are not compatible.

        The check_call docstring describes some of the arguments.
         _typeshed.SupportsKeysAndGetItemFc                     g | ]
}|         S r   r   )r   r&  r  s     r   r  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>	  s    :::QIaL:::r   r   r   c                     g | ]
}|         S r   r   r   r&  r  s     r   r  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>
  s    >a>a>aPQy|>a>a>ar   NTc                     g | ]
}|         S r   r   r  s     r   r  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>
  s    >>>	!>>>r   c                8    g | ]}|k    rt           nt          S r   )r5   r6   )r   r  inner_unpack_indexs     r   r  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>"
  s8     4" 4" 4"() 014F/F/FGGH4" 4" 4"r   r  )allow_unpack)$r  r   rE  r  r   r   r6   is_valid_var_argr  invalid_var_argr7   is_valid_keyword_var_argr   r  rR  invalid_keyword_var_argr  r  r  r   r   r   r   r5   r  r   r   r  r   r   r  r  r  rr  expand_actual_typer  )!r'  r  r  r  r  r  rY  r  rW  mapperr}  r  
is_mappingr  r  orig_callee_arg_typeexpanded_tuplerg  p_actual_typerf  p_callee_typecallee_arg_typescallee_arg_kindsunpacked_typeinner_unpackinner_unpacked_typer  r  actual_kindcallee_arg_typecallee_arg_kindexpanded_actualr  s!    ``                             @r   r  z&ExpressionChecker.check_argument_types	  s   " /	 !<!<!>!>??"%i";"; 	P 	PHh&x00H5>))$2G2G2Q2Q)((7;;;5?**43P3PQY3Z3Z*'dh112TUU 
 00:wOOO#$455 l	 l	JAw#263CA3F#G#G  #N::::':::L7||a /	'!*0E F F}i882M/00A55"=#6q#9:FF 6$(8EM?cRYll]^N^;_(___$1$7$:#;>a>a>a>aU\]^]_]_U`>a>a>a#aL!"6
CC 2(78L8Q(R(R%mY?? 2#0#6666/</B,05/?5=/ #M$7 8 81 <C 0, .2N! *L>>>>g>>>2J?? (L$34H4M$N$NM!-;; #D-@AT-U-U*-5/</B,07y3w<</G,,+8+>?Q+RL#-lJ#G#GGGG2A,BS2T2T/)*=?OPP L 4A3F 04" 4" 4" 4"-23}7J3K3K-L-L4" 4" 4" 0 0 (22Ex'P'P P P P':'?'HL\'\'\'\'\$1$78K9K8K$L':'?'B&C'*7||c-:M6N6N'NQR'R'T%T '4&9:Lq:P:R:R&S%T !1 5<9s7||3K 0 0#M3CDD D,@+A(,4:(()-BBBBB,1:>NNNNN,9,>q,A+BS\\+Q(,39s7||+C(((<'=G'L$(.(8(;'<s7||'K$|$$GIIIIL8I8IIIIIII#$$L(9(999|$$s+;'<'<<<HL33FGDDDDHL2267DIII'((C,=,====='((C0@,A,AAAAAVY|5EGWW W  R[/? #)";";$Q'#!+OZ!H!H #< # # 	##QJEL   ml	 l	r   caller_typeoriginal_caller_typecaller_kindr=   rn  mouter_contextc           
        t          |          }t          |          }t          |          }t          |t                    r| j                            ||	           dS |                     ||          r| j                            ||	           dS t          ||| j        j	                  s| j        
                    |||||||	|
          }|                                s| j                            |||	|           | j                                        s&| j                            |||	|j                   dS dS dS )z.Check the type of a single argument in a call.)r  )rW  rY  r  )parent_errorN)r   r   r   r  deleted_as_rvaluehas_abstract_type_partconcrete_only_callr   r  r  incompatible_argumentr'  incompatible_argument_noteprefer_simple_messagescheck_possible_missing_awaitr  )r'  r  r  r  r  rn  r  r  rW  rY  r  errors               r   r  zExpressionChecker.check_arg`
  s~    &k22./CDD%k22k;// 	H&&{G<<<<<((kBB 	H''W=====Kdh>NOOO 	H22$'+ 3 	 	E &&((  33(+wU 4    82244 55guz    %	 	" r   c                    |                                 }                     |          }                     ||||          }	d}
d}d}                     ||	          }d}t	           fd|D                       r	  j                                        5                       |	||||||||	  	        }ddd           n# 1 swxY w Y   |rUd |D             }d |D             }t          ||j	        |j
                                       t          |                    f}n# t          $ r d}Y nw xY w                     |	|||||||          }|M|Kt          |d         |d                   r-t!          t#          |d                   t$                    s|sd}nd}|M|I|D ]F}t!          t#          |          x}t&                    r  j                            |j        |           G|S |Lt!          t#          |d                   x}t&                    r  j                            |j        |           |S                      |	|||||          }
t1          |
          dk    r	|
d         }nUt%          t2          j                  }t7          |          sd}nt8          j        } j                            ||||	                                |||||||
          }|r'|s% j                             tB          j"        |           |S )z(Checks a call to an overloaded function.NFc              3  B   K   | ]}                     |          V  d S r   )
real_union)r   r   r'  s     r   r   z8ExpressionChecker.check_overload_call.<locals>.<genexpr>
  s/      99ts##999999r   c                    g | ]
}|d          S rC  r   r-  s     r   r  z9ExpressionChecker.check_overload_call.<locals>.<listcomp>
  s    <<<qt<<<r   c                    g | ]
}|d          S )r   r   r-  s     r   r  z9ExpressionChecker.check_overload_call.<locals>.<listcomp>
  s    %C%C%Cqad%C%C%Cr   Tr   r   r  r  rW  )#r  r   plausible_overload_call_targetspossible_none_type_var_overlapr  r  rU  union_overload_resultr   rE  rF  combine_function_signaturesr   r   infer_overload_return_typer   r   r   r   r   r  warn_deprecated
definitionoverload_erased_call_targetsr  r   rA  is_operator_methodr  OPERATORno_variant_matches_argumentsr  r  r   TOO_MANY_UNION_COMBINATIONS)r'  r  r  r  r  r  rW  rY  r  plausible_targetserased_targetsinferred_typesunioned_resultnone_type_var_overlapunion_interruptedunioned_returnreturnsinferred_resultrd  r  ry  r  r3  s   `                      r   r  z%ExpressionChecker.check_overload_call
  s    ,,..99$??	 @@y)V
 
 59,037
 !% C CIO` a a!9999y99999 	X++--  %)%?%?)!!!%#-
& 
&N              " " 
<<^<<<G%C%CN%C%C%CN .gw|W^TT889I.9Y9YZZ&N ! ) ) )$(!!!)$ 99	
 	
 &>+E ?1-~a/@AA'"??13E#F#FPP' .'
 "&"&%)%3 H HM!}'E'E"E!|TT H00wGGG!!&q/ABBB!LQQ @((w???"" ::y)Yg
 
 ~"" *!,FF Y122F%m44 &~H11&)WSW1XXX'# ! 
 
  	Q%: 	QHMM*FPPPs6   =D# C 4D#  CD# CD# #D21D2r   list[CallableType]c           
        d
d}g }g }d}d}	t          |          D ]5\  }
}|
t          k    r ||          sd}|
t          k    r ||          sd}	6|j        D ]}t	          |||j        |j        fd          }| j                                        5  |	                                |
                    |           nm|                     ||||d	          rS|r|j        r|
                    |           n4|	r|j        r|
                    |           n|
                    |           d	d	d	           n# 1 swxY w Y   ||z   S )aE  Returns all overload call targets that having matching argument counts.

        If the given args contains a star-arg (*arg or **kwarg argument, except for
        ParamSpec), this method will ensure all star-arg overloads appear at the start
        of the list, instead of their usual location.

        The only exception is if the starred argument is something like a Tuple or a
        NamedTuple, which has a definitive "shape". If so, we don't move the corresponding
        alternative to the front since we can infer a more precise match using the original
        order.r  r   r   r   c                    t          |           } t          | t          t          f          p t          | t                    o| j        j        S r   )r   r   r   r   r   r  is_named_tupler  s    r   	has_shapezDExpressionChecker.plausible_overload_call_targets.<locals>.has_shape.  sB    !#&&CcI}#=>> 3))Ech.Er   FTc                    |          S r   r   r  r  s    r   r  zCExpressionChecker.plausible_overload_call_targets.<locals>.<lambda>A  s    iXYl r   Nr  r   r   r   )r  r6   r7   r   r   r  r  r  rU  r  r  r  
is_var_arg	is_kw_arg)r'  r  r  r  r   r  matchesstar_matchesargs_have_var_argargs_have_kw_argr}  r  r  s    `           r   r  z1ExpressionChecker.plausible_overload_call_targets  s   $	 	 	 	 ')+-! Y	22 	( 	(ID#x		#$(!y  3 #' > 	, 	,C59cmS]DZDZDZDZ    '')) , ,>>##/ NN3''''..Iy:JD  , ) ,S^ ,$++C0000) ,cm ,$++C0000s+++!, , , , , , , , , , , , , , ,$ g%%s   BD::D>	D>	r  c	                <   g }	g }
g }t          t          t          |                    }g }|D ]S}| j        | j        j        u sJ | j                                        5 }| j        j        5 }|                     |||||||          \  }}ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                                 }|r|s | j        	                    |           ||fc S t          |          }t          |t                    r|	                    |           n|	                    |           |
                    |           |                    |           |                    |           U|	sdS t          |	|
|||          rt          |
          r0| j        	                    |d                    |
d         |d         fS t          d |
D                       rJ| j        	                    |d                    t!          |
d                   t!          |d                   fS |                     t#          t$          j                  ||||||          S | j        	                    |d                    |
d         |d         fS )a  Attempts to find the first matching callable from the given list.

        If a match is found, returns a tuple containing the result type and the inferred
        callee type. (This tuple is meant to be eventually returned by check_call.)
        If multiple targets match due to ambiguous Any parameters, returns (AnyType, AnyType).
        If no targets match, returns None.

        Assumes all of the given targets have argument counts compatible with the caller.
        )r  r  r  r  rY  r  rW  Nr   c                ,    g | ]}t          |          S r   )r    )r   r  s     r   r  z@ExpressionChecker.infer_overload_return_type.<locals>.<listcomp>  s     I I ISC I I Ir   )r  maphas_any_typer  r  rU  rN  r  r  store_typesr   r   r   r  any_causes_overload_ambiguityall_same_typesr    r   r   r:  )r'  r  r  r  r  r  r  rW  rY  r  return_typesr  args_contain_any	type_mapsr  wr  rD  
infer_typeis_matchp_infer_types                        r   r  z,ExpressionChecker.infer_overload_return_typeW  sM   * ')#%%'s<;;<<24	$ 	$ 	$C8tx|++++'')) 
QX, 	+/??"!"+"+ '&3$/ ,; , ,(Hj	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ++---H $ ( 0H((+++#Z////.z::lL99 ( NN<0000NN3'''##H---%%j111  ### 	64*7L)YXabb 	6 l++ $$Yq\222#Aq(999 I IL I I IJJ $$Yq\222!,q/22J~a?P4Q4QQQ"9#9::''#"/ + '    H  1...?N1$555s6   B.+ BB.BB.BB..B2	5B2	c           	     r    g }|D ]1}|                      ||||||          r|                    |           2|S )zReturns a list of all targets that match the caller after erasing types.

        Assumes all of the given targets have argument counts compatible with the caller.
        )erased_signature_similarityr  )	r'  r  r  r  r  r  rY  r  r  s	            r   r  z.ExpressionChecker.overload_erased_call_targets  sW     ')$ 	$ 	$C//9isG  $ s###r   c                   |r|sdS d}t          |          D ]H}t          |t                    st          |j                  D ]}t          |t                    rd} nI|sdS t          d |D                       }t          |          D ];t          fd|D                       rt          fd|D                       r dS <dS )a  Heuristic to determine whether we need to try forcing union math.

        This is needed to avoid greedy type variable match in situations like this:
            @overload
            def foo(x: None) -> None: ...
            @overload
            def foo(x: T) -> list[T]: ...

            x: int | None
            foo(x)
        we want this call to infer list[int] | None, not list[int | None].
        FTc              3  >   K   | ]}t          |j                  V  d S r   )r  r  r   r  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>  s,      EEaQ[))EEEEEEr   c              3  r   K   | ]1}t          t          |j                           t                    V  2d S r   )r   r   r  r   r   r  r  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>  sL        JK
?1;q>::HEE     r   c              3  r   K   | ]1}t          t          |j                           t                    V  2d S r   )r   r   r  r   r  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>  sL        MN
?1;q>::KHH     r   )r   r   r   r   r   minr  r  )r'  r  r  has_optional_argr}  r  
min_prefixr  s          @r   r  z0ExpressionChecker.possible_none_type_var_overlap  sI    ! 		 	5 (33 	 	Hh	22 (88  dH-- '+$E   	5EE3DEEEEE
z"" 	 	A    O`         Rc    
 ttur   r   r  levellist[tuple[Type, Type]] | Nonec                   |
t           k    rt          t          |          D ]\  }}|                     |          r nR|                     ||          5  |                     ||||||||	          }ddd           n# 1 swxY w Y   ||gS dS |s~|                     ||          5  |                     ||||||||	          }ddd           n# 1 swxY w Y   |2t          t          |d                   t          t          f          s|gS t          ||                   }t          |t                    sJ g }|
                                D ]V}|                                }|||<   |                     |||||||||	|
dz   
  
        }||                    |           T dS t                      }g }|D ]0}||vr*|                    |           |                    |           1|S )a  Accepts a list of overload signatures and attempts to match calls by destructuring
        the first union.

        Return a list of (<return type>, <inferred variant type>) if call succeeds for every
        item of the desctructured union. Returns None if there is no match.
        Nr   r   )r   r   r  r  type_overrides_setr  r   r   r   r   r  copyr  rc  rg  r   r  )r'  r  r  r  r  r  r  rW  r  rY  r  idxr  r  directfirst_union	res_itemsr  new_arg_types
sub_resultseenr3  pairs                          r   r  z'ExpressionChecker.union_overload_result  s   , J "),, 	 	HCs##  ((y99 
 
55%!	 	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 u4 % 	 ((y99 
 
88%!	 	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 !*q	**Y,@+ +! x &in55+y11111	..00 	 	D%NN,,M!%M#33!%	 J %  ,,,, tt (+uu 	$ 	$D4d###s$   A>>BB(CCCc                    t          |          }t          |t                    o$t          |                                          dk    S r  )r   r   r   r  r  r'  r  s     r   r  zExpressionChecker.real_unionL  s=    c""#y))Kc#2D2D2F2F.G.G!.KKr   exprsSequence[Expression]	overridesSequence[Type]Iterator[None]c              #     K   t          |          t          |          k    sJ t          ||          D ]\  }}|| j        |<   	 dV  |D ]
}| j        |= dS # |D ]
}| j        |= w xY w)z5Set _temporary_ type overrides for given expressions.N)r  r  r  )r'  r  r  r   r  s        r   r  z$ExpressionChecker.type_overrides_setP  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>f  s,      >>1:a..>>>>>>r   r  r   r   c                    g | ]}g S r   r   r  s     r   r  zAExpressionChecker.combine_function_signatures.<locals>.<listcomp>y  s    %U%U%UQb%U%U%Ur   FTN)r  r  r  rD  r3  r  )r  r  rD  r3  r  )r   r   r   r:  r   r  #merge_typevars_in_callables_by_namer  r  r  r  r  r  rq  r5   r  rD  r   r  r6   r7   )r'  r   	callablesr3  r5  	new_kindsnew_returnstoo_complexry  r  new_kindtarget_kindr   union_returnr  
final_args	args_listrr  s                     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   r  z?ExpressionChecker.erased_signature_similarity.<locals>.<lambda>  s    PYZ[P\ r   NFr  r   original_ccaller_typer  r=   r  rn  rZ  r  r  r   rW  r  rY  rG   r  r   r   c
                4    t          | |          st          d S r   )arg_approximate_similarityr  )
r  r&  r  r  rn  r  r  rW  rY  r  s
             r   r  z@ExpressionChecker.erased_signature_similarity.<locals>.check_arg  s'     .k;GG   r   )rY  r  T)r  r   r&  r   r  r=   r  r   rn  rZ  r  rZ  r  r   rW  r  rY  rG   r  rG   r   r   )r   r  r  r  rU  r  r  r  )	r'  r  r  r  r  r  rY  r  r  s	    `       r   r  z-ExpressionChecker.erased_signature_similarity  sg    2y&"2F4DF\F\F\F\
 
 X##%% 	 	,,	9i9I4   	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 		 	 	 	"	%% # &    4 	 	 	55	s#   A11A58A5B 
B-,B-r0  c                H    t          j        ||| j        j        ||          S )z=Simple wrapper around mypy.applytype.apply_generic_arguments.r/  )r   r2  r  incompatible_typevar_value)r'  r)  r   rY  r0  s        r   r2  z)ExpressionChecker.apply_generic_arguments  s2     0H/-
 
 
 	
r   c                D   |                      |           t          |          }t          |t                    r6t          t          j        |          t          t          j        |          fS t          t          j                  t          t          j                  fS )Nr  )r   r   r   r   r   r  r:  )r'  r  r  s      r   r  z%ExpressionChecker.check_any_type_call  s    --d333 ((fg&& 	T	2vFFF	2vFFF 
 9122GI<R4S4SSSr   c                      j                                         5   fd|                                D             }d d d            n# 1 swxY w Y   t          d |D                       |fS )Nc           	     B    g | ]}                     |          S r   )r  )r   subtyper  r  r  rY  r'  s     r   r  z6ExpressionChecker.check_union_call.<locals>.<listcomp>	  s=        y'9MM  r   c                    g | ]
}|d          S rC  r   )r   r  s     r   r  z6ExpressionChecker.check_union_call.<locals>.<listcomp>  s    &A&A&A#s1v&A&A&Ar   )r  disable_type_namesr  r   )r'  r  r  r  r  rY  resultss   ` ```` r   r  z"ExpressionChecker.check_union_call   s     X((** 	 	       %4466  G	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 &&A&A&A&A&ABBFKKs   %AAAc                    t          || j        j                   |                     ||          }|                     ||          }| j                            |j        |           |S )z'Visit member expression (of form e.id).)r  r  r/  analyze_ordinary_member_accessr1  r  r   )r'  r-  rM  r3  r4  s        r   visit_member_exprz#ExpressionChecker.visit_member_expr  s`    a!566644Q	BB//6::  +++r   rG  c                
   |j         |                     |          S |                     |j        | j                  }|j        }d}t          |t                    r&t          |j        t                    r|j        j	        }t          |t                    r3t          |j        t                    r|j        j        p|j        j        }nd}t          |j        |||dd|| j        |                                 |||          }|S )zAnalyse member expression or member lvalue.

        An rvalue can be provided optionally to infer better setter type when is_lvalue is True.
        Nr|  F)	rM  r  r  r  r  r  module_symbol_tabler\  rG  )r}  r0  ru  r   r   r   r`   r   rW   rh  rs   r\  is_clsr   r@  r  r_  )	r'  r-  rM  rG  r  rw  r6  r\  member_types	            r   r3  z0ExpressionChecker.analyze_ordinary_member_access  s	    6((+++ !KK$.KIIM6D"&$(( 6Z	8-L-L 6&*io#$((  Z	3-G-G   )+?ty/?/#!+H#'#:#:#<#<$7  K r   	base_typec                `    t          |||ddd|| j        |                                 	  	        S )z}Analyse member access that is external, i.e. it cannot
        refer to private definitions. Return the result type.
        Fr  )r   r  r_  )r'  r  r9  rY  s       r   analyze_external_member_accessz0ExpressionChecker.analyze_external_member_accessB  sD     %##6688

 

 

 
	
r   c                6    t          | j        d                   S Nr8  )r   r  r+  s    r   r_  z$ExpressionChecker.is_literal_contextU  s    #D$5b$9:::r   r  r   fallback_namec                   |                      |          }|                                 rt          ||          S |du r8| j        *|                    t          ||                    | _        | j        S |du r8| j        *|                    t          ||                    | _        | j        S |                    t          ||                    S )az  Analyzes the given literal expression and determines if we should be
        inferring an Instance type, a Literal[...] type, or an Instance that
        remembers the original literal. We...

        1. ...Infer a normal Instance in most circumstances.

        2. ...Infer a Literal[...] if we're in a literal context. For example, if we
           were analyzing the "3" in "foo(3)" where "foo" has a signature of
           "def foo(Literal[3]) -> None", we'd want to infer that the "3" has a
           type of Literal[3] instead of Instance.

        3. ...Infer an Instance that remembers the original Literal if we're declaring
           a Final variable with an inferred type -- for example, "bar" in "bar: Final = 3"
           would be assigned an Instance that remembers it originated from a '3'. See
           the comments in Instance's constructor for more details.
        )r  r  TN)r`  F)rR  r_  r   r%  r  r&  )r'  r  r>  r  s       r   ra  z)ExpressionChecker.infer_literal_expr_typeX  s    " oom,,""$$ 	^US9999}}%-),):):)453)O)O)O *; * *D& ))~~&.*-*;*;)453)O)O)O +< + +D' **$$kX[6\6\6\$]]]r   leftr   rightc                    t          |j                  rt          |j                  rJ t          |j        |j        z   |                     d                    S )z$Concatenate two fixed length tuples.r  )r   r  )r   r   r   rR  )r'  r@  rA  s      r   concat_tupleszExpressionChecker.concat_tuples{  sZ    '
33Y8KEK8X8XYYY*u{*T__EU5V5V
 
 
 	
r   rR   c                8    |                      |j        d          S )z(Type check an integer literal (trivial).builtins.intra  r  r'  r-  s     r   visit_int_exprz ExpressionChecker.visit_int_expr      ++AG^DDDr   rf   c                8    |                      |j        d          S )z&Type check a string literal (trivial).r9  rF  rG  s     r   visit_str_exprz ExpressionChecker.visit_str_expr  rI  r   rA   c                8    |                      |j        d          S )z%Type check a bytes literal (trivial).r   rF  rG  s     r   visit_bytes_exprz"ExpressionChecker.visit_bytes_expr  s    ++AG5EFFFr   rN   c                ,    |                      d          S )z%Type check a float literal (trivial).zbuiltins.floatrR  rG  s     r   visit_float_exprz"ExpressionChecker.visit_float_expr  s    /000r   rE   c                ,    |                      d          S )zType check a complex literal.zbuiltins.complexrO  rG  s     r   visit_complex_exprz$ExpressionChecker.visit_complex_expr  s    1222r   rK   c                ,    |                      d          S )zType check '...'.zbuiltins.ellipsisrO  rG  s     r   visit_ellipsisz ExpressionChecker.visit_ellipsis  s    2333r   r[   c                D   |j         r|                     |j                   S |j        dk    s|j        dk    r|                     |          S |j        dk    r/t	          |j        t                    r|                     |          S |j        dk    r~t	          |j        t                    r%| j	        
                    |j        |j                  S t	          |j        t                    r%| j	        
                    |j        |j                  S |                     |j                  }t          |          }t	          |t                    r|j        dk    r|j        j                            d          }|r|j        dk    rt          |                     |j                            }t	          |t                    r`|j        j                            d          }|>t'          |j                  t'          |j                  |                     ||          S nt,          | j        j        j        v rt	          |t4                    r| j                            |          r|j                            d          }||j        j        j        d
k    rwt'          |j                  c| j                            ||          }| j                            d
|g          }|                    |j        t?          |          gz             S t@          }	|j        dk    rtC          |d          rCt          |                     |j                            }t	          |tD                    rtF          }	t	          |tD                    r>t          |                     |j                            }tC          |d          rtH          }	t,          | j        j        j        v r|j        dk    rt	          |t4                    r|j        j        d
k    rt          |                     |j                            }t	          |t                    rU|j        j        j        d
k    r@t'          |j                  ,|                    t?          |          g|j        z             S |j        tJ          j&        v rtJ          j&        |j                 }
|	tN          j(        u s|	tN          j)        u r/| *                    |
||j        ||	tN          j(        u           \  }}nh|	tN          j+        u rK| *                    tJ          j,        |
         |                     |j                  |j        |d          \  }}nt[          |	           ||_.        |S t_          d|j                   )z(Type check a binary operator expression.andor*%+__add__zbuiltins.tuple.__add____radd__Nr  r  |rd  )r9  r   rY  allow_reverseFzUnknown operator )0rr  ru  opcheck_boolean_opr   r@  rU   check_list_multiplyrA   r  check_str_interpolationrA  rf   r   r   partial_fallbackr  r  r   r   r   rC  rv   r  r  enable_incomplete_featurer   type_is_iterableiterable_item_typerm  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_methodr{  r)  use_reversemethodr3  rj  s                r   visit_op_exprzExpressionChecker.visit_op_expr  sD   : 	+;;qz***45==ADDLL((+++43;;:afh77;++A...43;;!&),, T*BB1617SSS!&'** T*BB1617SSSKK''	*955&	22 	qts{{.?DHHSSO ?#;?W#W#W$3DKK4H4H$I$I!/;; (9(J(O(S(ST^(_(_%(0 00@0FGGO23D3JKKS#'#5#56FHY#Z#ZZ'48+;+UUU"#4h?? V112CDD V
 ):(>(B(B:(N(N%)1,=BKO___/0@0FGGO$(H$?$?@QST$U$U	!%!<!<=MPY{![![/=="2"8Jv<N<N;O"O  >      #643;; !1?CC 5 %4DKK4H4H$I$I!/?? 5"4K*M:: 4 %4DKK4H4H$I$I!$%6HH 4"3K$("2"LLL /:: $)26FFF$3DKK4H4H$I$I!0)<<):?HL\\\+,=,CDDL,::)*:;;<?P?VV ;    49''')!$/Fj000K:CS4S4S&*mm'"-1C"C '4 ' '# 
 111&*mm08"kk!'22"' '4 ' '# [)))'AMM91499:::r   rD   c                (   d}t          |j        |j        dd         |j                  D ]a\  }}}|                     |          }|dk    s|dk    ra|                     |          }||                     |          }t          |          }|g}t          |t                    r!t          |	                                          }| 
                                }	g }
g }d}d}|D ]8}| j                            d          5 }|                     d||gt          g||	          \  }}| j                            |          }ddd           n# 1 swxY w Y   t          |t"                    rd}|                                r!|                     |          r| j                            d          5 }| j                            ||          \  }}ddd           n# 1 swxY w Y   |                                r0| j                            |                                           d}Mt/          |gt0          j        gdg| 
                                |                     d
                    }|j                            |           |                    |           |                                s3|r1|
                    |           |j                            |           
| j                            |                                           d}:|s|st          j        |          }t;          ||          sk|
s| j                            d|||           nt          j        |
          }|                     |||d          r| j                            ||d|           n|t          j         v rt          j         |         }tC          | j        j"                  5 }| #                    ||||d          \  }	}|j                            |           ddd           n# 1 swxY w Y   |                                sj|dv rf|                     |          }|                     ||          r;tI          |          }tI          |          }| j                            ||d|           n|dk    s|dk    r|                     |          }| 
                                }	|                     ||d          r;tI          |          }tI          |          }| j                            ||d|           |j                            d           ntK          d|           ||	}LtM          j'        ||	          }c|J |S )zType check a comparison expression.

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

/ "
 "$-$8$H$HM%i?? ". " H>>tYPZ\]^^^^-6-A/-R-RN#88 ) .3=/4	  9     " !% = =$-~{A!" !" !" Y111"-h7!$(/22 7a.2mm	5!4 /< / /+J N))+666	7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 '')) \h,.F.F!%U!3!3J00JGG \$7	$B$B	%8%D%D
55iZYZ[[[T!!X%9%9![[//
!^^--
,,Y
SW,XX X 3I > >I!4Z!@!@JH11)ZUVWWW%%d++++"#L(#L#LMMM ~#<<!!!s7   A EEE9G$$G(+G(.8P22P6	9P6	c                *   t          |t                    sdS t          |j        t                    ra|                     |j        |          }t          |t
                    r1|j        *| j                            |t          |                     |S dS )zIf expression has a partial generic type, return it without additional checks.

        In particular, this does not generate an error about a missing annotation.

        Otherwise, return None.
        N)
r   r`   r   rs   r;  r   r  r  r  r   )r'  r   r3  s      r   r  z1ExpressionChecker.find_partial_type_ref_fast_path  s     $(( 	4di%% 	))$)T::F&+.. 6;3J##D*<V*D*DEEEtr   )ry  
seen_typesrz  r~  ry  r  set[tuple[Type, Type]] | Nonerz  r~  c               @	   | j         j        j        sdS |t                      }||f|v rdS |                    ||f           t          ||f          \  }}t          |d          st          |d          r|sdS |rt          |          }t          |          }| j         j        	                                rdS | j         j        j
        r-t          |t                    rt          |t                    rdS n,t          |t                    st          |t                    rdS t          |t                    rGt          |t                    r2t          |          }t          |          }t          ||f          \  }}|r t          |          rt          |          rdS t          |t                     rt          |t                     r|j        j        }|j        j        }|t&          v rq|t&          v rh| j                             d          }	t+          ||	          }t+          ||	          }|                     |j        d         |j        d         |          S |j                            d          r|j                            d          r| j                             d          }
t+          ||
          }t+          ||
          }|                     |j        d         |j        d         |          p-|                     |j        d         |j        d         |          S |d	v r4||k    r.|                     |j        d         |j        d         |          S |t2          v r|t2          v rdS t          |t4                    rKt          |t4                    r6t          |j        t8                    rt          |j        t8                    rdS t          |t4                    rFt          |t                     r1|j        j        j        d
k    r|j                            d          rdS t          |t4                    rFt          |t                     r1|j        j        j        d
k    r|j                            d          rdS t=          ||d           S )a  Check for dangerous non-overlapping comparisons like 42 == 'no'.

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

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

        Return tuple (result type, inferred method type). The 'original_type'
        is used for error messages. The self_type is to bind self in methods
        (see analyze_member_access for more details).
        FT)rM  r  r  r  r  r  r  )r   r   r   check_union_method_call_by_namer   r  r_  check_method_call)	r'  rr  r9  r  r  rY  r  r  rj  s	            r   r  z+ExpressionChecker.check_method_call_by_name/  s      &2*	#I..	i++ 	77	4G]   ,'#6688
 
 
 %%fidIW^___r   c           
     d   g }g }|                                 D ]z}	| j                                        5  |                     ||	||||          \  }
}ddd           n# 1 swxY w Y   |                    |
           |                    |           {t          |          t          |          fS )a  Type check a call to a named method on an object with union type.

        This essentially checks the call using check_method_call_by_name() for each
        union item and unions the result. We do this to allow plugins to act on
        individual union items.
        N)r  r  r0  r  r  r   )r'  rr  r9  r  r  rY  r  r  meth_resr  r  	meth_items               r   r  z1ExpressionChecker.check_union_method_call_by_nameV  s     !++-- 	' 	'C ,,..  "&"@"@Cy'=# #i               JJtOOI&&&&$S))+@+J+JJJs   AA"	%A"	rj  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  r9  rj  r  r  rY  r  rW  s	            r   r  z#ExpressionChecker.check_method_callr  s     ,,YDD#0#<ii$ 00;ik 1 
 
 '!  
 
 	
r   op_namerl  	left_exprr  
right_exprc           
     0    d fd}dd}t          |          }t          |          }t          |t                    rt          t          j        |          }	|	|	fS t          |t                    rt          t          j        |          }	|	|	fS t
          j        |         }
 |||          } ||
|          }|t
          j        v rt          ||          r||||fg}nt          ||          rut          |t                    r`t          |t                    rK|j        j        |j        j        j        |j        u s' |||           |||
          k    r|
|||f||||fg}n||||f|
|||fg}d |D             }g }g }|D ]\  }}}} j                            d          5 }                     ||||gt           g          }d d d            n# 1 swxY w Y   |                                r=|                    |                                           |                    |           |c S t          |t                    r|j        j        s!t          |t                    r)|j        j        rt          t          j                  }	|	|	fS |s j                            d          5 }                     |||gt           g          }d d d            n# 1 swxY w Y   |                                r=|                    |                                           |                    |           n|S  j                            |d                    t1          |          dk    r|d         S t          t          j                  }||f}|S )Nr  r  r9  r   r   r  c                (   t          || j                  sdS j                                        5 }t	          | |ddd|j                                        	  	        }|                                rdn|cddd           S # 1 swxY w Y   dS )zYLooks up the given operator and returns the corresponding type,
            if it exists.NFT)	r@  r  rM  r  r  r  rY  r  r  )r   rR  r  rU  r   r  r_  r  )r  r9  r  r  rY  r'  s       r   lookup_operatorz>ExpressionChecker.check_op_reversible.<locals>.lookup_operator  s    
  	7DODD t'')) >Q. !#" $"+#'+'>'>'@'@
 
 
  !//11=ttv> > > > > > > > > > > > > > > > > >s   ABBBr  r   r  r  c                j    | j         j        D ]%}|j                            |          r	|j        c S &dS )a  Returns the name of the class that contains the actual definition of attr_name.

            So if class A defines foo and class B subclasses A, running
            'get_class_defined_in(B, "foo")` would return the full name of A.

            However, if B were to override and redefine foo, that method call would
            return the full name of B instead.

            If the attr name is not present in the given class or its MRO, returns None.
            N)r  r  rh  r  r   )r  r  clss      r   lookup_definerz=ExpressionChecker.check_op_reversible.<locals>.lookup_definer  sE     x| ( (9==++ (<'''(4r   r  c                (    g | ]\  }}}}|	||||fS r   r   )r   nar_  objr   s        r   r  z9ExpressionChecker.check_op_reversible.<locals>.<listcomp>  s0    ```+=BCQSQ_RS#&Q_Q_Q_r   Trv  r   r   )r  r  r9  r   r   r  )r  r   r  r  r   r  )r   r   r   r   r  r   ri  op_methods_that_shortcutr   r   r   r  alt_promoter  rU  r  r5   r  r  r  r  r:  r  r  r  rA  )r'  r  rl  r  r  r  rY  r  r  any_typerev_op_nameleft_opright_opvariants_rawvariantsr  r1  r@  rr  r  r   local_errorsr3  	error_anys   `     `                 r   check_op_reversiblez%ExpressionChecker.check_op_reversible  s   	> 	> 	> 	> 	> 	> 	>,	 	 	 	  $I..	$Z00
 i)) 	&y9iPPPHX%%j'** 	&y9jQQQHX%%
  27;!/'955"?;
;; i888\)U_=`=`8 %gy*EFLLz9--	9h//	 :x00	
 *6N.3zFFy'22nnZQ\6]6]]] h
I>'9j9LL '9j9h
I>L a```` &. 	 	"D&#s''T'BB ^l//c6C57)U\]]^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^**,, l::<<===v&&&&
 y(++ 	&	0N 	&z8,,	&1;1P	& y566HX%%  	''T'BB l77Ywi               
 **,, l::<<===v&&&& F1I&&&w<<11:	 455I	)FMs$   )"GG	G	3!K  K$'K$r   r^  c                ^   |r|g}t          |          }t          |t                    r.t          t	          |                                                    }|                     |          }g }g }	| j                                        5 }
|D ]Y}| 	                    ||t          |          ||          \  }}|                    |           |	                    |           Z	 ddd           n# 1 swxY w Y   |
                                s"t          |          }t          |	          }||fS ||fg}t          |          }t          |t                    r-fdt	          |                                          D             }g }g }	| j                            d          5 }
|D ]a}|D ]\\  }}| 	                    ||t          |          ||          \  }}|                    |           |	                    |           ]b	 ddd           n# 1 swxY w Y   |
                                r| j                            |
                                           |
                                d         }t          t!                                }|j        |_        |j        |_        t'          |          dk    r.t'          |          dk    r| j                            |           nat'          |          dk    r| j                            d	||           n0t'          |          dk    r| j                            d
||           t          |          }|                     t/          |	                    }||fS |                     |||gt2          g          S )zType check a binary operation which maps to a method call.

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

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

        Type inference is special-cased for this common construct.
        rE  r8  r  __mul__)ru  rA  r   rR  r@  r  rh  rj  )r'  r-  r  rl  r3  rj  s         r   ra  z%ExpressionChecker.check_list_multiply  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   )	ru  r  r  check_assignmentry  check_finalr1  r  r  )r'  r-  r  s      r   visit_assignment_exprz'ExpressionChecker.visit_assignment_expr
  s    AG$$!!!(AG444Q(// 	1 H%000,,QX666r   rr   c                (   |                      |j                  }|j        }|dk    r5|                                 }| j                            ||j                   n5t          j        |         }|                     ||g g |          \  }}||_	        |S )z7Type check an unary operation ('not', '-', '+' or '~').not)
ru  r   r_  r  r  check_for_truthy_typer   unary_op_methodsr  rj  )r'  r-  operand_typer_  r3  rr  rj  s          r   visit_unary_exprz"ExpressionChecker.visit_unary_expr  s    {{16**T;;>>++FH**<@@@@/3F"&"@"@WY[]_`"a"aFK'AMr   rQ   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_helperr1  r   r_  r   r   r`  )r'  r-  r3  p_results       r   visit_index_exprz"ExpressionChecker.visit_index_expr"  sw    
 --a00--a88"6**##%%	/8X..	/ )5.Fr   c                    |j         r|                     |j                   S |                     |j                  }|                     ||          S r   )rr  ru  rw  visit_index_with_type)r'  r-  rl  s      r   r  z)ExpressionChecker.visit_index_expr_helper2  sI    : 	+;;qz***KK''	)))Q777r   ProperType | Nonec           	     t    j         }|p|}t          |          }                     |           t          |t                    r.t          d |j        D                       rt          |i           }t          |t                    r5p|t           fd|
                                D             d          S t          |t                    rF j                                        r,t          |t                    r                     ||          S                      |          }|g }|D ]}                     ||          }	|	|                    |	           0 j                            t&          j                   t          d |j        D                       r3                     |          }
 j                            d|
            t/          t0          j                  c S t          |          S                      ||          S t          |t6                    r!                     |j                   d         S t          |t:                    r|                                r|                                j         r. !                    |                                j                   S |                                j"        s|                                j#        d	k    r $                    d
          S t          |tJ                    r* &                    |'                                |          S t          |tP                    r%|j)        j#        dk    r $                    d          S  *                    d|j         gtV          g|          \  }}|_,        |S )a  Analyze type of an index expression for a given type of base expression.

        The 'original_type' is used for error messages (currently used for union types). The
        'self_type' is to bind self in methods (see analyze_member_access for more details).
        c              3  @   K   | ]}t          |t                    V  d S r   r  r   s     r   r   z:ExpressionChecker.visit_index_with_type.<locals>.<genexpr>L  s=       4
 4
+-Jr:&&4
 4
 4
 4
 4
 4
r   c                >    g | ]}                     |          S r   )r  )r   r  r-  r  r'  s     r   r  z;ExpressionChecker.visit_index_with_type.<locals>.<listcomp>V  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>k  s,      RRQz!Z88RRRRRRr   zVariadic tuple can have length r   r8  ztypes.GenericAliasr[  __getitem__)r  r  )-rj  r   ru  r   r   r  r   r&   r   r   r  r  r>  rd   visit_tuple_slice_helpertry_getting_int_literalsvisit_tuple_index_helperr  r  r   TUPLE_INDEX_OUT_OF_RANGEmin_tuple_lengthr  r   r   rA  nonliteral_tuple_index_helperr   visit_typeddict_index_exprr   r  r  r  visit_enum_index_exprr2  r   rR  r   r  values_or_boundr   r  r  r5   rj  )r'  rl  r-  r  r  rj  nsoutrn  r  min_lenr3  rj  s   ` ``         r   r  z'ExpressionChecker.visit_index_with_type9  s    *	#I..	 	Ei++ 	3 4
 4
1:4
 4
 4
 1
 1
 	3 $Ir22Ii++ )	=)6YM(     (7799   #(    	9-- 	=$(2N2N2P2P 	= %++ G44YFFF..u55B~ 	= 	=A88AFFD'

4((((&6&OQRSSSRR)/RRRRR Z&*&;&;I&F&FG HMM*UG*U*UWXYYY&y';<<<<<,S11199)UKKK	=11 		=229agFFqII	<00 	=Y5J5J5L5L 	=$$&&. =11)2G2G2I2I17TUVVV%%''1=((**3FF';<<<i-- 	--))++Qy   	8,, 	1HLa1a1a??#8999"&"@"@		+# #A # #FK (AMMr   c                H   t          |j                  }||                                S |j        |         }t          |t                    sJ t          |j        t                    r$|                                dz
  |j        j        z   S |                                dz
  S r  )r   r   lengthr   r   r  r   r  )r'  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   r  r  r  r   r  maxrE  rF  r  )	r'  r@  rn  r  r  unpackedboundmiddleextra_itemss	            r   r  z*ExpressionChecker.visit_tuple_index_helper  s   *4:661uuS__$A''''DJ'''''z!}$4L)&*-----"6;//h 011 	& $H$899EeX.....:&*:::::Z]FFh11111=)-=====]1%F++D11DKKMMAAE66D))$//// t<z!}$'*\A-AOa4GXYIY0Z0ZZ[\		   	
T""4(((q554{***:a+o122#Js1l++l:;vhF	SWS^
 
 	
r   slicrd   c           	        d g}d g}d g}|j         r4|                     |j                   }||                     ||          S |}|j        r4|                     |j                  }||                     ||          S |}|j        r4|                     |j                  }||                     ||          S |}g }	t          j        |||          D ]\  }
}}|                    |
|||                     d                    }|@| j	        
                    t          j        |           t          t          j                  c S |	                    |           t#          |	          S )Nr  r  )begin_indexr  r  	end_indexstride	itertoolsproductslicerR  r  r  r   !AMBIGUOUS_SLICE_OF_VARIADIC_TUPLEr   r   rA  r  r   )r'  rl  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   rj  list[int] | Nonec                   t          |t                    r|j        gS t          |t                    ra|j        dk    r'|j        }t          |t                    rd|j        z  gS |j        dk    r$|j        }t          |t                    r|j        gS t          |                     |                    }t          |t                    r|j	        |j	        }t          |t                    r"t          |j        t                    r|j        gS t          |t                    rgg }t          |j                  D ]N}t          |t                    r5t          |j        t                    r|                    |j                   L dS |S dS )a  If the given expression or type corresponds to an int literal
        or a union of int literals, returns a list of the underlying ints.
        Otherwise, returns None.

        Specifically, this function is guaranteed to return a list with
        one or more ints if one the following is true:

        1. 'expr' is a IntExpr or a UnaryExpr backed by an IntExpr
        2. 'typ' is a LiteralType containing an int
        3. 'typ' is a UnionType containing only LiteralType of ints
        -r8  rZ  N)r   rR   r  rr   r_  r   r   ru  r   r`  r   rZ  r   r   r   r  )r'  rj  operandr  r  r  s         r   r  z*ExpressionChecker.try_getting_int_literals  s{    eW%% 
	+K= y)) 	+x3*gw// 0.//x3*gw// +#M?*dkk%0011c8$$ 	')=)I&Cc;'' 	Jsy#,F,F 	I;c9%% 	C(33    dK00  Z
C5P5P  JJtz****44Jtr   c                    |                      d||gt          g|           |                     |          }t          |t                    r| j                            d|g          S |S )Nr   r;  r  )r  r5   union_tuple_fallback_itemr   rd   r  rm  )r'  rl  rj  unions       r   r  z/ExpressionChecker.nonliteral_tuple_index_helper  sl    &&}i%7)]b&ccc..y99eY'' 	J8../?%IIIr   c                   g }|j         D ]}t          |t                    rt          |j                  }t          |t
                    rt          |j                  }t          |t                    r1|j        j        dk    r!|	                    |j
        d                    t          |	                    |           t          |          S )Nr  r   )r   r   r   r   r  r   r  r   r   r  r  NotImplementedErrorr   )r'  rl  r   r  r  s        r   r-  z+ExpressionChecker.union_tuple_fallback_item  s    O 	# 	#D$
++ # /	 : :m-=>> O$3M4M$N$NM}h77.%*37GGGLL!3A!67777--T""""$U+++r   td_typesetitemtuple[Type, set[str]]c                   t          |t                    r
|j        g}n(t          |                     |                    }t          |t
                    rt          |j                  }n|g}g }t          |          D ]}t          |t                    r|j
        |j
        }t          |t                    rJt          |j        t                    r0|j        j        j        dk    r|                    |j                   | j                            ||           t'          t(          j                  t-                      fc S g }|D ]y}	|j                            |	          }
|
F| j                            ||	||           t'          t(          j                  t-                      fc S |                    |
           zt3          |          t-          |          fS )Nr   )r   rf   r  r   ru  r   r  r   r   r   r`  r   r  r  r  r   r  r  $typeddict_key_must_be_string_literalr   r   rA  rg  r  typeddict_key_not_foundr   )r'  r1  rj  r2  	key_namesr  	key_typesr  value_typeskey_namer  s              r   r  z,ExpressionChecker.visit_typeddict_index_expr,  s    eW%% 	@II!$++e"4"455C#y)) "(,SY		 E	I,Y77 @ @h11 9h6O6['8H x55@"8>377@ !).7;KKK$$X^4444HAA'5QQQ"9#788#%%????! 	/ 	/H **844J!00(E7SSSy344cee;;;;"":....$[113y>>AAr   	enum_typec                    |                      d          }| j                            |                     |          ||dd           t	          |g           S )Nr9  zEnum index should be a stringzactual index type)rR  r  check_subtyperu  r   )r'  r;  rj  rY  string_types        r   r  z'ExpressionChecker.visit_enum_index_exprQ  s\     !OON;;KK+	
 	
 	
 	2&&&r   rC   c                   |                      |j        t          t          j                  dd          }|j        }| j        j        }|j        rRt          |t          t          j                            s+t          ||          r| j
                            ||           |j        r+t          |          r| j
                            d||           t          || j        j        | j        j        | j
        |           |S )zType check a cast expression.Tr  ro  r  zTarget type of castr;  )ru  r   r   r   r:  r  r  r  warn_redundant_castsr   r  redundant_castdisallow_any_unimportedr   unimported_type_becomes_anyr   is_typeshed_stub)r'  r   source_typetarget_typer  s        r   visit_cast_exprz!ExpressionChecker.visit_cast_expr^  s   kkI !788"!	 " 
 
 i("(	7 gi6L.M.MNN	7 [+66	7
 H##K666* 	[/KK/X/X 	[H001FUYZZZ)48+DdhX\	
 	
 	
 	
 r   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 )Nr8  Tr@  zC"assert_type" expects everything to be "Any" in unchecked functions)ru  r   r  r  r|  r  r   r   r  r   r   r`  r   r>  r  r  assert_type_fail)r'  r   rF  rG  proper_source_types        r   visit_assert_type_exprz(ExpressionChecker.visit_assert_type_expru  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   ra   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.Nr8  Tr  ro  z9'reveal_type' always outputs 'Any' in unchecked functionsc                (    i | ]}|j         |j        S r   )r@  r  )r   var_nodes     r   rB  z7ExpressionChecker.visit_reveal_expr.<locals>.<dictcomp>  s    SSShX]HMSSSr   )r}  r<   r   ru  r  r  r|  r  reveal_typer>  r  check_reveal_importedlocal_nodesreveal_localsr   )r'  r   revealed_typenames_to_typess       r   visit_reveal_exprz#ExpressionChecker.visit_reveal_expr  s7   9##9((( KK	(9"(=QU (  M 81 1$$]DI>>>x3355 HMMSUYU^   **4000   81 1 '3 TS$BRSSSS  &&~t<<<**4000::r   c                   t           j        | j        j        j        vrd S d}|j        t          k    rd}n|j        t          k    r
|j        sd}nd S | j        	                    d| d|t           j                   |dk    rY| j        j        j
        dk    rdnd	}d
                    ||          }| j                            ||t           j                   d S d S )N rT  rQ  zName "z" is not definedr  )r     typingtyping_extensionszXDid you forget to import it from "{module}"? (Suggestion: "from {module} import {name}"))moduler@  )r  UNIMPORTED_REVEALr  r  r  r}  r;   r<   is_importedr  r  r  r  )r'  r   r@  r]  hints        r   rR  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   tapprl   c                `   t          |j        t                    rt          |j        j        t                    r|j        j        j        r|                                 S t          |j        j        |j        | j	        j
        |j        j        j        || j	        j                  }t          |          }t          |t                    r6t          |j        | j                  }|                     ||j        |          S t          |t(                    rQ|j        j        j        r@t          |j        j        | j                  }|                     ||j        j        |          S t          |t.                    r|                     |          S | j	        
                    t2          j        |           t7          t8          j                  S t          |                     |j                            }t          |t>          t@          f          rU|!                                s%| j	        
                    t2          j        |           |                     ||j        |          S t          |t6                    rt7          t8          j"        |          S t7          t8          j#                  S )a{  Type check a type application (expr[type, ...]).

        There are two different options here, depending on whether expr refers
        to a type alias or directly to a generic class. In the first case we need
        to use a dedicated function typeanal.instantiate_type_alias(). This
        is due to slight differences in how type arguments are applied and checked.
        r  )$r   r   r`   r   r   python_3_12_type_aliastype_alias_type_typer   r   r  r  r  r  r   r   r   r  rR   apply_type_arguments_to_callabler  r   rc  r  r   r1  r   ONLY_CLASS_APPLICATIONr   r   rA  ru  r   r   r  r  r:  )r'  ra  r  r  s       r   visit_type_applicationz(ExpressionChecker.visit_type_application  s2    di)) 	5j.S.S 	5y~4 300222)	
	&  D #4((D$)) 
5%diAA<<RDQQQD),, 51F1K1Z 5%d&;&@$/RR<<RAVA[]abbbD-00 5;;DAAA.EtLLLy3444 T[[3344b<455 	O>>## M.EtLLL88TZNNNb'"" 	F95"EEEEy-...r   aliasrk   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`.
        TrP  )rV  r   )r'  rh  s     r   visit_type_alias_exprz'ExpressionChecker.visit_type_alias_expr  s"     11%*%Z^1___r   )rQ  r   rQ  c                  |j         r|                                 S t          |j        t                    r%|j        j        rt          t          j                  S | j	        j
        j        o| j        }t          t          |g |j        |j        | j	        j
        || j        j                            }t          |t                    r?t'          |j        | j                  }|j        r|S |                     ||j        |          S t          |t2                    rDt5          |          j        j        dk    r't'          t5          |          j        | j                  S t          |t8                    r|                     |          S t          |t<                    rt?          ||j        |j                  S t          |t                    rt          t          j         |          S t          |tB                    r<|j"        r5| j	        j
        j#        dk    r | j	        $                    d|j%                  S |rt          t          j&                  S |                     d          S )a  Get type of a type alias (could be generic) in a runtime expression.

        Note that this function can be called only if the alias appears _not_
        as a target of type application, which is treated separately in the
        visit_type_application method. Some examples where this method is called are
        casts and instantiation:

            class LongName(Generic[T]): ...
            A = LongName[int]

            x = A()
            y = cast(A, ...)
        )disallow_anyr  r  rE  rF  r  r  ztypes.UnionTyper[  )'rc  rd  r   ry  r   invalidr   r   rA  r  r  disallow_any_genericsr   r   r   rE  rF  r  r  r   r  rR  r  re  r  r   r   r   r   r1  r   r   r  r   r  r  rm  r   r:  )r'  rh  rL  rQ  rl  r  r  s          r   rV  z/ExpressionChecker.alias_type_in_runtime_context  s:     ' 	/,,...elH-- 	1%,2F 	19/000
 x'=P$.
 )X]  

 

 dH%% 	: "$)T_==B} 	88TYLLLtY''	: 4  %.2BBB#N4$8$8$=tOOOm,, 	:77===h'' 	:DtyEEEEg&& 	:95$GGGGtY''
	:'
	:  /7::8../@$*MMM 7y5666??#8999r   r   c                `   |                                 r|                                j        j        }nt	          |j                  }t          |          }t          |j        |          D ]\  }}t          |t                    rt          t          |          t          t          t          t          f          sb| j                            dt!          || j        j                   |           t          t$          j                  gt)          |          z  c S |rt+          d |D                       st	          |          S |                                 sJ |                                }t-          |||j        |j                  }t3          || j        j        d          sFt5          || j        j        | j        j        d| j        j                   t	          |j                  }t;          d t=          |          D                       }	t)          |          |	z
  d	z
  }
||	         }t          |t>                    sJ tA          tC          |          |	|
          \  }}}t	          |          tE          t	          |          |j#                  gz   t	          |          z   S )
a  Handle directly applying type arguments to a variadic Callable.

        This is needed in situations where e.g. variadic class object appears in
        runtime context. For example:
            class C(Generic[T, Unpack[Ts]]): ...
            x = C[int, str]()

        We simply group the arguments that need to go into Ts variable into a TupleType,
        similar to how it is done in other places using split_with_prefix_and_suffix().
        zQCan only replace ParamSpec with a parameter types list or another ParamSpec, got c              3  @   K   | ]}t          |t                    V  d S r   r   r   r  s     r   r   z7ExpressionChecker.split_for_callable.<locals>.<genexpr>d  s-      MM1z!-=>>MMMMMMr   rm  T)empty_tuple_indexF)rl  r  c              3  J   K   | ]\  }}t          |t                    |V  d S r   rr  )r   r  r  s      r   r   z7ExpressionChecker.split_for_callable.<locals>.<genexpr>t  s6      YYFQAGW9X9XYaYYYYYYr   r   )$r  r  r  r2  r  r3  r   r  r   r   r   r   r   r   r  r  r3   r  r   rA  r  r  r   rE  rF  r   r   r  r  nextr  r   r   tupler   r   )r'  r   r  rL  varsre  r   r  fakeprefixsuffixtvtstartr  r"  s                  r   split_for_callablez$ExpressionChecker.split_for_callableC  s    ==?? 	%==??'1DD$$D$T** 1;-- 
	G 
	GGB"m,, 	G!#C((:}g{*[  G HMMX3>sDHDT3U3UX X  
 $I$899:SYYFFFF 	3MMMMMMM 	::}}}}d#*EEE !tx}MMM 	#dhmTX]PTPXP`    	??DYYiooYYYYYTV#a'6l#/000009%++vvVVvsE{{iVc6HIIJJTRUYYVVr   r  c                    t          |          }t          |t                    r|                                r|                                j        j        }nt          |j                  }t          d |D                       }t          d |D                       }t                    |k     s!t                    t          |          k    r|s|                                r|                                j        dk    rt          t          t                     j                            d                    gt           gdgt          t                     j                            d                    |j        d|j        |j                  S  j                            |t          |          t                               t-          t.          j                  S                      |                     |                    S t          |t6                    r.|j        D ]}|                                r|                                j        j        }nt          |j                  }t          d |D                       }t          d |D                       }t                    |k     s t                    t          |          k    rT|sR j                            |t          |          t                               t-          t.          j                  c S t7           fd	|j        D                       S t-          t.          j                  S )
a{  Apply type arguments to a generic callable type coming from a type object.

        This will first perform type arguments count checks, report the
        error as needed, and return the correct kind of Any. As a special
        case this returns Any for non-callable types, because if type object type
        is not callable, then an error should be already reported.
        c              3  @   K   | ]}|                                  V  d S r   has_defaultr  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s-      GGAMMOO 3GGGGGGr   c              3  @   K   | ]}t          |t                    V  d S r   rr  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s-      $X$XZ3C%D%D$X$X$X$X$X$Xr   r  rv  N)r@  r  r9  c              3  @   K   | ]}|                                  V  d S r   r  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s-      #K#KA$7#K#K#K#K#K#Kr   c              3  @   K   | ]}t          |t                    V  d S r   rr  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>  s-      (\(\QA7G)H)H(\(\(\(\(\(\r   c           
     h    g | ].}                     |                    |                    /S r   )r2  r}  )r   r   r  rL  r'  s     r   r  zFExpressionChecker.apply_type_arguments_to_callable.<locals>.<listcomp>  sP        00T5L5LRQUWZ5[5[]`aa  r   )r   r   r   r  r  r  r2  r  r3  ry  r  r  r   r   r  rR  r5   r  r  r9  r  incompatible_type_applicationr   r   rA  r2  r}  r   r   r:  )r'  r  r  rL  r2  min_arg_counthas_type_var_tupler   s   ` ``    r   re  z2ExpressionChecker.apply_type_arguments_to_callable{  sH    R  b,'' '	a~~ / NN,,1;		 ..	GGYGGGGGM!$$X$Xi$X$X$X!X!XD		M))SYYY-G-G( .H>>## (8(8(AEU(U(U ("4::tx/B/B7/K/KLLM 	!$t**dh.A.A'.J.JKK$#%=!#	 	 	 	 66!3y>>3t99c   y3444//D4K4KBPTVY4Z4Z\_```b*%% 	h 9 9>>## 3 " 0 0 5 ?II $R\ 2 2I ##K#K#K#K#K K K%((\(\R[(\(\(\%\%\"II--TS^^1K1K, 2LH::%s9~~s4yy#   #9#788888      h     y-...r   rU   c                0    |                      |dd          S )z#Type check a list expression [...].ra  z<list>check_lst_exprrG  s     r   visit_list_exprz!ExpressionChecker.visit_list_expr  s    ""1ox@@@r   rc   c                0    |                      |dd          S )Nr   z<set>r  rG  s     r   visit_set_exprz ExpressionChecker.visit_set_expr  s    ""1ng>>>r   ListExpr | SetExpr | TupleExprcontainer_fullnamec                ~   | j         d         }|s|j        sdS | j        j        rdS | j                            |d          }|t          |t                    r|ndS g }t                      }|j        D ]s}t          |t                    rt                      | j        |<    dS |                     |          }||vr*|                    |           |                    |           t|                     |          }	|	t                      | j        |<   dS | j                            ||	g          }
|
| j        |<   |
S )a  
        Fast path to determine the type of a list or set literal,
        based on the list of entries. This mostly impacts large
        module-level constant definitions.

        Limitations:

         - no active type context
         - at least one item
         - no star expressions
         - not after deferral
         - either exactly one distinct type inside,
           or the joined type of all entries is an Instance or Tuple type,
        r8  N)r  r   r  r|  r  r  r   r   rg  re   r   ru  r  r   _first_or_join_fast_itemrm  )r'  r-  r  rL  rtr	  
values_setr  r  vtcts              r   fast_container_typez%ExpressionChecker.fast_container_type  sS   " # 	ag 	48) 	4##At,,>#B11;22t; #
G 		$ 		$D$)) (0

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

  1555r   rj   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   re   r   r-  s     r   r  z;ExpressionChecker.tuple_context_matches.<locals>.<listcomp>1  s'    MMMaZ85L5LMMMMr   c                <    g | ]}t          |t                    |S r   r  r  s     r   r  z;ExpressionChecker.tuple_context_matches.<locals>.<listcomp>4  s'    AAAaAx)@)@AAAAr   r   Fc              3  J   K   | ]\  }}t          |t                    |V  d S r   r  )r   r  lvs      r   r   z:ExpressionChecker.tuple_context_matches.<locals>.<genexpr>6  s7      ``UQzRTV^G_G_`q``````r   )r   r   r  ru  r  )r'  r   rL  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.r8  Nc                    g | ]D}t          |t                    r                    |          st          |t                    B|ES r   )r   r   r  r   r   )r   r   r-  r'  s     r   r  z6ExpressionChecker.visit_tuple_expr.<locals>.<listcomp>?  sh     ! ! !q),,! 261K1KAq1Q1Q! %Q(ABB	!! ! !r   r   r   Fr  z<tuple>T)"r   r  r   r   r   r   r  r   r  r   r   r   r  r   rv   r  r  rd  r  re   r   r  ru  r   r  rc  re  rf  rm  r  r   r   r:  r&   )r'  r-  r  type_context_itemstuples_in_contextunpack_in_contextseen_unpack_in_itemsallow_precise_tuplesr   r  r  r  ctx_itemrL  ttr{  r)  fallback_itemr3  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   rI   c                   | j         d         }|s|j        sdS | j        j        rdS | j                            |d          }|t          |t                    r|ndS g }g }t                      }t                      }d}|j        D ]!\  }	}
|	t          | 
                    |
                    }t          |t                    rC|j        j        dk    r3t          |j                  dk    r|j        d         |j        d         f}t                      | j        |<    dS | 
                    |	          }||vr*|                    |           |                    |           | 
                    |
          }||vr*|                    |           |                    |           #|                     |          }|t                      | j        |<   dS |                     |          }|t                      | j        |<   dS |r0|d         |k    s|d         |k    rt                      | j        |<   dS | j                            d||g          }|| j        |<   |S )a  
        Fast path to determine the type of a dict literal,
        based on the list of entries. This mostly impacts large
        module-level constant definitions.

        Limitations:

         - no active type context
         - at least one item
         - only supported star expressions are other dict instances
         - either exactly one distinct type (keys and values separately) inside,
           or the joined type of all entries is an Instance or Tuple type
        r8  Nrd  r  r   r   )r  r   r  r|  r  r  r   r   rg  r   ru  r  r   r  r  r   r  r   r  rm  )r'  r-  rL  r  r  r	  keys_setr  stargsr  r  stkey_tvalue_tktr  dts                    r   fast_dict_typez ExpressionChecker.fast_dict_type  sh    # 	ag 	48) 	4##At,,>#B11;22t;!ee #
+/' 	, 	,JC{$T[[%7%788r8,, (O;;BG)) gaj"'!*5FF,4JJD&q)44C((((KK&&&LL'''++e,,*,,MM'***NN7+++**400:$,JJDq!4**622:$,JJDq!4 	vayB&)r//$,JJDq!4X((2r(CC "1	r   typeddict_contextc                    |                      ||j        |d           }t          |          }t          |t                    r|                                S |                                S )N)r  r  rY  r  )r  r   r   r   r   r  )r'  r-  r  rU  rD  s        r   "check_typeddict_literal_in_contextz4ExpressionChecker.check_typeddict_literal_in_context  sn     ;;$QWaT < 
 
 #=11h.. 	,))+++ ..000r   c           
        |                      | j        d         |          \  }}|rt          |          dk    r|r|                     ||d                   S |D ]}| j                                        5 }| j        j        5 }|                     ||          }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                                r| j        	                    |           |c S |r| j        
                    ||           |                     |          }|r|S t          ddt          dd          g |                                 t          t           j                            }	t          d	d	t          d
d          g |                                 t          t           j                            }
g }g }|j        D ] \  }}|F|                    |           |                    | j                            d|	|
g                     Nt+          ||g          }|j        dk    r|j        |_        |j        |_        n|j        |_        |j        |_        |j        |_        |j        |_        |                    |           |                    t5          |	|
g|                     d                               t9          |t:          j        gt          |          z  dgt          |          z  | j                            d|	|
g          |                     d          d|	|
g          }|                     ||t:          j        gt          |          z  |          d         S )zoType check a dict expression.

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

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

*$$5yr   rS   c                   | j         }d| _         | j                            |d           |                     |          \  }}|sK| j        j                            t          t          j                             | j        j	        
                    dd          5  | j        j                            |          5  |j        j        dd         D ]}|                    | j                   |                     |                                d          }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                     d	          }| j        j                                         || _         t%          |||          S | j        j                            |j                   | j        j                            |          5  | j                            ||
           ddd           n# 1 swxY w Y   | j                            |                                          sb| j        j	        
                    dd          5  |                     |                                d           ddd           n# 1 swxY w Y   | j                            |                                          }| j        j                                         || _         t3          ||          S )zType check lambda expression.TF)body_is_trivialr   can_skipfall_throughNr8  rq  rO  )type_override)r$  r  check_default_argsinfer_lambda_type_using_contextr  r  r   r   r:  r  frame_contextr]  push_functionbodyru  r   rR  popr   rD  tscopefunction_scopecheck_func_itemr  r  replace_callable_return_type)r'  r-  old_in_lambdard  r  stmtrD  r  s           r   visit_lambda_exprz#ExpressionChecker.visit_lambda_expra  s   +"##Au#==='+'K'KA'N'N$}  	IH!((1G)H)HIII --t!-LLI I,,Q//I I FK, * *DKK))))  ;;qvvxx4;HHI I I I I I I I I I I I I I I I I I I I I I I I I I I I I I ':;;HH!%%'''"/D Hh777 H!(()?@@@//22 I I((-(HHHI I I I I I I I I I I I I I I8$$QVVXX.. BX_22Dq2QQ B BKKDKAAAB B B B B B B B B B B B B B Bx++AFFHH55HH!%%'''"/D/xHHHs[    D;=AD$D;$D(	(D;+D(	,D;;D?D?G==HH*JJJ/tuple[CallableType | None, CallableType | None]c                >  	 t          | j        d                   }t          |t                    rFd t	          |                                          D             }t          |          dk    r|d         }|rt          |t                    sdS | j        j	        j
        sg 	|j        D ]<}d t          |          D             }	                    	fd|D                        =|                    t          |j        t#                                t%          |j                  	z             }nJt          |t#                                }t          |t(                    rt          |t                    sJ |}|                    |                     d	          
          }|j        |j        dS d |j        D             }|j        s|                                X|                    dt7          t8          j                  gt          |          z  ||j                                                  }t@          |v s	tB          |v r|dfS |j"        |k    r'| j        #                    tH          j%        |           dS |                    |j                  |fS )zTry to infer lambda expression type using context.

        Return None if could not infer type.
        The second item in the return type is the type_override parameter for check_func_item.
        r8  c                <    g | ]}t          |t                    |S r   r  r  s     r   r  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s9       ZPQS_E`E`  r   r   r   NNc                D    g | ]}|j                                         |S r   )r  is_meta_var)r   re  s     r   r  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s+    XXXBBEDUDUDWDWXRXXXr   c                    g | ]}|v|	S r   r   )r   re  
extra_varss     r   r  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s#    "R"R"R"Rz=Q=Q2=Q=Q=Qr   )rD  r3  rO  r  Nc                    g | ]	}|j         
S r   )r}  )r   r   s     r   r  zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>  s    555#SX555r   F)is_ellipsis_argsr  r  r  )r  )&r   r  r   r   r   r  r  r   r  r  r!  r  r   rc  r  r"   rD  r   r  r3  r   rR  r  r  	argumentsr  r  r   r   r:  r  r  r6   r7   r  r  r   CANNOT_INFER_LAMBDA_TYPE)
r'  r-  rL  r  r   	meta_varscallable_ctxr3  r  r  s
            @r   r  z1ExpressionChecker.infer_lambda_type_using_context  s    d/344c9%% 	# +C,>,>,@,@AA  I 9~~""l 	*S,77 	: x2 	& J} T TXX*;C*@*@XXX	!!"R"R"R"R	"R"R"RSSSS,,*3<FFs}--
: -  LL
 +3
==Jj*55^*ZQ]:^:^^^^%L $114??K^;_;_1``".,2F2R :55555	( 	CNN,<,<,H'55!&"9#9::;c)nnL#+**,,	 6  L y  I$:$:%%!Y..HMM*CQGGG: ))AK)@@,NNr   rg   c                `   |                      |          }t          |t                    r|\  }}n|S t          |          }|>| j                            t          j        |           t          t          j
                  S t          |          }|>| j                            t          j        |           t          t          j
                  S |j        }d}||v r|                    |          }nl| j        j                                        }	|	Lt!          ||	j                  r6|j        r/||j        j        v r!|j        j        }|                    |          }|U|j        r||k    r
|j        sd}n>| j                            t          j        |           t          t          j
                  S t+          |          |dz   k    r>| j                            t          j        |           t          t          j
                  S ||dz   d         D ]}
|j        |
j        v s|
|d         k    rq|j        r3|j        j        r'|
|d         k    rt          t          j                  c S t7          |j        |ddd||
|| j        |                                 
  
        c S J d            )	z+Type check a super expression (non-lvalue).N)is_classmethodr8  r   FT)
r@  r  rM  r  r  r  override_inforY  r  r  r  )_super_arg_typesr   rv  type_info_from_typer  r  r   UNSUPPORTED_ARG_1_FOR_SUPERr   r   rA  UNSUPPORTED_ARG_2_FOR_SUPERr  rj  r]  current_functionr   is_classr  r  !SUPER_ARG_2_NOT_INSTANCE_OF_ARG_1r  TARGET_CLASS_HAS_NO_BASE_CLASSr@  rh  r  r:  r   r_  )r'  r-  r   	type_typeinstance_type	type_infoinstance_infor  rj  rr  rw  s              r   visit_super_exprz"ExpressionChecker.visit_super_expr  s    %%a((eU## 	',$I}}L (	22	HMM*FJJJ9/000+M:: HMM*FJJJ9/000 IIi((EEX^4466F !&7fo' ' '! 6 1i16:55&*CIIi00E=)5!Y..!- / .PRSTTTy3444s88uqy  HMM*I1MMM9/000	$ 	 	Dv##ts2w6 ;af4 ;R #9#9:::::,%#! %"/"&'+'>'>'@'@      (7& 	$m###r   Type | tuple[Type, Type]c                
   | j                                         st          t          j                  S t          |j        j                  dk    r!|j        st          t          j	                  S | j         j
                                        r>| j                             t          j        |           t          t          j	                  S t          |j                  }t!          |          }| j         j
                                        }|J |j        r|j        d         j        j        p|}n| j                             t          j        |           t          t          j	                  S t,          |j        j        v r>| j                             t          j        |           t          t          j	                  S t3          |j        j                  t4          hk    r>| j                             t          j        |           t          t          j	                  S t          |j        j                  dk    r>| j                             t          j        |           t          t          j	                  S t          |j        j                  dk    rXt;          |                     |j        j        d                             }|                     |j        j        d                   }n>| j                             t          j        |           t          t          j	                  S tA          |t                    rD|j        r"t!          t          |j                            }nt          t          j!        |          S tA          |t                     r`|j"        }tA          |t                    rD|j        r"t!          t          |j                            }nt          t          j!        |          S tA          |t                     s]tA          |tF                    r|$                                s4| j%        &                    ||           t          t          j	                  S t;          |          }tA          |t                    r7|j        rt          |j                  }nt          t          j!        |          S tA          |t                     r`|j"        }tA          |t                    rD|j        r"t!          t          |j                            }nt          t          j!        |          S ||fS )a*  
        Computes the types of the type and instance expressions in super(T, instance), or the
        implicit ones for zero-argument super() expressions.  Returns a single type for the whole
        super expression when possible (for errors, anys), otherwise the pair of computed types.
        r   Nr   r  r  )'r  r>  r   r   rJ  r  callr  r  rA  r]  active_classr  r   %SUPER_OUTSIDE_OF_METHOD_NOT_SUPPORTEDr   r   r  r  variabler  (SUPER_ENCLOSING_POSITIONAL_ARGS_REQUIREDr6   r  SUPER_VARARGS_NOT_SUPPORTEDrg  r5   SUPER_POSITIONAL_ARGS_REQUIRED#SUPER_WITH_SINGLE_ARG_NOT_SUPPORTEDr   ru  TOO_MANY_ARGS_FOR_SUPERr   r  r  r   r  r  %first_argument_for_super_must_be_type)r'  r-  current_typer  rr  r	  	type_iteminstance_items           r   r   z"ExpressionChecker._super_arg_types)  sT    x++-- $	190111""6 5y3444,,.. 5.TVWXXXy3444 )00L$,\$:$:I X^4466F%%% 5&,&6q&9&B&G&W<.WYZ[[[y3444)))HMM*FJJJ9/000!""wi//HMM*I1MMM9/000""HMM*NPQRRR9/000""'AFKN(C(CDDI KKA77MMHMM*BAFFF9/000 i)) 	Uv Q$]16%:%:;;		y9iPPPP	8,, 	U!I)W-- U6 U (qv)>)> ? ?II"9#=)TTTT)X.. 	1y,//	14=4I4I4K4K	1 H::9aHHH9/000 (66mW-- 	Yv U -af 5 5y9mTTTTx00 	Y).M-11 Y6 Y$,]16-B-B$C$CMM"9#=-XXXX-''r   c                   	 | j                             d          }n*# t          $ r | j                             d          }Y nw xY wt          |          }g }|j        |j        |j        fD ]w}|rR|                     |          }| j                             |||t          j
                   |                    |           V|                    t                                 x| j                             d|          S )Nztyping_extensions.SupportsIndexrE  zbuiltins.slice)r  rR  rf  r   r  r  r  ru  r=  r   INVALID_SLICE_INDEXr  r   rm  )r'  r-  supports_indexexpected	type_argsrj  r   s          r   visit_slice_exprz"ExpressionChecker.visit_slice_expr{  s
   	A!X001RSSNN 	A 	A 	A!X00@@NNN	A%n55	mQ[!(; 	- 	-E -KK&&&&q(E;K;_```  ####  ,,,,x**+;YGGGs    $AArT   c                :    |                      |j        dd          S )Nra  z<list-comprehension> check_generator_or_comprehension	generatorrG  s     r   visit_list_comprehensionz*ExpressionChecker.visit_list_comprehension  s$    44K*@
 
 	
r   rb   c                :    |                      |j        dd          S )Nr   z<set-comprehension>r#  rG  s     r   visit_set_comprehensionz)ExpressionChecker.visit_set_comprehension  s$    44K)>
 
 	
r   rP   c                l   t          |j                  sXt          |j                  sDt          d |j        dd          D                       st          d |j        D                       rd}t                      g}nd}t                      t                      g}|                     ||d|          S )Nc              3  4   K   | ]}t          |          V  d S r   r   )r   sequences     r   r   z9ExpressionChecker.visit_generator_expr.<locals>.<genexpr>  s+      RRh'11RRRRRRr   r   c              3  >   K   | ]}|D ]}t          |          V  d S r   r   )r   condlistconds      r   r   z9ExpressionChecker.visit_generator_expr.<locals>.<genexpr>  s9      __(V^__d'--_______r   ztyping.AsyncGeneratortyping.Generatorz<generator>)additional_args)r  is_asyncr   r  	sequences	condlistsr   r$  )r'  r-  r  r0  s       r   visit_generator_exprz&ExpressionChecker.visit_generator_expr  s     
OO	7#AK00	7 RR!+abb/RRRRR	7 __ak_____		7 *C+3::,OO$C'zz8::6O44sM? 5 
 
 	
r   genr  id_for_messagesr0  list[Type] | Nonec                V   |pg }| j         j                            dd          5  |                     |           t	          ddt          dd          g |                                 t          t          j	                            }|g}t          |t          j        gd	g| j                             |||z             | j                             d
          ||g          }|                     ||j        gt          j        g|          d         cd	d	d	           S # 1 swxY w Y   d	S )z:Type check a generator expression or a list comprehension.Tr   r  r  r8  z<genexp>r  r  NrO  r  )r  r  r  check_for_compr   r   rW  r   r   r  r   r   r5   rm  rR  r  r  )r'  r5  r  r6  r0  re  tv_listr  s           r   r$  z2ExpressionChecker.check_generator_or_comprehension  s    */RX_**Dq*II 	Z 	Z$$$ R:666 ,,..	 ?@@  B $&$G&++Iw7PQQ##$788$$  K ??;%-RUVVWXY/	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Zs   C+DD"%D"rJ   c                    | j         j                            dd          5  |                     |           t	          ddt          dd          g |                                 t          t          j	                            }t	          d	d	t          d
d          g |                                 t          t          j	                            }t          ||gt          j        t          j        gddg| j                             d||g          | j                             d          d||g          }|                     ||j        |j        gt          j        t          j        g|          d         cddd           S # 1 swxY w Y   dS )z&Type check a dictionary comprehension.Tr   r  r  r8  r  r  r  r  r  Nrd  rO  z<dictionary-comprehension>r  )r  r  r  r9  r   r   rW  r   r   r  r   r   r5   rm  rR  r  r  r  )r'  r-  ktdefvtdefr  s        r   visit_dictionary_comprehensionz0ExpressionChecker.visit_dictionary_comprehension  s   X_**Dq*II  	  	"""  R8444 ,,..	 ?@@  E  R8444 ,,..	 ?@@  E '.t++OeU^LL##$7881 %.  K ??aeQW-u}/Mq = 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	s   EFF
F'GeneratorExpr | DictionaryComprehensionc                &   t          |j        |j        |j        |j                  D ]h\  }}}}|r| j                            |          \  }}nx| j                            |          \  }}t          t          |          t                    r9t          |t                    r$|j        dk    rt          t          j                  }| j                            ||d|           |D ]}|                     |           | j                            |          \  }	}
|	r| j                            |	           t(          j        | j        j        j        v r;|	| j                            d|           |
| j                            d|           jdS )zCheck the for_comp part of comprehensions. That is the part from 'for':
        ... for x in y if z

        Note: This adds the type information derived from the condlists to the current binder.
        r,  TNF)r  indicesr2  r3  r1  r   analyze_async_iterable_item_typeanalyze_iterable_item_typer   r   r   rY   r@  r   r   r:  analyze_index_variablesru  r  push_type_mapr  r  r  r  r  $redundant_condition_in_comprehension)r'  r-  rj  r+  
conditionsr1  r,  sequence_type	conditiontrue_map	false_maps              r   r9  z ExpressionChecker.check_for_comp  s    69Iq{AK6
 6
 	W 	W1E8Z  
D#'8#L#LX#V#V ==#'8#F#Fx#P#P =}==OOD"5(33D 
c)) %,I,B$C$CMH,,UM4KKK' W W	I&&& '+h&D&DY&O&O#) 5H**8444'48+;+OOO'EEeYWWWW"*EEdIVVVW!	W 	Wr   rF   c                   |                      |j                   | j        d         }| j                            |j                  \  }}t
          j        | j        j        j        v rE|!| j	        
                    d|j                   n"| | j	        
                    d|j                   |                     ||j        ||          }t          t          |                    p|}|                     ||j        ||          }t           j                            || j        j                  sQ|}	t          t          |	                    p|	}
|t'          |
|          s|                     ||j        |
|          }n'||k    r|}	n|                     ||j        ||          }	t)          |          rt)          |	          s|}	t+          ||	g          }t-          |          rxt/          t          | j        d                   t0                    sKt3          j        ||	          }t          |          }t/          |t6                    r|j        j        dk    r|}|S )Nr8  FT)rY  ro  re  )ru  r.  r  r  r  r  r  r  r  r  redundant_condition_in_ifr  if_exprr   r   	else_exprr  r  rl  r   r   r   r1  r   r   r   r  r   r  r   )r'  r-  ro  rL  if_mapelse_mapif_typeif_type_fallbackfull_context_else_type	else_typeelse_type_fallbackr  alternativep_alts                 r   visit_conditional_exprz(ExpressionChecker.visit_conditional_expr  s   AF#  899!&AA48#3#GGG~225!&AAAA!224@@@**AIs>O + 
 
 /w/G/GHHSG "&!9!9ak3BS ": "
 "
 |227DH<LMM $	.I "5_Y5O5O!P!P!]T] {-0BC"H"H{ 22I.&7	 3   $$ /II 00("3	 1  I   677 	/@TU^@_@_ 	/.I)7I*>??$S)) 	"*D-b122I3
 3
 	" /'9==K#K00EeX.. "%*2EIZ2Z2Z!
r   r  dict[Expression, Type] | Nonesuppress_unreachable_errorsc                   | j         j                            dd          5  |e| j                            |          5  |                     |||           d d d            n# 1 swxY w Y   t                      cd d d            S | j                             |           |                     |||          cd d d            S # 1 swxY w Y   d S )NTr   r  )rU  rN  )r  r  r  r  rU  ru  r   rE  )r'  r  r   rY  ro  r[  s         r   r  z%ExpressionChecker.analyze_cond_branche  s    X_**Dq*II 		` 		`{ X++:U+VV a aKK7N_K```a a a a a a a a a a a a a a a&((		` 		` 		` 		` 		` 		` 		` 		` H""3''';;t'M^;__		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		` 		`s;   C A%C%A)	)C,A)	-C
1CCCtyc                    g }|&t          |          r|S |                    |           | j        r-| j        d          |                    | j        d                    |rt          |          S d S r=  )r  r  r  r   )r'  r]  	ctx_itemss      r   r  z#ExpressionChecker._combined_contextx  s    	>B  	R    	4!22!6!BT.r2333 	4(333tr   r  r   c                L   || 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          }	n`|r.t          |t                    r|                     |d          }	n0|r.t          |t                    r|                     |d          }	n t          |t          t"          t$          t&          t(          f          r| j        s| j        j        s| j        j        j        s||f| j        v rv| j        ||f         \  }
}	}}|
| j        j        j        k    r5| j                            |           | j                            |           nE|                      ||          }	n-|                      ||          }	n|!                    |           }	nR# tD          $ rE}tG          || 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        +                                r6tY          |	          r'| j        j        s| j        -                    |	|           | j        +                                r| j        j        rt]          t^          j0                  }n|	}|r5| j1        |j&        xx         t          j                    |z
  z  cc<   d| _        |S )zType check a node in the given type context.  If allow_none_return
        is True and this expression is a call, allow it to return None.  This
        applies only to this expression and not any subexpressions.
        FTrq  r  N)2r  r  r  timeperf_counter_nsr  r  r   r   rB   rv  ru   visit_yield_from_exprrF   rY  r@   visit_await_exprrU   rj   rI   r[   r$  r  r|  r  disable_expression_cacher#  r  versionr  r  r  accept_maybe_cacheru  	Exceptionr%   r  filerE  r  r  disallow_any_expris_stubr>  r  disallowed_any_typer   r   rJ  r  )r'  r   r  ro  r  r   record_timet0old_is_calleer  binder_versionmessagestype_mapr  r3  s                  r   ru  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 4(Hi6!RSS(,(040N( (A(
 ,'4?::>BotUaNb>c;NC8%)@@@,,X666++H5555"55d5VV11$\1RRCCkk$'' 	 	 	!TX_)49dhotxGW       	 'D#&&& H.	4$	4 H$	4 ,,..		4
 S!!	4 H2	4 H((d333x++-- 	1O 	"9#899FFF 	'*495559M9O9ORT9TT555!&Ds   ,G H- -
I<7;I77I<c                   | j         j        j        }| j                            dd          5 }| j         j        5 }|                    |           }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                                }|| j         j        j        k    r| j         j        s||||f| j	        ||f<   | j         
                    |           | j                            |           |S )NT)rU  rw  )r  r  rf  r  rU  rN  ru  r  r|  r#  r  r  )r'  r   r  rp  r  rr  r  rq  s           r   rg  z$ExpressionChecker.accept_maybe_cache  se   0X##$T#RR 	(VY( (Hkk$''( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( &&((TX_444TX=[45CS(T\4]DOT<01X&&&H%%%
s4   A4AA4A!	!A4$A!	%A44A8;A8r@  c                6    | j                             |          S )z}Return an instance type with type given by the name and no type
        arguments. Alias for TypeChecker.named_type.
        )r  rR  )r'  r@  s     r   rR  zExpressionChecker.named_type  s     x""4(((r   c                    | j         j        j        dk    r|                     d          S |                     d          S )zFReturns a `typing.TypeAliasType` or `typing_extensions.TypeAliasType`.)r     ztyping.TypeAliasTypeztyping_extensions.TypeAliasType)r  r  r  rR  r+  s    r   rd  z&ExpressionChecker.type_alias_type_type  s;    8*g55??#9:::@AAAr   c           	         t          |          }t          |t          t          t          t
          f          p@t          || j                            dt          t          j
                  g                    S )z$Is a type valid as a *args argument?rX  )r   r   r   r   r   r   r   r  rm  r   r:  r  s     r   r  z"ExpressionChecker.is_valid_var_arg  sd    c""#	7M:NOO 
S],,->I_A`A`@abbT
 T
 	
r   c           
     \   t          || j                            d|                     d          t	          t
          j                  g                    pWt          || j                            dt                      t                      g                    pt          |t                    S )z'Is a type valid as a **kwargs argument?r  r9  )
r   r  rm  rR  r   r   r:  r   r   r   r  s     r   r  z*ExpressionChecker.is_valid_keyword_var_arg  s     ++6__^44gi>T6U6UV   . ++69J9JOL]L]8^  . #}--	
r   c                <    | j                             ||           dS )zCalled when we can't infer the type of a variable because it's not ready yet.

        Either defer type checking of the enclosing function to the next
        pass or report an error.
        N)r  r?  )r'  r@  rY  s      r   not_ready_callbackz$ExpressionChecker.not_ready_callback  s"     	--dG<<<<<r   rt   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 )Nr8  Factual typeexpected type)r  r  get_generator_yield_typer   r   r   r   r   r>  r  r   YIELD_VALUE_EXPECTEDru  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 )Nr8  typing.Awaitabler  )r  r  rm  r   ru  r   r   r   r   r  check_awaitable_exprr   INCOMPATIBLE_TYPES_IN_AWAITr   r  r  )r'  r-  ro  expected_typer  rn  s         r   rd  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`.
        r  r|  r}  	__await__r   F)r  r=  rR  r   r   r:  r  get_generator_return_typer   r   r   r  r  r  )r'  r   rL  r  r  r%  rD  s          r   r  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   ru   c                   | j         j        d         }t          |                     |j                            }t          |t                    rt          t          j        |          }n;| j         	                    |          rt          |          r/t          |          s | j         j                            ||           t          t          j                  }| j                             d|||g          }|                    |           |                     d|g g |          \  }}nyt          |          rt          |          s:| j         j                            ||           t          t          j                  }n!|                     ||t(          j                  }| j                             |d          }	| j                             |d          }
| j                             |
|	|t(          j        dd           t          |          }| j                             |d	          }|sBt          t          |          t2                    r | j         j                            d |           |S )
Nr8  r  r/  __iter__r;  Fr|  r}  )is_coroutine)r  r  r   ru  r   r   r   r   r  re  is_async_defhas_coroutine_decoratorr  yield_from_invalid_operand_typer:  rm  r  r  rA  r  r    INCOMPATIBLE_TYPES_IN_YIELD_FROMr~  r=  r  r   r  )r'  r-  ro  r  subexpr_type	iter_typer  generic_generator_typer,  r  r  	expr_types               r   rc  z'ExpressionChecker.visit_yield_from_exprQ  s^    h+B/
 't{{16':':;; lG,, 	%i&@\ZZZIIX&&|44 	L)) N2I+2V2V N<<\1MMMy566H%)X%@%@"Xx$B& &" #++A...99L"b:P :  LIqq !.. 3J;3W3W <<\1MMM#I$899		 55 !%5%V 	 "X>>{ERR8<<YNN=	
 	
 	
 $I..	H66yu6UU	  	8Z	0J0JH%U%U 	8HL..tQ777r   ri   c                    |j         S r   r  rG  s     r   visit_temp_nodez!ExpressionChecker.visit_temp_node  	    vr   ro   c                   t          |j                  t          t                    rj        t
          j        k    srt          |j                  s| j	        
                    d|           |j        r;t          fd|j        D                       s| j	        
                    d|           t          t
          j                  S )Nz3TypeVar default must be a subtype of the bound typec              3  8   K   | ]}t          |          V  d S r   r   )r   r  	p_defaults     r   r   z8ExpressionChecker.visit_type_var_expr.<locals>.<genexpr>  s-      #Y#YuLE$B$B#Y#Y#Y#Y#Y#Yr   z3TypeVar default must be one of the constraint types)r   r  r   r   type_of_anyr   r  r   r  r  r  r	  r  r:  )r'  r-  r  s     @r   visit_type_var_exprz%ExpressionChecker.visit_type_var_expr  s    #AI..	y'**	X%)HHHi77 XSUVWWWx X#Y#Y#Y#YPQPX#Y#Y#Y Y Y XSUVWWWy-...r   r]   c                4    t          t          j                  S r   r   r   r:  rG  s     r   visit_paramspec_exprz&ExpressionChecker.visit_paramspec_expr      y-...r   rq   c                4    t          t          j                  S r   r  rG  s     r   visit_type_var_tuple_exprz+ExpressionChecker.visit_type_var_tuple_expr  r  r   rZ   c                4    t          t          j                  S r   r  rG  s     r   visit_newtype_exprz$ExpressionChecker.visit_newtype_expr  r  r   rX   c                "   |j         j        }|ri| j        j        j        r+t          |          r| j                            d||           t          || j        j        | j        j	        | j        |           t          t          j                  S )NzNamedTuple typer;  )r  
tuple_typer  r  rC  r   r  rD  r   rE  r   r   r:  )r'  r-  r  s      r   visit_namedtuple_exprz'ExpressionChecker.visit_namedtuple_expr  s    V&
 	x7 W<X= = W 445F
TUVVV"DH,dh.G[\    y-...r   rL   c                Z   t          |j        |j                  D ]x\  }}|q|                     |          }t	          t          |          t                    s:|j        j        |         j	        }t	          |t                    r||_        d|_        yt          t          j                  S NT)r  r   r	  ru  r   r   r   r  rh  r   rs   r  r  r   r:  )r'  r-  r@  r  r  r=  s         r   visit_enum_call_exprz&ExpressionChecker.visit_enum_call_expr  s    qw11 	/ 	/KD% kk%((!/#"6"6@@ /&,t,1C!#s++ /
 $'*.y-...r   rm   c                4    t          t          j                  S r   r  rG  s     r   visit_typeddict_exprz&ExpressionChecker.visit_typeddict_expr  r  r   r_   c                    |j         S r   r  rG  s     r   visit__promote_exprz%ExpressionChecker.visit__promote_expr  r  r   re   c                6    |                      |j                  S r   )ru  r   rG  s     r   visit_star_exprz!ExpressionChecker.visit_star_expr  s    {{16"""r   c                ,    |                      d          S )zReturn instance type 'object'.re  rO  r+  s    r   rW  zExpressionChecker.object_type  s    0111r   c                ,    |                      d          S )zReturn instance type 'bool'.r^  rO  r+  s    r   r  zExpressionChecker.bool_type  s    ///r   
known_typec                    d S r   r   )r'  r   r  s      r   r1  z)ExpressionChecker.narrow_type_from_binder  s    SVSVr   r  c                    d S r   r   )r'  r   r  r  s       r   r1  z)ExpressionChecker.narrow_type_from_binder  s	     cr   c                l   t          |          t          k    r| j        j                            |          }|rzt          t          |          t                    r| j        j        sL|rt          ||d          sdS t          ||          }t          t          |          t                    r|S |S |S )zNarrow down a known type of expression using information in conditional type binder.

        If 'skip_non_overlapping' is True, return None if the type and restriction are
        non-overlapping.
        T)prohibit_none_typevar_overlapN)r-   r:   r  r  r  r   r   r   r|  r/   r0   r   )r'  r   r  r  restrictionr4  s         r   r1  z)ExpressionChecker.narrow_type_from_binder  s     4==L(((/--d33K   ?:66@@ EIXEc  (  0D41 1 1    4/
KHHoh77II ' '&r   c                     t          |t                    rHt          |t                    r3t           fdt          |j        |j                  D                       S                      ||          S )Nc              3  ~   K   | ]7\  }}                     t          |          t          |                    V  8d S r   )has_abstract_typer   )r   callerr  r'  s      r   r   z;ExpressionChecker.has_abstract_type_part.<locals>.<genexpr>  s\        "FF &&v'>'>PV@W@WXX     r   )r   r   r  r  r   r  r'  r  r  s   `  r   r  z(ExpressionChecker.has_abstract_type_part  s    k9-- 	*[)2T2T 	    &)+*;[=N&O&O      %%k;???r   c                t   t          |t                    ot          |t                    o|                                oz|                                j        p|                                j        oHt          |j        t                    o.|j        j	        j        p|j        j	        j        o| j
        j         S r   )r   r   r   r  r  r  r  r  r   r  r  allow_abstract_callr  s      r   r  z#ExpressionChecker.has_abstract_type  s    {L11 1;111''))1 ((**6_+:Q:Q:S:S:_1 ;+X66	1
 !&2Wk6F6K6W1 H00	
r   )
r  r  r  r2   r  r{   r  r  r   r   r   r   )r-  rY   r   r   F)r-  r`   r6  r   r   r   )r   rh   rL  rG   rM  r   rJ  r   rK  r   r   r   )r=  rs   rY  rG   r   r   )r   rW   r   r   )r-  rB   ro  r   r   r   )rw  rM   r   r   )r-  rB   r   r   )rW  r   r  r  r   r  r   rM   r   r   )r  r  r   r   )r  r   r  r  r  r  r  r  rY  rG   r  r  r   r   )r  r  r  r   r   r  )
r  rM   r  r   r3  r  r  r   r   r   r  r   r   r   )r  r   r  r*  rY  rG   r   r   )
r  r   r  r*  rY  rG   r  r  r   r   )r  rn   r   r   r   )r  r   r3  r4  r   r   )r  r   r  r  rY  rG   r  r  r  r   r   r   )r   rV   r   rZ  )rs  r`   r   rt  )r-  rB   rw  r  r=  rs   r   rx  )r  r   r  r  r  r  r  r  r  r  r  r  r   r  rW  r  rY  rG   r   r   )r  r   r  r  r  r  r  r  r  r  r   r   )r  r   r  r  r  r  rY  rG   r  r  r  r  r   r   )r  r   r  r  r  r  rY  rG   r  r  rW  r   r  r  r   r   r  )r  r  r  r   r  r  r  r  rY  rG   r  r  rW  r  r   r   )r  r   r  r  r   r  )r  r   r  r   rL  rG   r   r  )r  r   r-  rB   r  r  rW  r  r  r  r   r   )r-  rB   rW  r   r  r  r   r   )NNNNN)r  r   r  r  r  r  rY  rG   r  r  r  r  r  r  rW  r  r  r  r   r  )r  r   r  r  r  r  rY  rG   r  r  r  r  r  r  rW  r  r   r  )r  rn   r  r  r   r   )r  r   rY  rG   r   r   )r  r  r   r  )r  r   r   r   )
r  r   r  r  r  r  r  r  r   r  )r)  r   r*  rG   r   r   )r  r   r  r  r  r  r  r  r  r  r	  r   rY  rG   r   r   )r  r   r  r  r  r  r  r  r  r  rR  rS  r	  r   rY  rG   r   rT  )r   r*   )r  r   r  r  r  r  r  r  rY  rZ  r   r[  )r  r   r  rS  rY  rG   r   r   )r  r   rf  r  rg  r  rh  r  r  r  rY  ri  rW  r  r  r  r   r   )r  r   rf  r  rg  r  rh  r  rz  r  rY  rG   r   r  )rW  r   r  r  rY  rG   r   r   )r  r  r  r  r  r  r  r   r  r  rY  rG   r  r  rW  r  r   r   )r  r   r  r   r  r=   r  r   rn  rZ  r  rZ  r  r   rW  r  rY  rG   r  rG   r   r   )r  r   r  r  r  r  r  r  r  r  rW  r  rY  rG   r   r  )
r  r  r  r  r  r  r   r   r   r  )r  r  r  r  r  r  r  r  r  r  r  r  rW  r  rY  rG   r   r  )r  r  r  r  r  r  r  r  r  r  rY  rG   r   r  )r  r  r  r  r   r   rC  )r  r  r  r  r  r  r  r  r  r  r  r  rW  r  r  r   rY  rG   r  rZ  r   r   r  )r  r  r  r  r   r  )r   r  r   r  )r  r  r  r  r  r  r  r  r  r   rY  rG   r   r   )
r)  r   r   rS  rY  rG   r0  r   r   r   )r  r  r  r   r   r  )r  r   r  r  r  r  r  r  rY  rG   r   r  )r-  rV   rM  r   r   r   )r-  rV   rM  r   rG  r  r   r   )r  r  r9  r   rY  rG   r   r   )r   r   )r  r   r>  r  r   r   )r@  r   rA  r   r   r   )r-  rR   r   r   )r-  rf   r   r   )r-  rA   r   r   )r-  rN   r   r   )r-  rE   r   r   )r-  rK   r   r   )r-  r[   r   r   )r-  rD   r   r   )r   rM   r   r  )r@  r   rA  r   ry  r  r  r  rz  r   r~  r   r   r   )rr  r  r9  r   r  r  r  r  rY  rG   r  r  r  r  r   r  )rr  r  r9  r   r  r  r  r  rY  rG   r  r  r   r  )r  r  r9  r   rj  r   r  r  r  r  rY  rG   r   r  )r  r  rl  r   r  rM   r  r   r  rM   rY  rG   r   r  )rr  r  r9  r   r   rM   rY  rG   r^  r   r   r  )r-  r?   r   r   )r-  rr   r   r   )r-  rQ   r   r   )
rl  r   r-  rQ   r  r  r  r  r   r   )r@  r   r   rZ  )r@  r   rn  rZ  r   r  )rl  r   r  rd   r   r   )rj  rM   r   r(  )rl  r   rj  rM   r   r   )rl  r   r   r   )r1  r   rj  rM   r2  r   r   r3  )r;  rn   rj  rM   rY  rG   r   r   )r   rC   r   r   )r   r>   r   r   )r   ra   r   r   )r   ra   r   r   )ra  rl   r   r   )rh  rk   r   r   )rh  r   rL  rG   rQ  r   r   r   )r   r   r  r  rL  rG   r   r  )r  r   r  r  rL  rG   r   r   )r-  rU   r   r   )r-  rc   r   r   )r-  r  r  r  r   r  )r   r  r   r  )r-  r  r   r  r  r  r   r   )r   rj   rL  r   r   r   )r-  rj   r   r   )r-  rI   r   r  )r-  rI   r  r   r   r   )r-  rI   r   r   )rY  r  r  rI   r   r  )r-  rS   r   r   )r-  rS   r   r  )r-  rg   r   r   )r-  rg   r   r  )r-  rd   r   r   )r-  rT   r   r   )r-  rb   r   r   )r-  rP   r   r   )
r5  rP   r  r  r6  r  r0  r7  r   r   )r-  rJ   r   r   )r-  r?  r   r   )r-  rF   ro  r   r   r   )FT)r  rZ  r   rM   rY  r  ro  r   r[  r   r   r   )r]  r  r   r  )NFFF)r   rM   r  r  ro  r   r  r   r   r   r   r   )r   rM   r  r  r   r   )r@  r  r   r   )r   r   )r@  r  rY  rG   r   r   )r-  rt   r   r   )r-  r@   ro  r   r   r   )
r   r   rL  rG   r  r  r  r   r   r   )r-  ru   ro  r   r   r   )r-  ri   r   r   )r-  ro   r   r   )r-  r]   r   r   )r-  rq   r   r   )r-  rZ   r   r   )r-  rX   r   r   )r-  rL   r   r   )r-  rm   r   r   )r-  r_   r   r   )r-  re   r   r   )r   rM   r  r   r   r   )r   rM   r  r   r  r   r   r  )r  r   r  r   r   r   )r   r   r   r   __annotations__r(  r,  r5  r0  rB  r;  rX  rv  rz  rt  r  r  r  r  r  r  r  r  r   r  r-  r  rT  r1  r  r_  rb  re  r  rg  rh  r  r  r  r  r  r  r  r  r  r  rO  r  r  r   r$  r   r  r+   rF  rE  rD  rK  r  ro  rs  r  r  r  r  r  r  r  r  r  r   r  r  r  r2  r  r  r4  r3  r;  r_  ra  rC  rH  rK  rM  rP  rR  rT  rs  r  r  r  r  r  r  r  rh  r`  ra  r  r  r  r  r  r  r  r  r  r  r-  r  r  rH  rL  rW  rR  rg  rj  rV  r}  re  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r&  r(  r4  r$  r>  r9  rY  r  r  ru  rg  rR  rd  r  r  rz  r  rd  r  rc  r  r  r  r  r  r  r  r  r  r  rW  r  r   r1  r  r  r   r   r   r  r  +  s          "!!!#### 0///****NNN9999*4 *4 *4 *4X       	 	 	 	+ + + + +f !% %.- .- .- .- .- .-`3 3 3 3$   4	R 	R 	R 	R 	R
 
 
 
V V V V Vp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(Q Q Q Q TX
 
 
 
 
 ] ] ] ]~   0 #	*1 1I    
 #_$56"_$56$,.?#@!NO#DE	A AN    %P %P %P %PN	" 	" 	" 	") ) ) )VG G G GR% % % %@
 
 
 
$
 
 
 
> 26#'' ' ' ' 'R   &= = = =H "0 0 0 0 0d* * * *D 26+/$(#'%)xY xY xY xY xYts' s' s' s'j   0,- ,- ,- ,-\        #% #% #% #%JS
 S
 S
 S
jIR IR IR IRV;* ;* ;* ;*z- - - -- - - -^Q Q Q Q8 $($(N N N N N`;+ ;+ ;+ ;+z   , (,#'K K K K KZ+ + + +ZM M M M^9& 9& 9& 9&vR6 R6 R6 R6h   *$ $ $ $b d d d d dLL L L L . . . ^.P
 P
 P
 P
d3 3 3 3t "'
 
 
 
 
 	T 	T 	T 	TL L L L      KO( ( ( ( (T
 
 
 
&; ; ; ;!^ !^ !^ !^F
 
 
 
E E E EE E E EG G G G1 1 1 13 3 3 34 4 4 4k; k; k; k;ZS S S Sj   * +/48#$AN AN AN AN AN ANT &*!%%` %` %` %` %`\ &*K K K K K8
 
 
 
<n n n nl $m m m m m^IM IM IM IMV    	 	 	 	       8 8 8 8 ,0!%V V V V Vp! ! ! !.
 .
 .
 .
`, , , ,@$ $ $ $L   , , , ,( JO#B #B #B #B #BJ' ' ' '   .   4   >D D D D.)/ )/ )/ )/V` ` ` ` KPC: C: C: C: C: C:J6W 6W 6W 6WpJ/ J/ J/ J/XA A A A? ? ? ?. . . .`	 	 	 	!6 !6 !6 !6FY Y Y Yg g g gRE E E EN	1 	1 	1 	1QU QU QU QUf   4&I &I &I &IPKO KO KO KOZQ$ Q$ Q$ Q$fP( P( P( P(dH H H H 
 
 
 


 
 
 


 
 
 
2 .2 Z  Z  Z  Z  ZD" " " "H#W #W #W #WJO O O O Ol #(,0` ` ` ` `&   * %)"'!&Q Q Q Q Qf
 
 
 
 
) ) ) )B B B B
 
 
 

 
 
 
&= = = =G G G G*     UZ    .: : : : :x   
/ 
/ 
/ 
// / / // / / // / / /
/ 
/ 
/ 
// / / // / / /   # # # #2 2 2 20 0 0 0 VVV XV   X
 PU    <@ @ @ @	
 	
 	
 	
 	
 	
r   r  Fignore_in_type_objc                F    |                      t          |                    S )zWhether t contains an Any type)ru  
HasAnyType)r   r  s     r   r  r    s    88J122333r   c                  L     e Zd Zd fdZddZd fd
ZddZddZddZ xZ	S )r  r  r   r   r   c                l    t                                          t          j                   || _        d S r   )superr(  r   ANY_STRATEGYr  )r'  r  	__class__s     r   r(  zHasAnyType.__init__  s,    +,,,"4r   r   r   c                ,    |j         t          j        k    S r   )r  r   r:  r'  r   s     r   	visit_anyzHasAnyType.visit_any  s    }	 666r   r   c                    | j         r|                                rdS t                                          |          S )NF)r  r  r  visit_callable_type)r'  r   r  s     r   r  zHasAnyType.visit_callable_type  s:    " 	q}} 	5ww**1---r   r   c                    |                                 r|j        gng }|                     |j        g||j        z             S r   )r  r  query_typesr  r	  r'  r   r  s      r   visit_type_varzHasAnyType.visit_type_var  sA    !"819++b 9 9AH DEEEr   r   c                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   )r  r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )
r   r   r   r(  r  r  r  r  r  __classcell__r  s   @r   r  r    s        5 5 5 5 5 57 7 7 7. . . . . .
F F F F; ; ; ;; ; ; ; ; ; ; ;r   r  c                j    t          |           } t          | t                    o| j        j        dk    S )z;Whether t came from a function decorated with `@coroutine`.typing.AwaitableGenerator)r   r   r   r  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  r  r   s    r   r  r  2  sx     	A1h'FO:::KK1AF1I&&a""Lqv:L'LLr   c                r    t          |           } t          | t                    ot          | j                  S r   )r   r   r   r   r   r   s    r   r  r  J  s,    Aa##5QW5r   mappingr[  rf  r  rg  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   r7   r   r   r   )r   r  rg  rf  s     r   r   z'is_duplicate_mapping.<locals>.<genexpr>`  sf       
 
  Ou. P|A??OOO
 
 
 
 
 
r   )r  r   r6   r7   r   )r  rf  rg  s    ``r   ru  ru  O  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  h  s    ??L?111r   c                  ,     e Zd ZdZd	 fdZd
dZ xZS )r]  zQuery whether an argument type should be inferred in the second pass.

    The result is True if the type has a type variable in a callable return
    type anywhere. For example, the result for Callable[[], T] is True if t is
    a type variable.
    r   r   c                ^    t                                          t          j                   d S r   r  r(  r   r  r'  r  s    r   r(  z ArgInferSecondPassQuery.__init__u  $    +,,,,,r   r   r   r   c                T    |                      |j                  pt          |          S r   )r  r  r   r  s     r   r  z+ArgInferSecondPassQuery.visit_callable_typex  s%    ,,@a0@0@@r   r  r  )r   r   r   r   r(  r  r  r  s   @r   r]  r]  m  sc         - - - - - -A A A A A A A Ar   r]  r  c                L    | d uo |                      t                                S r   )ru  HasErasedComponentsQueryr   s    r   r  r  }  s$    D=AQXX&>&@&@AAAr   c                  ,     e Zd ZdZd	 fdZd
dZ xZS )r  z<Visitor for querying whether a type has an erased component.r   r   c                ^    t                                          t          j                   d S r   r  r  s    r   r(  z!HasErasedComponentsQuery.__init__  r  r   r   r   r   c                    dS r  r   r  s     r   visit_erased_typez*HasErasedComponentsQuery.visit_erased_type      tr   r  )r   r   r   r   )r   r   r   r   r(  r  r  r  s   @r   r  r    sW        FF- - - - - -       r   r  c                L    | d uo |                      t                                S r   )ru  HasUninhabitedComponentsQueryr   s    r   r1  r1    s$    D=FQXX&C&E&EFFFr   c                  ,     e Zd ZdZd	 fdZd
dZ xZS )r  zEVisitor for querying whether a type has an UninhabitedType component.r   r   c                ^    t                                          t          j                   d S r   r  r  s    r   r(  z&HasUninhabitedComponentsQuery.__init__  r  r   r   r   r   c                    dS r  r   r  s     r   visit_uninhabited_typez4HasUninhabitedComponentsQuery.visit_uninhabited_type  r  r   r  )r   r   r   r   )r   r   r   r   r(  r  r  r  s   @r   r  r    sW        OO- - - - - -       r   r  r  r  c                    t                      t                    t           t                    rt                      t          t                    rt                    d
d}t          t                    r$t           t          t
          t          f          rdS  |           r |          rdS t           t                    r-t          fd 	                                D                       S t          t                    r-t           fd	                                D                       S t           t                    r,t          t                    rdS t           j                  S t          t                    rt           t                    r j         t           t
                    r j        d	         j         t           t                    rt!                      t           t                    rj         j        j        v rdS t'          t)          j                   t)          j                            S )a  Return if caller argument (actual) is roughly compatible with signature arg (formal).

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

    This is useful when we're doing error reporting: for example, if we're trying
    to select an overload alternative and there's no exact match, we can use
    this function to help us identify which alternative the user might have
    *meant* to match.
    r  r   r   r   c                    t          | t                    pMt          | t                    o|                                 p$t          | t                    o| j        j        dk    S )Nr8  )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  r  s     r   r   z-arg_approximate_similarity.<locals>.<genexpr>  s.      ``-dF;;``````r   c              3  8   K   | ]}t          |          V  d S r   r  )r   r  r  s     r   r   z-arg_approximate_similarity.<locals>.<genexpr>  s.      ``-fd;;``````r   r   r  )r   r   r   r   r   r   r   r   r  r  r   r(  r  r   r   r   r   r  r  r   r   r    )r  r  r  s   `` r   r(  r(    sP    V$$FV$$F &+&& 1(00&+&& 1(00
 
 
 
 &,'' f|ZBCC 	4 $4$4V$<$< t &)$$ a````H]H]H_H_``````&)$$ a````H]H]H_H_`````` &-(( Cfm,, 	4)&/6BBB &(## 	fl++ 	%_Ffj)) 	.\!_-Ffi(( 	,#F++Ffh'' 	FK6;?,J,J4 i*622I4H4P4PQQQr   r   r  r  r  r  r  r  c                   t          |          rdS fd| D             }t                    D ]\  }t          |d          rfdt          |          D             }g }g }	|D ]L\  }
}| |
         }|                    |j                   |D ]"}|	                    |j        |                    #Mt          |	          st          |          s dS dS )a  May an argument containing 'Any' cause ambiguous result type on call to overloaded function?

    Note that this sometimes returns True even if there is no ambiguity, since a correct
    implementation would be complex (and the call would be imprecisely typed due to Any
    types anyway).

    Args:
        items: Overload items matching the actual arguments
        arg_types: Actual argument types
        arg_kinds: Actual argument kinds
        arg_names: Actual argument names
    Fc           
     P    g | ]"}t          |j        |j        fd           #S )c                    |          S r   r   r  s    r   r  z:any_causes_overload_ambiguity.<locals>.<listcomp>.<lambda>  s    IVWL r   )r   r  r  )r   r  r  r  r  s     r   r  z1any_causes_overload_ambiguity.<locals>.<listcomp>  sN         	y$.$.BXBXBXBX	
 	
  r   T)r  c                :    g | ]\  }}|         ||         fS r   r   )r   item_idxlookuparg_idxs      r   r  z1any_causes_overload_ambiguity.<locals>.<listcomp>  s@     + + +$Hf'?+6'?++ + +r   )r  r  r  r  rD  r  )r   r  r  r  r  actual_to_formalr}  matching_formals_unfilteredmatching_returnsmatching_formalsr  formalsmatched_callabler  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   Nr  )r   r   r   s     r   r   z!all_same_types.<locals>.<genexpr>  s1      <<Q|AuQx((<<<<<<r   r   )r   )r   s   `r   r  r    s;     t<<<<%)<<<<<<r   r  Sequence[CallableType],tuple[list[CallableType], list[TypeVarType]]c                   g }i }g }| D ]}|                                 rt          |          }i }|j        D ]k}|j        }||vrNt	          |t
          t          f          r*t	          |t                    sJ |||<   |                    |           ||         ||j	        <   lt          ||          }|                    |           ||fS )a<  Takes all the typevars present in the callables and 'combines' the ones with the same name.

    For example, suppose we have two callables with signatures "f(x: T, y: S) -> T" and
    "f(x: List[Tuple[T, S]]) -> Tuple[T, S]". Both callables use typevars named "T" and
    "S", but we treat them as distinct, unrelated typevars. (E.g. they could both have
    distinct ids.)

    If we pass in both callables into this function, it returns a list containing two
    new callables that are identical in signature, but use the same underlying TypeVarType
    for T and S.

    This is useful if we want to take the output lists and "merge" them into one callable
    in some way -- for example, when unioning together overloads.

    Returns both the new list of callables and a list of all distinct TypeVarType objects used.
    )r  r)   r3  r   r   r   r   r   r  r  r&   )r  r   unique_typevarsr3  ry  renamere  r@  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   r  r   c                j    t          |           } t          | t                    r| j        | j        S | S )z>If possible, get a more precise literal type for a given type.)r   r   r   r`  r  s    r   r  r  E  s7    
#

C#x   $S%9%E##Jr   r   rM   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   rQ   rw  r`   r   r   rY   r   r   r   ry  r   )r   rw  
underlyings      r   r  r  M  s    $	"" Qy$((PT]>P-PP$!! 
Y
*i00 
ZJ-..6
 6
 	
 5r   c                    t          |           } ddh}t          | t                    rt          d | j        D                       S t          | t
                    r| j        j        |v rdS dS )z?Is this one of builtin byte types, or a union that contains it?r   r   c              3  4   K   | ]}t          |          V  d S r   )r  r  s     r   r   z&has_bytes_component.<locals>.<genexpr>_  s+      ==a&q))======r   TF)r   r   r   r  r   r   r  r   )r  
byte_typess     r   r  r  Z  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  e  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   r8  )splitr   rg  r	  ri  r  )r   
short_names     r   r  r  x  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   rk  rk    s%    y
1k22yafntHr   rY  c                    t          |           } t          | t                    rdS t          | t                    rt	          d | j        D                       S dS )NTc              3  4   K   | ]}t          |          V  d S r   )rG  )r   r  s     r   r   z'is_type_type_context.<locals>.<genexpr>  s+      HH$'--HHHHHHr   F)r   r   r   r   r  r   r;  s    r   rG  rG    s]    g&&G'8$$ t'9%% IHH'-HHHHHH5r   )r   r   r   r   )r   r`   r   r   r   r   r  )r   r   r  r   r   r   )r  r[  rf  r  rg  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   r   r   r  r  )r  r   r   r#  )r   r  r   r   )r   r  r   r(  )rY  r  r   r   (#  r   
__future__r   enumr  ra  collectionsr   collections.abcr   r   r   
contextlibr   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.checker_sharedr   mypy.checkmemberr   r   mypy.checkstrformatr   mypy.erasetyper    r!   r"   mypy.errorsr#   r$   r%   mypy.expandtyper&   r'   r(   r)   
mypy.inferr*   r+   r,   mypy.literalsr-   mypy.maptyper.   	mypy.meetr/   r0   mypy.message_registryr1   mypy.messagesr2   r3   
mypy.nodesr4   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   rs   rt   ru   mypy.optionsrv   mypy.pluginrw   rx   ry   rz   r{   mypy.semanal_enumr|   
mypy.stater}   mypy.subtypesr~   r   r   r   r   mypy.traverserr   mypy.typeanalr   r   r   r   r   r   r   mypy.typeopsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
mypy.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mypy.types_utilsr   r   r   r   mypy.typestater   mypy.typevarsr   	mypy.utilr   mypy.visitorr   rZ  r   r  r   r   r   rh  r   r   r  r  uniqueEnumr  r  r  r	  r  r
  r  r  r  BoolTypeQueryr  r  r  r  ru  r  r]  r  r  r1  r  r(  r  r  r  r  r  r  r  r  rk  rG  r   r   r   <module>rS     s'   M M M " " " " " "       # # # # # # 8 8 8 8 8 8 8 8 8 8 2 2 2 2 2 2 2 2 F F F F F F F F F F F F F F F F C C C C C C C C           V V V V V V V V V V V V V V V V V V W W W W W W W W W W : : : : : : @ @ @ @ @ @ @ @ 6 6 6 6 6 6 [ [ [ [ [ [ [ [ [ [ F F F F F F F F F F            a ` ` ` ` ` ` ` ` ` ! ! ! ! ! ! 2 2 2 2 2 2 @ @ @ @ @ @ @ @ . . . . . . 5 5 5 5 5 5 5 5D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D D DJ - , , , , ,              ) ( ( ( ( (                    0 / / / / /                                                      &* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *V            & % % % % % ' ' ' ' ' ' ( ( ( ( ( ( * * * * * * "	4$S,QXY[__
     
    
	& 	& 	&  	 	 	 	& & &         I      L L L L<O O O O Oy O O O         (/  / / / /&-  - - - -%+  + + + +__
 __
 __
 __
 __
)$/1K __
 __
 __
D4 4 4 4 4
; ; ; ; ;$ ; ; ;4V V V VM M M M06 6 6 6
   22 2 2 2
A A A A Ae1 A A A B B B B    u2   G G G G    E$7   <R <R <R <R~7 7 7 7t= = = =* * * *Z   
 
 
 
      &           r   