
    %^gn                   |   U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZmZmZ ddlmZmZmZ ddlZddlmZ ddlmZmZm Z m!Z!m"Z"m#Z#m$Z$ dd	l%m&Z&m'Z'm(Z( dd
l)m*Z*m+Z+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZDmEZE ddlFmGZG ddlHmIZImJZJ ddlKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZ dd lmZ dd!lmZ dd"lmZ dd#lmZ eeeeUeeeeee   e_e_g
df   Zd$ed%<   d&Zd'ed(<   g d)Zd'ed*<   h d+Zd'ed,<    G d- d.e      ZdUd/ZdVd0Z G d1 d2e      Zej                   G d3 d4ej                               Zej                  Zd'ed5<   ej                   Zd'ed6<   ej                  Zd'ed7<    G d8 d9ee         ZdWdXd:Z G d; d<e$j                        ZdUd=ZdUd>Z	dUd?Z
	 	 	 	 	 	 	 	 dYd@ZdZdAZ G dB dCe$j                        Zd[dDZ G dE dFe$j                        Zd[dGZ G dH dIe$j                        Zd\dJZ	 	 	 	 	 	 	 	 	 	 	 	 d]dKZd^dLZ	 	 	 	 d_dMZd`dNZdadOZdbdPZdcdQZdddRZdedSZdfdTZy)gzGExpression type checker. This file is conceptually part of TypeChecker.    )annotationsN)defaultdict)contextmanager)	CallableClassVarFinalIterableIteratorListOptionalSequencecast)	TypeAliasassert_neveroverload)	applytype	erasetypejoinmessage_registrynodes	operatorstypes)ArgTypeExpandermap_actuals_to_formalsmap_formals_to_actuals)analyze_member_accessfreeze_all_type_varstype_object_type)StringFormatterChecker)
erase_type!remove_instance_last_known_valuesreplace_meta_vars)ErrorWatcherreport_internal_error)expand_typeexpand_type_by_instancefreshen_all_functions_type_varsfreshen_function_type_vars)ArgumentInferContextinfer_function_type_argumentsinfer_type_arguments)literal)map_instance_to_supertype)is_overlapping_typesnarrow_declared_type)ErrorMessage)MessageBuilderformat_type)B	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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)	bind_selfcallable_typecustom_special_methoderase_to_union_or_bound
false_onlyfixup_partial_typefunction_typeget_all_type_varsget_type_varsis_literal_type_likemake_simplified_unionsimple_literal_type	true_onlytry_expanding_sum_type_to_uniontry_getting_str_literalstuple_fallback)(LITERAL_TYPE_NAMESTUPLE_LIKE_INSTANCE_NAMESAnyTypeCallableTypeDeletedType
ErasedType
ExtraAttrsFunctionLikeInstanceLiteralTypeLiteralValueNoneType
Overloaded
ParametersParamSpecFlavorParamSpecTypePartialType
ProperType	TupleTypeTypeTypeAliasTypeTypedDictType	TypeOfAnyTypeType	TypeVarId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y)TooManyUnionszyIndicates that we need to stop splitting unions in an attempt
    to match an overload in order to save performance.
    N__name__
__module____qualname____doc__     .lib/python3.12/site-packages/mypy/checkexpr.pyr   r      s    r   r   c                    t        | t              r| j                  ryt        |       } t        | t              xs. t        | t
              xr t        d | j                  D              S )NFc              3  2   K   | ]  }t        |        y wN)allow_fast_container_literal.0its     r   	<genexpr>z/allow_fast_container_literal.<locals>.<genexpr>   s     (\T[b)Eb)IT[   )
isinstancer   is_recursiver   r   r   allitemsts    r   r   r      sT    !]#Aa" 1i \S(\TUT[T[(\%\r   c                |   t               }t        | j                  t              s| j                  rt        | j                  t              r'| j                  r|j                  | j                         t        | t              rt        | j                  t              xr | j                  j                  }t        | j                  t              r1|j                  t        | j                  j                               	 |S d| j                  v r0|s.|j                  | j                  j                  dd      d          	 |S t        | t              r*t        | j                  t               r| j                  } n	 |S t#        dt%        |              t        | j                  t              r|| j                  r|S )zRecursively extracts all module references from a reference expression.

    Note that currently, the only two subclasses of RefExpr are NameExpr and
    MemberExpr..   r   zUnknown RefExpr subclass: )setr   noderV   fullnameaddrX   rq   is_suppressed_importrm   updater   module_namersplitrU   exprr_   AssertionErrortype)r   outputr   s      r   extract_refexpr_namesr      sE   
 uF
TYY
)T]]dii*t}} JJt}}%dH%#-dii#=#`$))B`B` $))X.01F1FGH  M %.B

4==//Q7:; M j)$))W-yy M !#=d4j\!JKK- TYY
)T]]. Mr   c                      e Zd ZdZy)FinishedzDRaised if we can terminate overload argument check early (no match).Nr   r   r   r   r   r     s    Nr   r   c                      e Zd ZdZdZdZdZy)
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GFEr   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<   	 	 	 	 	 	 	 	 	 	 ddZddZddZdddZddZ	ddZ
dddZddZdddZddZddZddZddZddZddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 dd Zdd!Z	 	 	 	 	 	 	 	 dd"Z	 	 	 	 	 	 	 	 	 	 dd#Zdd$Zdd%Z	 	 	 	 	 	 	 	 	 	 	 	 dd&Zdd'Zd(gd)d*gd+Zd,ed-<   d.d/gid0d1gid0d1gid0d2d/gid3Zd4ed5<   dd6Z dd7Z!	 	 	 	 	 	 	 	 dd8Z"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd9Z#	 	 	 	 	 	 	 	 	 	 	 	 dd:Z$	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd;Z%	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd<Z&	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd>Z'	 	 	 	 	 	 dd?Z(	 	 	 	 	 	 	 	 dd@Z)	 d	 	 	 	 	 	 	 	 	 	 	 ddAZ*ddBZ+	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddCZ,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddDZ-ddEZ.ddFZ/ddGZ0ddHZ1	 	 	 	 	 	 	 	 	 	 ddIZ2	 	 	 	 	 	 ddJZ3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddKZ4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddLZ5ddMZ6	 	 	 	 	 	 	 	 	 	 	 	 ddNZ7	 	 	 	 	 	 	 	 ddOZ8	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddPZ9	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddQZ:	 	 	 	 	 	 	 	 ddRZ;	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddSZ<	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddTZ=	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddUZ>	 	 	 	 	 	 	 	 	 	 ddVZ?	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddWZ@	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddXZA	 	 	 	 	 	 d dYZB	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZZCdd[ZDeE	 	 	 	 	 	 dd\       ZFdd]ZG	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd^ZH	 d	 	 	 	 	 	 	 	 	 dd_ZIdd`ZJ	 	 	 	 	 	 	 	 	 	 	 	 d	daZKdȐd
dbZLd
dcZM	 	 	 	 	 	 	 	 dddZNddeZOddfZPddgZQddhZRddiZSddjZTddkZUddlZVddmZWddnZXddoZYddpZZd=d=dqdr	 	 	 	 	 	 	 	 	 	 	 ddsZ[	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddtZ\	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dduZ]	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddvZ^	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddwZ_	 d	 	 	 	 	 	 	 	 	 	 	 ddxZ`ddyZaddzZbdd{Zcd d|Zdd!d}Zed!d~Zf	 d	 	 	 	 	 	 	 d"dZgd#dZhd$dZid%dZjd&dZkd'dZld(dZm	 d	 	 	 	 	 	 	 d)dZn	 	 	 	 	 	 	 	 d*dZod+dZpd,dZqd-dZrd.dZsd/dZtd0dZudd	 	 	 	 	 	 	 d1dZv	 	 	 	 	 	 	 	 d2dZw	 	 	 	 	 	 	 	 d3dZxd4dZyd5dZz	 	 	 	 	 	 d6dZ{d7dZ|d8dZ}d9dZ~d:dZ	 	 	 	 	 	 d;dZd<dZ	 	 	 	 	 	 d=dZd>dZ	 	 	 	 d?dZd@dZdAdZdBdZdCdZdDdZdEdZ	 d	 	 	 	 	 	 	 	 	 dFdZdGdZdHdZdȐdIdZ	 d	 	 	 	 	 	 	 	 	 dJdZ	 	 	 	 dK	 	 	 	 	 	 	 	 	 	 	 dLdZdMdZdNdZddZddZdOdZdPdZdQdZdȐdRdZ	 d	 	 	 	 	 	 	 	 	 dSdZdȐdTdZdUdZdVdZdWdZdXdZdYdZdZdZd[dZd\dZd]dZd^dZdNdZdNdZed_d       Ze	 	 	 	 	 	 	 	 d`d       Z	 d	 	 	 	 	 	 	 d`dZdadÄZdadĄZy=(b  ExpressionCheckerz^Expression type checker.

    This class works closely together with checker.TypeChecker.
    mypy.checker.TypeCheckerchkr1   msgzlist[Type | None]type_contextzdict[Expression, ProperType]resolved_typer   strfrm_checkerry   pluginc                ^   || _         || _        || _        || _        |j                  j
                  du| _        d| _        dg| _        i | _	        t        | | j                   | j                        | _        i | _        d| _        | j                   j                  j                   t        _        y)z%Construct an expression type checker.NF)r  r  r  per_line_checking_time_nsoptionsline_checking_statscollect_line_checking_statsin_expressionr  type_overridesr   r  r  	is_calleeold_type_inferencer   infer_polymorphic)selfr  r  r  r  s        r   __init__zExpressionChecker.__init__;  s     )B&+.;;+J+JRV+V( #!F 794T488TXXN +/88+;+;+N+N'N
$r   c                    i | _         y r   )r  r  s    r   resetzExpressionChecker.reset]  s
    r   c                    | j                   j                  j                  t        |             | j	                  |      }| j                  ||      }| j                   j                  |j                  |       |S )z_Type check a name expression.

        It can be of any kind: local, member or global.
        )r  module_refsr   r   analyze_ref_exprnarrow_type_from_bindercheck_deprecatedr   )r  eresultnarroweds       r   visit_name_exprz!ExpressionChecker.visit_name_expr`  sa    
 	##$9!$<=&&q)//6:!!!&&!,r   Fc                   d }|j                   }t        |t              r%|j                  rt	        t
        j                        S t        |t              rC| j                  ||      }t        |t              r| j                  j                  ||||      }nt        |t              rt        || j                  d            }nt        |t              r|j                   g| j                  j#                         r2|j$                  r&| j                  j'                  |j(                  |       t	        t
        j*                        }n|j                   }nt        |t,              r|j.                  r| j1                  |      }n9|j2                  dk(  rt5        t7                     }nt9        || j                        }t        |t:              rPt        |j<                  t>              r6|j@                  |j<                  _         |jB                  |j<                  _!        tE        | jF                  d         rtI        jJ                  |      }nt        |tL              r| jO                  |      }nt        |tP              r| j                  |jR                  |      }nt        |tT              r#| jW                  |||jX                  xs |      }nt        |tZ              r| j                  d      S t        |t\        t^        f      r| ja                         }n>t        |tb              rJ d|j2                  d       t	        t
        j*                        }|J |S )Nbuiltins.functionztypes.NoneTypectxalias_definitionztyping.TypeVarzPlaceholderNode z leaked to checker)2r   r   rX   is_special_formr   r   special_formrq   analyze_var_refr   r  handle_partial_var_typerN   r   
named_typer[   r   in_checked_functionr   handle_cannot_determine_typename
from_errorrm   typeddict_typetypeddict_callabler   r   r   r   r   ret_typer   linecolumnis_type_type_contextr  r   erase_typevarsrV   module_typerG   varr   alias_type_in_runtime_contextis_alias_rvaluern   r\   ro   object_typer]   )r  r%  lvaluer&  r   s        r   r"  z"ExpressionChecker.analyze_ref_exprk  s   "vva"q'8'891122dC ))$2F&+.99&&$PQRg&"49L)MNF/0yy 88//1djjHH99$))QG !5!56h'""006"22!(*-)$@&,/J5
 ()vv$)*&#D$5$5b$9: #11&9h'%%d+Fi())$((A6Fi( 77!a.?.?.I6 8 F k*??#344}.>?@%%'F$0T 00AASTTu Y112F!!!r   c                0   |j                   rt        |j                         }t        |t              ru|j                  dk(  r| j                  d      S | j                         r|j                  |j                  S |j                  dv r| j                  |j                  dk(  d      S |j                   S |j                  s@| j                  j                         r&| j                  j                  |j                  |       t        t        j                         S )Nz
typing.Anytyping._SpecialForm>   TrueFalserG  builtins.bool)r   r   r   r   r   r3  is_literal_contextlast_known_valuer6  infer_literal_expr_typeis_readyr  r4  r5  r   r   r0  )r  r@  contextvar_types       r   r1  z!ExpressionChecker.analyze_var_ref  s    88&sxx0H(H-<<</??+@AA**,1J1J1V#444880077F8JO\\88O<<DHH$@$@$B55chhH91122r   c                   	 | j                  d      }i }t               }|j                  j	                         D ]  \  }}|j
                  st        |j                  t              r'|j                  j                  r|j                  |       | j                  j                  |      }|r|||<   wt        t        j                        ||<    t!        |||j"                        |_        |S # t        $ r | j                  d      }Y w xY w)Nztypes.ModuleTypebuiltins.object)r3  KeyErrorr   namesr   module_publicr   r   rq   is_finalr   r  determine_type_of_memberr   r   r0  r   r   extra_attrs)r  r   r&  module_attrs	immutabler6  ntyps           r   r?  zExpressionChecker.module_type  s    	8__%78F E	zz'')GD!??!&&#&166??d#((33A6C%(T" &-Y-C-C%DT" * (iO)  	8 __%67F		8s   C, ,D	D	c                   |j                   rjt        |j                   t              r'|j                   j                  s| j	                  |       | j                  |j                   | j                  d         S | j	                  ||      S )zType check a call expression.r+  allow_none_return)analyzedr   rW   is_typedvisit_call_expr_inneracceptr  )r  r%  r^  s      r   visit_call_exprz!ExpressionChecker.visit_call_expr  sj    ::!**n5ajj>Q>Q **1-;;qzz4+<+<R+@AA))!?P)QQr   c                   t        |t              syt        |j                  t              r|j                  j                  yt        |j                  t
              xr- t        t        |j                  j                        t              S )NFT)	r   r_   r   rm   r8  r   r   targetr   )r  bases     r   refers_to_typeddictz%ExpressionChecker.refers_to_typeddict  sb    $(dii*tyy/G/G/S$))Y/ 
JDII,,-}5
 	
r   c                     j                  j                        s?t        j                  t              r j                  j                  j                        rt         j                  j                  d            }t        |t              r[t        |j                        }t        |t              sJ  j                  |j                  j                  j                  |      S t        j                  t              rj                  j                  dv rt!        j                        dk(  rt"        j$                  j'                  j                  d         D ]  }d }t        |t              r&	  j(                  j+                  |j                        }t/        |      r2 j0                  j3                  j                  j                  d       y|rt        |j4                  t6              rst        |j4                  j8                        }t        |t:              r2 j0                  j3                  j                  j                  d       t        |t<              rt        |t              r t        |j>                  t@        tB        f      s}t        |t              r|rt        |j4                  t6              rl|j4                  jD                  sVt        t        |j4                  j8                        x}tF              r|jH                  s j0                  jK                         t        |tL              st        |j4                  tN              s|j4                  jP                  r3 j0                  j3                  j                  j                  d       G|j4                  jR                  s_ j0                  j3                  j                  j                  d	         jU                         d }	t        j                  tV              rtY        j                  j                  j                  j                  j                  j                   fd
      }
t[        t!        j                  j                              D cg c]D  }t]        j^                  |
|   D cg c]   } j                  j                  |         " c}      F }}}t        |j                  j                  j                  j                   ja                          jc                  d            }	t         j                  j                  |	dd            }d }d }d t        j                  tL              rj                  jd                  xs d t        j                  j4                  t6              rOt        j                  j4                  j8                        }t        |tf              r|jh                  jd                  st        j                  tj              rt j(                  jm                  j                  jn                        rEj                  j                  } j(                  jq                  j                  jn                        } j(                  jr                  jt                  r j(                  jw                         rt        |t              r|jx                  r}|j                  tz        k7  rj||J  j}                  ||      r2t        fd j(                  jr                  j                  D              s j0                  j                  |        j                  |||      }t        j                  tL              rkt!        j                        dk(  rSj                  jd                  dv r j                         j                  jd                  dk(  r j                         t        j                  tj              r*j                  j                  dk(  r j                         t        |      }t        |tF              rt        |j                        }t        |t              r0|j                  s$ j(                  j                  j                          |sjt        |t<              rZ j                  j                        r? j(                  j0                  j                  |       t;        t        j                        S |S # t,        $ r Y w xY wc c}w c c}}w )NTr  )r   
issubclassr  r   LiteralAny	TypedDictNewTypec                @    j                  j                  |          S r   )rb  args)ir%  r  s    r   <lambda>z9ExpressionChecker.visit_call_expr_inner.<locals>.<lambda>/  s    $++affQi0r   r*  )r:  fallback)always_allow_anyr  c              3  T   K   | ]  }|k(  xs j                  | d        ! yw)r   N)
startswith)r   pr   s     r   r   z:ExpressionChecker.visit_call_expr_inner.<locals>.<genexpr>d  s6      '?A A=!4!4s!W!==?s   %()zbuiltins.isinstancebuiltins.issubclassrx  format)Prg  calleer   rP   rf  r   rb  r   r:  r   check_typeddict_call	arg_kinds	arg_namesrp  rX   r6  lenmypycheckerflattenr  lookup_qualifiedrR  is_expr_literal_typer  cannot_use_function_with_typer   r   re  r   r   r_  rk   rj   no_argsr   uses_pep604_syntaxtype_arguments_not_allowedr_   rm   r8  
is_newtypetry_infer_partial_typerR   r   ranger   join_type_listrC  r3  r   r   r   rU   has_typer   lookup_typer  disallow_untyped_callsr4  implicitr8   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   r7  )r  r%  r^  r9  r8  r[  r   re  union_targetr  formal_to_actualrq  j	arg_typescallee_typerC  memberr:  r   s   ``                @r   ra  z'ExpressionChecker.visit_call_expr_inner  s   $$QXX.!((I.((7!0QXXQU1V!W,l;!01C1L1L!M!.-@@@00"AKKaffaI[  qxx*!==AFFq ||++AFF1I6c8,#xx88B (,HH::188==)UVWJtyy)<,TYY-=-=>F!&'2>>qxx}}eUVW !&(3 sI."3<</=1QRsH-"499i8 II--"?499CSCS3T#T<V_`(;; HH77:c7+
388X0Nxx..>>qxx}}k[\],,>>qxx}}iYZ[I 7J 	##A&ahh
+5""""0  s188#5#5677A ##EUVWEX$YEXT[[%;EX$YZ7   (""""))+)<=L &KK,QUKV

 ahh( xx((0DH!((--3()=)=>fh/%{{33H qxx4HH%%ahhmm4"hh22188==A HH33,,.;5$$  K/F$6"...//VD3 '))??' $ ..{A>88Hk6
 ahh(S[A-=xx  $RR003xx  $99..q1ahh
+0I&&q)"8,h	*,X^^<Hh09K9KHHOO'')
 "8X.((2HHLL..{A>9//00y $ X %Zs*   ?%d9#e>%e	#	e9	ee	ec                   t        |j                  t              sJ d}t        |j                  j                  t              r"|j                  j                  j
                  }n_| j                  j                  |j                  j                        r/t        | j                  j                  |j                  j                              }t        |t              r|j                  j                  rt        |j                  t              rvt        |j                  j
                  t              rR|j                  j                   |j                  j
                     j                  }t        |t"              rt        |      }t%        |      }t        |t              r&t        |j
                  t              r|j
                  }|| j&                  j)                  ||       yy)z>More precise type checking for str.format() calls on literals.N)r   rz  rU   r   re   valuer  r  r   r  r   r   is_enumrK  r   strrS  r   try_getting_literalr  r  )r  r%  format_valuer[  
value_typebase_typs         r   r  z'ExpressionChecker.check_str_format_call  s<   !((J///ahhmmW-88==..LXXqxx}}-!$(("6"6qxx}}"EFC3)HH$$s33[As33993? XX^^C,@,@,F,FGLL
j$/)*5C*3/H(K0ZPS5T'~~#55aF $r   c                   t        |      }t        |t              r&|j                         rt        |j                        }nt        |t
              r|j                  }d}t        |t              r|j                  j                  }n{t        |t        t        f      r6|j                  j                  j                  |      }||j                  nd}n/t        |t              rt        |      j                  j                  }|r| d| S y)zConvert a method name to a fully qualified name, based on the type of the object that
        it is invoked on. Return `None` if the name of `object_type` cannot be determined.
        Nr   )r   r   r   is_type_objr:  r   itemr   r   r   r   r   rs  get_containing_type_infor   r   )r  rC  method_name	type_nameinfos        r   r  z!ExpressionChecker.method_fullname  s     &k2k<0[5L5L5N *+*>*>?KX.%**K	k8,#((11Im[%AB'',,EEkRD)-)9tIY/&{388AAI[+//r   c                D   t        |t              r| j                  |j                        ryt        |t              r|j                  t        | j                  j                  |j                              }t        |t              r|j                  }nTt        |t              rC|j                         r3t        |j                        }t        |t              r|j                  }nyy|j                  |j                        }|r| j                  |j                        ryy)zPCheck if `node` refers to something explicitly annotated as only returning None.TF)r   r_   defn_returns_noner   rU   r   r  r  r   r   r   r   r  r:  getr6  )r  r   r[  r  r:  syms         r   r  z%ExpressionChecker.always_returns_none  s    dG$%%dii0dJ'DII,=!$(("6"6tyy"ABC#x(xxC.3??3D*3<<8h1#==D ((499%Ct--chh7r   c                p    t        |t              rIt        |j                  t              xr- t        t	        |j                  j
                        t              S t        |t              rt         fd|j                  D              S t        |t              rt	        |j                        }|j                  s4t        |t              r$t        t	        |j
                        t              ryt        |t              r9|j                  j                  d      }|r j                  |j                        ryy)z'Check if `defn` can _only_ return None.c              3  @   K   | ]  }j                  |        y wr   )r  )r   r  r  s     r   r   z6ExpressionChecker.defn_returns_none.<locals>.<genexpr>  s     K
t--d3
   T__call__F)r   rN   r   r   r   r:  r   r[   r   r   rq   is_inferredr   r  r  r   )r  defnr[  r  s   `   r   r  z#ExpressionChecker.defn_returns_none  s    dG$dii6 :		 2 23X<  d-.K

KKKdC !$)),C$$sL1s||<hG#x(hhll:.411#((;r   c                   t         j                  j                  |j                  d         D ]  }t	        | j
                  j                  |            }t        |t              s8|j                         sI|j                         j                  sd|j                         j                  r| j
                  j                  t        j                  |        y Nr   )r  r  r  rp  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    LL((3D !5!5d!;<B2|,NN$NN$00(99.HH!L 4r   c                   t         j                  j                  |j                  d         D ]  }t	        | j
                  j                  |            }t        |t              s8|j                         sI|j                         j                  sdt        |j                               }|s| j
                  j                  j                  |j                         ||        y r  )r  r  r  rp  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    LL((3D !5!5d!;<B"l+0@R^^EUEaEa:2>>;KLHHLL;;BNN<Ll\]^ 4r   c                   |rt        d |D              rot        |D cg c]  }|t        |      nd  c}|      }| j                  ||      }	|	|	\  }
}| j	                  ||
|||      S t        t        j                        S t        |      dk(  r|d   t        k(  r|d   }t        |t              r| j                  ||j                  ||      S t        |t              rBt        |j                  t              r(| j                  ||j                  j                  ||      S |s| j	                  |i ||t!                     S | j"                  j%                  t&        j(                  |       t        t        j                        S c c}w )Nc              3  8   K   | ]  }|t         t        fv   y wr   )r3   r6   )r   aks     r   r   z9ExpressionChecker.check_typeddict_call.<locals>.<genexpr>   s     Iyy)44ys   kwargsrz  r   r   )r   zipre   validate_typeddict_kwargs check_typeddict_call_with_kwargsr   r   r7  r~  r4   r   rH   check_typeddict_call_with_dictr   rA   r_  r   r  r  r   INVALID_TYPEDDICT_ARGS)r  rz  r|  r}  rp  rN  orig_calleerZ  r  r&  validated_kwargsalways_present_keys
unique_args                r   r{  z&ExpressionChecker.check_typeddict_call  sz    CIyII SA'!*4?SUYZF336&3QF!8>5 "5<<,g{DW  9//00t9>ilg5aJ*h/::J,,g{  *h/Jz?R?RT\4]::J//55w  88Wk[^[`aa&==wGy++,,7 Ts   Fc                   t        t              }t               }d }|D ]  \  }}|r| j                  |      }t	        ||      }	d }
|	rt        |	      dk(  r|	d   }
|
B|xs |}| j                  j                  t        j                  |t        j                          y |g||
<   |j                  |
       |}| j                  ||||      r y  | j                  j                  j                  rX|Vg }|j                   D ]'  }||j"                  vs||vs|j%                  |       ) |r| j&                  j)                  ||       ||fS )Nr   r   code)r   listr   rb  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  rz  r&  r  last_star_founditem_name_expritem_argkey_typevaluesliteral_valuekey_contextabsent_keyskeys                 r   r  z+ExpressionChecker.validate_typeddict_kwargs!  sW    T"!e(.$NH;;~61.(K $c&kQ.$*1IM ("0"<HKHHMM(MM#".. " 
  
 .6JF=)'++M:"*88ff.A  5 )/6 88((_-HK||f222s&7H&&s+ $ 
 ;;KY***r   c           
        t        | j                  ||            }g }t        |t              r|g}nt        |t              rpt        |j                               D ]S  }t        |t              r|j                  |       %| j                  |      r7| j                  j                  ||        y n.| j                  |      s| j                  j                  ||       yt               }|D ]  }	||	j                  j                         z  }! |D ]  t        t	        j                  |D 	cg c]   }	|	j                  v s|	j                     " c}	            }
|
j!                  |       t#        fd|D              rD|j%                         |   r'|   d   }t        |t              s||
g|<   |
g|<   |
g|<   |   j                  |
        yc c}	w )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              3  :   K   | ]  }|j                   v   y wr   )r  )r   tdr  s     r   r   zAExpressionChecker.validate_star_typeddict_item.<locals>.<genexpr>u  s     B\r3"***\s   r   T)r   rb  r   r   r   r   relevant_itemsr  valid_unpack_fallback_itemr  %unsupported_target_for_star_typeddictr   r   keysrh   
make_unionset_liner   r   )r  r  rz  r&  r  inferredpossible_tdsr  all_keysr  argfirstr  s               @r   r  z.ExpressionChecker.validate_star_typeddict_itemS  s    #4;;xf;#MNh.$:L),()@)@)BCdM2 ''-88>HHBB4R  D 00:HH::8XN UB'H C$$l%^lcUWU]U]obhhsml%^_C LL"B\BB#'',
 #;"3KNE%eX6 (-cls'*es#&%F3K s""3'1 2 / &_s   -GGc                   t        |t              ryt        |t              r|j                  j	                  d      syt        || j                  j                  d            }t        d t        |j                        D              S )NTtyping.MappingFc              3  <   K   | ]  }t        |t                y wr   )r   r   r   as     r   r   z?ExpressionChecker.valid_unpack_fallback_item.<locals>.<genexpr>  s     Q3Pa:a)3P   )r   r   r   r   has_baser-   r  lookup_typeinfor   r   rp  )r  r[  mappeds      r   r  z,ExpressionChecker.valid_unpack_fallback_item  se    c7##x(0A0ABR0S*30H0HIY0Z[Q3CFKK3PQQQr   c                    | j                  ||      }|W|\  }}|j                  t        |j                               cxk  xr& t        |j                  j                               k  S c S y)Nr  F)r  r  r   r  r   )r  rz  r  rN  r&  r  _s          r   match_typeddict_call_with_dictz0ExpressionChecker.match_typeddict_call_with_dict  sj     //vf/M"(a''3/?/D/D/F+Gc3v||O`O`ObKcccccr   c                    | j                  ||      }||\  }}| j                  |||||      S t        t        j                        S )Nr  )r  rN  r  r  )r  r  r   r   r7  )r  rz  r  rN  r  r&  r  r  s           r   r  z0ExpressionChecker.check_typeddict_call_with_dict  se     //vf/M4:1188''$7 9   9//00r   c           	        |j                   J |j                   j                  }t        |t              rt        |t              sJ t        |j                  j                               }t        j                  gt        |      z  }t        |j                  j                               }t        ||||| j                  d      |j                  j                        S )a  Construct a reasonable type for a TypedDict type in runtime context.

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

        Note it is not safe to move this to type_object_type() since it will crash
        on plugin-generated TypedDicts, that may not have the special_alias.
        builtins.type	variables)special_aliasre  r   r   r   r  r   r  r<   r3   r~  r  r   r3  r  	type_vars)r  r  re  expected_typeskindsrS  s         r   r9  z$ExpressionChecker.typeddict_callable  s     !!---##**&*-*V]2SSSfll1134""#c.&99V\\&&()OOO,ii))
 	
r   c           	     T   t        t        |j                  j                               |j                  D cg c]0  }||j                  v rt
        j                  nt
        j                  2 c}t        |j                  j                               || j                  d            S c c}w Nr  )
r   r  r   r  r  r<   r3   ARG_NAMED_OPTr  r3  )r  rz  r6  s      r   typeddict_callable_from_contextz1ExpressionChecker.typeddict_callable_from_context  s    $$&' #LL(D &*V-A-A%A!!wG\G\\( ""$%OOO,	
 		
s   5B%
c                0   |j                         }|j                  r.||j                  z  }|r| j                  j	                  ||       |j
                  |k  r||j                  j                         k  s%||j                  j                         k  s`| j                  j                  ||j                  j                         D cg c]  }||j
                  v s||v r| c}t        |      |       |j
                  |k  sq| j                  j                  ||j                  j                         D cg c]  }||j
                  v s| c}|D cg c]  }||j
                  v s| c}|       |j
                  |kD  rt        t        j                        S t        |      }t        |t              r|}	nW|j                  j                   j"                  &| j%                  |j                  j                         }	n| j'                  |      }	| j                  j)                         5  | j*                  j-                         5  | j/                  |	|j1                         D 
cg c]  }
|
d   	 c}
t2        j4                  gt7        |      z  |t        |j                               d d d       \  }}d d d        d d d        t              }t        |t8              s|}|j                  j                         D ]l  \  }}||v s||   }|D ]X  }| j*                  j;                  |||t=        t>        j@                  jB                  tD        jF                        d| dd       Z n |S c c}w c c}w c c}w c c}
w # 1 sw Y   xY w# 1 sw Y   xY w)	NrN  )expected_keysactual_keysrN  r   r  zTypedDict item ""
expression)lvalue_typervaluerN  r  lvalue_namervalue_name)$r  to_be_mutatedreadonly_keysr  readonly_keys_mutatedr  r   unexpected_typeddict_keysr  r   r   r7  r   r   r   rs  r   r
  r9  r  filter_errorsr  local_type_mapcheck_callable_callr  r<   r3   r~  r   check_simple_assignmentr0   r   INCOMPATIBLE_TYPESr  r  TYPEDDICT_ITEM)r  rz  r  rN  r  r  r  assigned_readonly_keysr  infer_calleerp  orig_ret_typer  r:  	item_nameitem_expected_typeitem_values
item_values                     r   r  z2ExpressionChecker.check_typeddict_call_with_kwargs  sO    kkm%063G3G%G"%../Ew.W  $77K6<<K\K\K^<^6<<#4#4#6622 $*<<#4#4#6##6C&"6"66#:L #6#
 !%[ 1# 3 	 ((,??22'-||'8'8':#':cVEYEY>Y':# (;!':cVEYEY>Y':! $ 3 	 ##k1 y3344%k2k<0&L ##11=#66v7K7KL  $CCFK XX##%txx'>'>'@#77 &,]]_5_Ta_5""#c&k1V[[]# M1 (A% #=1(M2 H-5^^-A-A-C)I)F"$Y/"-JHH44$6) *(,??EEEL`L` '7yk$C$0 5 	 #. .D U##!< 6 (A'@%%sU   M,
6M1

M1
M6(M6,NN &M;2AN 4N;N  N		NNc                   t        |j                  t              rDt        |j                  j                  t              r |j                  j                  j
                  sy| j                  j                  j                         }|r|j                  |j                  vry|j                  |j                     }t        |j                  t              r0t        |j                  j                  t              r|j                  S y)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   rX   r   rq   is_selfr  scopeenclosing_classr6  rS  r   r   )r  r   r  r  s       r   get_partial_self_varz&ExpressionChecker.get_partial_self_var7  s     tyy(+499>>3/		&& xx~~--/tyy

2jj#chh$CHHMM;)O88Or   r  r   discard)builtins.listr   zClassVar[dict[str, list[str]]]	item_argsextendr3  r   builtins.dictr   )r3  r6  zcollections.OrderedDictr   z)ClassVar[dict[str, dict[str, list[str]]]]container_argsc                   t        |j                  t              sy|j                  }t        |j                  t              rS| j                  |j                        }|y|\  }}| j                  ||j                  |      }|||v r||_        ||= yyyt        |j                  t              rBt        |j                  j                  t              r|j                  j                  y|j                  j                  }|j                  j                  }| j                  |      }|y|\  }}t        |j                        }	|	|	j                  y| j                  ||j                  |      }
|
|| j                  |      }t         j"                  j%                  |      rK|	j                  J |	j                  j&                  }| j(                  j+                  |||
g      |_        ||= yyyyy)z-Try to make partial type precise from a call.N)r   rz  rU   r   r_   get_partial_var&try_infer_partial_value_type_from_callr6  r   rP   rf  r_  indexget_partial_instance_typer  rb  r  r  is_valid_inferred_typer   r  named_generic_type)r  r%  rz  retr@  partial_typesr[  rf  r;  partial_typer  r  typenames                r   r  z(ExpressionChecker.try_infer_partial_typeY  s   !((J/fkk7+&&v{{3C{!$C==acRC3-#7!#& $8 Y/Jv{{?O?OQX4Y{{##/;;##DKK%%E&&t,C{!$C4SXX>L#|'>'>'FDDQUXYJ%;;u-<<66x@',,888+0099H#xx::8hPZE[\CH%c* A & 5Z/r   c                    |j                   }|!t        |t              r| j                  |      }t        |t              sy | j
                  j                  |      }|y ||fS r   )r   r   rU   r1  rq   r  find_partial_types)r  refr@  r@  s       r   r9  z!ExpressionChecker.get_partial_var  s^    hh;:c:6++C0C#s#33C8 M!!r   c                6   | j                   j                  ryt        |j                        }|y|j                  r!|j                  j                  j
                  }n$|j                  J |j                  j
                  }|| j                  v r|| j                  |   v ro|j                  t        gk(  r[| j                  |j                  d         }t        j                  j                  |      r| j                   j                  ||g      S y|| j                  v r|| j                  |   v r|j                  t        gk(  rt!        | j                  |j                  d               }t#        |t$              rv|j                  j
                  }|| j                  |   |   v rKt'        d |j                  D              r/| j                   j                  |t)        |j                              S yt#        |t*              r| j                   j-                  |      S y)zCTry to make partial type precise from a call such as 'x.append(y)'.Nr   c              3  Z   K   | ]#  }t         j                  j                  |       % y wr   )r  r  r=  )r   	item_types     r   r   zKExpressionChecker.try_infer_partial_value_type_from_call.<locals>.<genexpr>  s'      )6I ;;IF)6s   )+)r  current_node_deferredr<  r   r  r   r4  r|  r4   rb  rp  r  r  r=  r>  r7  r   r   r   r   r  r   r3  )	r  r%  
methodnamer@  rA  rB  rH  arg_typearg_typenames	            r   r:  z8ExpressionChecker.try_infer_partial_value_type_from_call  s    88))0:""#..33<<H$$000#((11H &dnnX66y(AFF1I.I||229=xx228i[II$ ! +++d11(;;y(&t{{166!9'=>H(H-'}}554#6#6x#@#LL )1   $xx::8T(--EXYY  Hg.xx**844r   c
                   t        |j                        }
t        |
      D cg c]  }g  }}t        |
      D cg c]  }g  }}t        |
      D cg c]  }g  }}t        |
      D cg c]  }g  }}t        |      D ]  \  }}|D ]u  }||   j	                  ||          ||   j	                  ||          |r||   j	                  ||          n||   j	                  d       ||   j	                  ||          w  |V| j
                  j                  |      }|J  |t        |||j                  ||j                  ||	| j                              S | j
                  j                  |      }|J t        |      } |t        ||||j                  ||j                  ||	| j                  	            S c c}w c c}w c c}w c c}w )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.
        N)r  r|  callee_arg_namesr}  default_return_typerp  rN  api)	r   r  r|  rN  r}  rO  rp  rN  rP  )r~  r  r  	enumerater  r  get_function_hookru   r}  r:  r  get_method_hookr   rw   )r  rz  r|  r  r}  r  rp  r   rC  rN  num_formalsr  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   . &**+:?:L-M:LQb:L-M@Ek@R3S@R1B@R3S@Ek@R3S@R1B@R3S=B;=O0P=O=O0P()9:OFG! (//	&0AB (//V=$V,33If4EF$V,33D9 (//	&0AB "  ; {{44X>H'''..%+%5%5.(.)#	  #kk99(CO"...)+6K"$..%+%5%5.(.)#
 G .N3S3S0Ps   	F=	G	G+	Gc                    t        |t              rt        |j                        }t	        |||j                  |j
                   fd      }t        |      D cg c]  }g  }	}t        |      D ]#  \  }
}|D ]  }|	|
   j                  |           %  ||	|      S t        |t              sJ g }|j                  D ]:  } j                  ||||      }t        |t              sJ |j                  |       < t        |      S c c}w )z@Helper to apply a signature hook for either a function or methodc                ,    j                  |          S r   rb  rq  rp  r  s    r   rr  z8ExpressionChecker.apply_signature_hook.<locals>.<lambda>      $++d1g.r   )r   r   r~  r|  r   r}  r  rQ  r  r   r   apply_signature_hook)r  rz  rp  r|  r}  hookrT  r  r  rV  rY  rZ  r[  r   r  adjusteds   ` `             r   rd  z&ExpressionChecker.apply_signature_hook   s    fl+f../K5    .  EJ+DV7WDVqDV7W#,-=#>%F$V,33DLA & $? (&11fj111E44T4IW[\!(L999X& % e$$ 8Xs   	D	c           	     <      j                  |||| fd      S )zKApply a plugin hook that may infer a more precise signature for a function.c                @     t        | |j                              S r   )rv   r  )rp  sigrN  r  signature_hooks     r   rr  zAExpressionChecker.apply_function_signature_hook.<locals>.<lambda>/  s    ~.@sGUYU]U].^_r   )rd  )r  rz  rp  r|  rN  r}  rj  s   `   ` `r   apply_function_signature_hookz/ExpressionChecker.apply_function_signature_hook   s'     ((_
 	
r   c           
     V     t        |       j                  |||| fd      S )zIApply a plugin hook that may infer a more precise signature for a method.c           	     B     t        | |j                              S r   )rx   r  )rp  ri  rN  pobject_typer  rj  s     r   rr  z?ExpressionChecker.apply_method_signature_hook.<locals>.<lambda>D  s    .$\4gtxxP#r   )r   rd  )	r  rz  rp  r|  rN  r}  rC  rj  rn  s	   `   `  `@r   apply_method_signature_hookz-ExpressionChecker.apply_method_signature_hook2  s3     '{3((

 
	
r   Nc           	        t        |      }|{t        |t              rk|6| j                  j	                  |      }|r| j                  |||||||      S |S | j                  j                  |      }	|	r| j                  ||||||	      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_hookro  get_function_signature_hookrk  )
r  callable_namerz  rp  r|  rN  r}  rC  method_sig_hookfunction_sig_hooks
             r   transform_callee_typez'ExpressionChecker.transform_callee_typeJ  s    0 !($FL)I&"&++"G"G"V";;i)[Ra   %)KK$K$KM$Z!$==i)EV  r   c                "   |j                   sJ t        |j                        dk7  st        |      dk7  ryt        t	        |j                  d         t
              syt        t	        |j                        t
              sy| j                  j                         5  | j                  j                         5  t	        | j                  |d   d            }ddd       ddd       t        t              r|S y# 1 sw Y   $xY w# 1 sw Y   (xY w)zSCheck if this looks like an application of a generic function to overload argument.r   Nr   r  )r	  r~  r  r   r   r   r:  r  r!  r  r   rb  r   )r  r  rp  rK  s       r   "is_generic_decorator_overload_callz4ExpressionChecker.is_generic_decorator_overload_calls  s     $$$${$$%*c$i1n/+*?*?*BC\R/+*>*>?NXX$$&'')*4;;tAwT;+RS * ' h
+O	 *) '&s$   D6 C9D9D	>DDc                   g }g }|j                   D ]  }t        |      }| j                  j                         5 }| j	                  ||gt
        g|      \  }	}
ddd       j                         r`t        	      }t        |t              s|t        
      }t        |t              s|j                  |       |j                  |        |r|syt        |      t        |      fS # 1 sw Y   xY w)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   rh   r  r   
check_callr4   has_new_errorsr   r   r   r  r   )r  r  
overloadedr-  r&  inferred_argsr  r  erritem_resultinferred_argp_item_resultp_inferred_args                r   handle_decorator_overload_callz0ExpressionChecker.handle_decorator_overload_call  s     $$Dt$C'')S,0OOK#QXPY[^,_)\ *!!#+K8Mm\:,\:Nnl;  0MM-( % ]&!:m#<<<! *)s   C((C1	c           
     <   |||J | j                  ||      }t        |      }|r6| j                  |||j                  |j                  ||j
                  |      }n%|#t        |t              r| j                  |||      S | j                  ||j                  |j                  ||j
                  |j                  ||      \  }}t        |      }t        |j                  t        t        f      r2| j                  j                  |j                  j                  ||       t        |j                  t               r^t        |t"              rN|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'.
        )callable_noders  rC  )re  )r  r   rv  rp  r|  r}  r   r   check_union_call_exprr{  rz  rX   rU   r  warn_deprecated_overload_itemr   r_   r   
type_guardtype_is)r  r  r%  rs  rC  r  r:  proper_callees           r   r  z2ExpressionChecker.check_call_expr_with_callee_type  sd   &  V%7*** 00fEM%k244{AFFAKKAKKQ\K J{I$F--afEE $FFKKKK(('# !0 	!
+ (4ahh: 67HH22188==!K2Xahh(Z|-T''3&3&>&>#$$0#0#8#8 r   c                   g }|j                         D ]  }| j                  j                         5  t        |||ddd| j                  || j                  | j                         |      }ddd       | j                  |j                  d      }|| j                  ||      }|r|nd}	|j                  | j                  ||||	              t        |      S # 1 sw Y   rxY w)zFType check calling a member expression where the base type is a union.F)	is_lvalueis_superis_operatorr  original_typer  in_literal_context	self_typeNT)skip_non_overlapping)r  r  r   r   r  rJ  r#  rz  r  r  r  r   )
r  r%  rC  r  resr[  r  r'  rs  item_object_types
             r   r  z'ExpressionChecker.check_union_call_expr  s    --/C''),#" %"-'+'>'>'@! * 33AHHdY]3^H 00f=M&3sJJ55h=Rbc+ 00 %S))- *)s   9CC#	c
                    t        |      }t        |t              rO|j                  r+| j	                  ||      }
|
| j                  ||
|      }||S | j                  ||||||||      S t        |t              r| j                  |||||||      S t        |t              s| j                  j                         s| j                  ||      S t        |t              r| j                  |||||      S t        |t              rt!        d||ddd| j"                  |	xs || j                  | j%                         
      }|j&                  j(                  dz   }| j+                  |||||||      }| j-                  ||||||||      }|r| j                  j/                  ||       |S t        |t0              r | j-                  |j2                  |||||      S t        |t4              r2| j7                  |j8                  |      }| j-                  ||||||      S t        |t:              r#| j-                  t=        |      ||||||||	      S | j"                  j?                  ||      t        t@        jB                        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
        r  FTr  r  r  r  r  r  r  z	.__call__r  )"r   r   r   r	  rx  r  r"  r   check_overload_callr   r  r4  check_any_type_callr   check_union_callr   r   r  rJ  r   r   rv  r{  
store_typer   upper_boundr   analyze_type_type_calleer  r   r   not_callabler   r7  )r  rz  rp  r|  rN  r}  r  rs  rC  r  r}  overloaded_resultcall_functionr&  r  s                  r   r{  zExpressionChecker.check_call  s   @ !(fl+!DDVTR
) )-(K(K
G)% )400++	 	 
+++iM;PW  (0L0L0N++D&99	*((y)WUU)1 HH+5vHH#'#:#:#<M #KK00;>M 66}dIw	SYM __	F  ##M6:M,??""D)Wi  )00gFD??4y'9m\\	*??v&$ # 
 
 88((979CWCW;XXXr   c	                    |j                         j                         }||j                  r|j                  }t        |j                        }	|j                         r&t        |	t              r|	j                  j                  }t        |t              r |j                  t        v r|j                  |fS |j                         rx|j                         j                  r^|j                  sR j                  j!                  t"        j$                  j'                  |j                         j                        |       n|j                         r|j                         j(                  r|j                  s|j                         j*                  s|j                         }
i }|
j,                  D ])  \  }}|t.        k(  r j1                  |
|      ||<   %d||<   +  j2                  j5                  |j                         j                  ||       |j7                         }|rt        |j8                  t:              rd}t=        |      D ]  \  }}|t>        k7  rt         jA                  |            }t        |tB              rtE        d |jF                  D              sW|rI j2                  j!                  d|tH        jJ                         tM        tN        jP                        |fc S d} tS        |||jT                  |jV                   fd      }t        |j                        }	t        |	tX              r>|	jZ                  r2t]        |j                        }t_        |       |ja                  |      }|jc                         rtE        d |jZ                  D              }te        |      } jg                  ||      }|r'tS        |||jT                  |jV                   fd	      } ji                  ||||||      }|r'tS        |||jT                  |jV                   fd
      }|jk                         }||t>        tl        gk(  rto        |      dk(  r jA                  d         } jA                  d         }t        |tp              rt        |tp              rt|jr                  tt        jv                  k(  rW|jr                  tt        jx                  k(  r:|jz                  |jz                  cxk(  r|jz                  k(  rn n|j                  |fS  j}                  |||      } j                  ||||||||        j                  ||||||       |j                         r[to        |      dk(  rMt        |j                   j                  d            r(|ja                  t        j                  |d               }|r j                  j                  ||       |re| j                  j                  |      s|F j                  j                  |      r+ j                  ||||||||	      }|ja                  |      }|j                  |fS )zxType check a call that targets a callable value.

        See the docstring of check_call for more information.
        Fc              3  <   K   | ]  }t        |t                y wr   r   r   r   r   s     r   r   z8ExpressionChecker.check_callable_call.<locals>.<genexpr>  s      >7E!Jq*-~r  z<Passing multiple variadic unpacks in a call is not supportedr  Tc                ,    j                  |          S r   ra  rb  s    r   rr  z7ExpressionChecker.check_callable_call.<locals>.<lambda>  s    dkk$q'*r   r:  c              3  H   K   | ]  }t        |t        t        f        y wr   )r   r   r   r   vs     r   r   z8ExpressionChecker.check_callable_call.<locals>.<genexpr>  s"      JZQ
1}.>?@JZs    "c                ,    j                  |          S r   ra  rb  s    r   rr  z7ExpressionChecker.check_callable_call.<locals>.<lambda>      dkk$q'2r   c                ,    j                  |          S r   ra  rb  s    r   rr  z7ExpressionChecker.check_callable_call.<locals>.<lambda>  r  r   r  r   r   rC  r  )Jwith_unpacked_kwargswith_normalized_var_argsr6  r   r:  r  r   r   r   r   r_   rz   r  r  from_type_typer  r  r   CANNOT_INSTANTIATE_PROTOCOLry  is_abstractfallback_to_anyabstract_attributesr7   can_return_noner  !cannot_instantiate_abstract_classvar_argr[  r   r  r5   rb  r   r  r   r  CALL_ARGr   r   r7  r   r|  r}  r   r	  r'   r   copy_modified
is_genericr(   +infer_function_type_arguments_using_contextr*   
param_specr6   r~  r   flavorr   ARGSKWARGSidinfer_arg_types_in_contextcheck_argument_countcheck_argument_typesr}   r3  r   make_normalizedr  r  rR  rS  r^  )r  rz  rp  r|  rN  r}  r  rs  rC  r:  r   r  	attr_nameabstract_statusr  seen_unpackr  arg_kindrK  r  fresh_ret_typeneed_refreshr  arg1arg2r  new_ret_types   ` `                        r   r"  z%ExpressionChecker.check_callable_calll  s     ,,.GGI V[["KKM"6??3Jx$B$MM22MmW--2H2HJ2V??F**  ""$00))HHMM <<CCFDVDVDXD]D]^
  ""$00))&&(88%%'D 46.2.F.F*	?"&99595I5I$PY5Z'	25:'	2	 /G
 HH66""$))+> .."z'++z:  K!$T9!5Xx'*4;;s+;<!(I6# >7?~~> ; #Z#!& & 
  'y';';<fDD"&K "6  2*
 #6??3h-(2D2D<V__MN 0))>)BF JPJZJZ L 07FEEfgVF $:$$$$2$  77i4DlT[F #9$$$$2$  &&(
"h	22$%*;;tAw'D;;tAw'D4/t]3KK?#7#77KK?#9#99GGtww7*--7..33FD)M]^	!!		
 	!!y$0@'Wb 	" 	

  Y1$foot/OP))83K3KIVWL3Y)ZFHHv6 T[[%B%B=%Q'DKK,G,G,V55 
L ))<)@F&&r   c                   t         j                  sy|j                  D ]  }|j                  j	                  |      }|!|j
                  }t        |t              r|j                  }t        |t              r|j                  }t        |t              sv|j                  t        |j                  t              sJ t        t               |j                  j                         c S  y)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mrorS  r  r   r   r[   implrG   funcrN   r   r   r   r   r:  )r  r   r  rf  symnoder   s         r   r  z!ExpressionChecker.can_return_none'  s    
 $$ HHDjjnnY/G<<D$ 12yy$	*yy$(99(%dii>>>%hj$))2D2DEE  r   c           
        t        |t              rt        t        j                  |      S t        |t              rrt        |j                  | j                        }t        |t              r|j                  d      }t        ||      }t        |t              r|j                  g       }|S t        |t              rKt        |j                         D cg c]  }| j                  t        |      |       c}|j                        S t        |t               r| j                  t        |j"                        |      }t        |      }t        |t              r|j                  |      }|S t        |t$              r3t%        |j&                  D cg c]  }|j                  |       c}      }|S t        |t(              r=t+        |      j                  j,                  dk7  r| j                  t+        |      |      S t        |t.              r| j1                  |      S | j2                  j5                  ||       t        t        j6                        S c c}w c c}w )zzAnalyze the callee X in X(...) where X is Type[item].

        Return a Y that we can pass to check_call(Y, ...).
        
source_anyT)r  r  r  builtins.tuple)r   r   r   from_another_anyr   r   r   r3  r   r  r&   r   r  r  r   r;  r   r  r   r   r   r   r   r   r  r  unsupported_type_typer7  )r  r  rN  r  expandedr  rz  cs           r   r  z*ExpressionChecker.analyze_type_type_callee?  s   
 dG$955$GGdH%"499doo>C#|,''t'<.sD9H(L1 $11B1?OdI& #1133 11/"2EwO3 		  dK(
 22?4CSCS3TV]^F$V,F&,/--t-< M FJ/#V\\$Z\Q__d_%C\$Z[MdI&>$+?+D+D+M+MQa+a001EwOOdM*77==&&tW5y++,,3  %[s   "IIc                    g }|D ]I  }| j                  |      }t        |      r|j                  t                      9|j                  |       K |S )zInfer argument expression types in an empty context.

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

8:&

8$  
r   c                R    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 ]c  \  }}|D ]Y  }||   j                         r|j                  |   }	| j	                  |	      }
| j                  ||   |	      ||<   |
t        _        [ e t        |      D ]  \  }}|r	| j                  ||         ||<   ! 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 
 y wr   r   )r   r  s     r   r   z?ExpressionChecker.infer_arg_types_in_context.<locals>.<genexpr>  s     0Cb2T>Cs   )r~  rQ  is_starr  r  rb  r   r  r   r   r   r   )r  rz  rp  r|  r  r  rq  rZ  airK  r  r   s               r   r  z,ExpressionChecker.infer_arg_types_in_context  s     #'#d)!3#$45JAw },,.%//2H CCHMC"kk$r(H=CG.1J+  6 cNDAqT!W-A # 0C0000DJ$$r   c                   | j                   d   }|s|S t        |t                     }|j                  }t	        |      r!t	        |      rt        |      }t        |      }t        |t              r&t        |      st        |      s|j                         S t        |j                  ||d      }g }|D ];  }t        |      st        |      r|j                  d       +|j                  |       = | j!                  |||d      S )a  Unify callable return type to type context to infer type vars.

        For example, if the return type is set[t] where 't' is a type variable
        of callable, and if the context is set[int], return callable modified
        by substituting 't' with 'int'.
        r+  Tskip_unsatisfiedN)r  r"   r   r:  r   r   r   r   r   r   r  r+   r	  has_uninhabited_componentr  r  apply_generic_arguments)	r  callableerror_contextr-  
erased_ctxr:  rp  new_argsr  s	            r   r  z=ExpressionChecker.infer_function_type_arguments_using_context  s     #O 'sJL9
$$x(-@-E 'x0H(4J h,0 's+4H4M--//#*t
 ')C(-1Ec1J%$	  ++h , 
 	
r   c                     j                   j                         r j                  j                         5   j	                  ||      }ddd        j                  |t                    }	g }
t        |      D ]0  \  }}|	|   dkD  r|
j                  d        |
j                  |       2 t        |
||| j                          j                   j                               \  }}d|	v r j                  ||||||      \  }j                  dk(  rt        |      dk(  rt        |v st        |v rt        |d         }t!        |t"        t$        f      r j'                  d      |d<   nG|rt)         j'                  d      |      s* j                   j+                  t,        j.                  |        j                   j0                  j2                  sTt5        fd|D              r?|r't7        ||j8                  j:                   fd	      }t        |||| j                          j                   j                         d
      \  }} j=                  ||      }t?        j@                  ||      }|tC        d |D              rtE        |       |S t%               }d
|_#        |D cg c]A  }|;tI        |tK        jL                        |z   D ci c]  }|jN                  | c}      ndC }}}n0tQ        tR        jT                        gt        jL                        z  } jW                  ||      S # 1 sw Y   xY wc c}w c c}}w )zInfer the type arguments for a generic callee type.

        Infer based on the types of arguments.

        Return a derived callable type that has the arguments applied.
        Nr   )rN  strictr  dictr   builtins.strc              3     K   | ]O  }|d u xsE t        t        |      t              xs* t        t	        |            t        j
                        z   Q y wr   )r   r   r   r   r   r	  )r   r  r  s     r   r   zBExpressionChecker.infer_function_type_arguments.<locals>.<genexpr>O  s_      ? 'A T	 Foa0/BF}Q'(3{/D/D+EEF 's   AAc                ,    j                  |          S r   ra  r  rp  r  s    r   rr  zAExpressionChecker.infer_function_type_arguments.<locals>.<lambda>^  s    $++d1g"6r   T)rN  r  allow_polymorphicc              3  \   K   | ]$  }|d uxr t        t        |      t                & y wr   )r   r   r   r  s     r   r   zBExpressionChecker.infer_function_type_arguments.<locals>.<genexpr>t  s3      // TMY*_Q5G*Y&YY/s   *,),r  r4  r  r   r  get_arg_infer_passesr~  rQ  r  r*   argument_infer_context#infer_function_type_arguments_pass2special_sigr3   r6   r   r   r   r   r3  r   r  r   &KEYWORD_ARGUMENT_REQUIRES_STR_KEY_TYPEr  r  r  r   r|  r}  r  r   
apply_polyr   r   r  r%   r  r	  r  r   r   unannotatedapply_inferred_arguments)r  r  rp  r|  r}  r  r  rN  r  arg_pass_nums
pass1_argsrq  r  r~  r  	first_argpoly_inferred_args	free_varspoly_callee_typeappliedunknownr  r  s   ```                    r   r*   z/ExpressionChecker.infer_function_type_arguments  sg     88'')
 '') ;;y2B	 *
 !55T9.>D	M -/J#I.3 #a'%%d+%%c*	 /  = 335xx335 M1 M!/3/W/W$! 	0,m ''61&!+)+yI/E ,M!,<=	i(O)DE'+~'FM!$"*T__^5TV_*`HHMM"2"Y"Y[bc88##663 ? '	? <   (>!!#--#--6($ 1N$ 77988779&*	1-"I $(#?#?!3W$ 
 $../?K&3 /// , )1"N)+$(! 0	! 0 = $tK<Q<Q7RU^7^_7^!g7^_ "	" 0  	! %Y%:%:;<s;CXCX?YYM,,[-QQi *)R  `	!s#   M6'MM1MMMc	           	         t        |      }	t        t        |	            D ],  \  }
}t        |t        t
        f      st        |      s(d|	|
<   .  j                  ||	|      }|r't        |||j                  |j                   fd      } j                  j                         5   j                  |||      }ddd       t        |||| j                               \  }	}||	fS # 1 sw Y   /xY w)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                ,    j                  |          S r   ra  r  s    r   rr  zGExpressionChecker.infer_function_type_arguments_pass2.<locals>.<lambda>  rc  r   r  )r  rQ  r   r   r   r   r  r  r   r|  r}  r  r   r  r*   r  )r  r  rp  r|  r}  r  old_inferred_argsr  rN  r~  rq  r  r  r  s   ` `           r   r  z5ExpressionChecker.infer_function_type_arguments_pass2  s    2 ./ 0 ?@FAs#/:;?STW?X#'a  A 22;wW5%%%%.  XX##%77T9.>I &
 9//1
q M)) &%s   'C**C3c                ~    t        | j                  j                  d      | j                  j                  d            S )Nr  typing.Iterable)r)   r  r3  r  s    r   r  z(ExpressionChecker.argument_infer_context  s4    #HH 014883F3FGX3Y
 	
r   c                
   dg|z  }t        |j                        D ]  \  }}d}	t        |j                  |         }
t        |
t              r|
j                         ry||   D ]q  }t        ||         }t        |t              rt        d||d      }|t        |      }t        |t              sN|j                  r[t        ||   t              rod}	 n |	r|j                  t                     s||   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  r  )rQ  r  r   r   r   r  r   r|   r	  rR   rb  ArgInferSecondPassQuery)r  rz  rp  r  r  num_actualsr  rq  r  skip_param_specp_formalr  p_actualcall_methods                 r   r  z&ExpressionChecker.get_arg_infer_passes  s      cK 0 01FAs#O&v'7'7':;H(L1h6I6I6K)!,A.y|<H "(H5&1*h^b&c&2'6{'CH"8\: ( 2 2 *47J ?*.) -* #szz2I2K'L)!,ACF -5 28 
r   c                    t        |      D ]Y  \  }}|rt        |      s| j                  j                  ||dz   |       t	        t
        j                        gt        |      z  }[ | j                  |||      S )zApply inferred values of type arguments to a generic function.

        Inferred_args contains the values of function type arguments.
        r   )	rQ  r  r  could_not_infer_type_argumentsr   r   r7  r~  r  )r  r  r~  rN  rq  inferred_types         r   r  z*ExpressionChecker.apply_inferred_arguments  sq     !*- 8A} $8$G77QUGT!()=)=!> ?#mBT T	 !9 ++KPPr   c	                   |"t        t        t        j                              }i }	|D ]!  }
|
D ]  }|	j	                  |d      dz   |	|<    # | j                  |||||	|      \  }}t        |j                        D ]  \  }}|j                         r||   s~|s||j                         r9| j                  j                  |||       |rJ|rHd|v rD| j                  |||       n0|j                  |   xs d}| j                  j                  |||       d}|j                         snt!        ||   ||      r^| j"                  j%                         s#t'        t)        |||   d            t*              s| j                  j-                  |||       d}|j/                         rP||   rK|||   d      t0        j2                  t0        j4                  fvr | j                  j7                  ||       d}x|j9                         ||   r|j:                  dk7  s| j                  j                  |||       d} |S )aO  Check that there is a value for all required arguments to a function.

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

        Return False if there were any errors. Otherwise return True
        r   r   r   ?Fpartial)rh   r   r   r0  r   check_for_extra_actual_argumentsrQ  r|  is_requiredis_positionalr  too_few_argumentsmissing_classvar_callable_noter}  missing_named_argumentr  is_duplicate_mappingr  r4  r   r   r   duplicate_argument_valueis_namedr   r3   r6   too_many_positional_argumentsr  r  )r  rz  actual_typesactual_kindsactual_namesr  rN  rC  rs  all_actualsrZ  r  okis_unexpected_arg_errorrq  kindargnames                    r   r  z&ExpressionChecker.check_argument_count	  s$   $ ?wy'='=>?G
 ')'G!,A!6!:A  ( '+&K&KL,k7'
##
 !!1!12GAt!*:1*=F]%%'HH..vwM"}9M;;KX_`$..q18SGHH33FGWM\\^(< #\<) 88//1Z#L1A!1DQ1G$HI96 HH55faIB$Q' !1!!4Q!78RWRaRa@bb 66vwG!!#/(+&&)3**67LIC 3D 	r   c                h   d}d}t        |      D ]  \  }	}
|	|vr|
t        j                  k7  st        ||	         r}|
t        j                  k7  rjd}|
t        j
                  k7  r| j                  j                  ||       q|sJ d       ||	   }|J ||	   }| j                  j                  ||||       d}|
t        j                  k(  rt        j                  |j                  vs|
t        j                  k(  st        ||	         }t        |t        t        f      s|j                  |	d      t        |j                         k  s<|
t        j                  k7  st        |t              s| j                  j                  ||       n| j                  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 givenr   )rQ  r   r5   is_non_empty_tupler6   r3   r  too_many_argumentsunexpected_keyword_argumentr|  r   r   r   r   r  r~  r   "too_many_arguments_from_typed_dict)r  rz  r&  r'  r(  r)  rN  r+  r*  rq  r,  act_nameact_typeactual_types                 r   r  z2ExpressionChecker.check_for_extra_actual_argumentsT	  s    #( .GAt$ '+=l1o+N ' 5??*HH//@'Z)ZZ<+AH#///+AHHH888U\].2+&5>>AQAQ+Q(-l1o>kI}+EF"q!,s;3D3D/EE5??2*[R_:` HH77H HHGG &W 7;3"K /R ***r   c                   t        |t              rt        |t              r|j                  dd      \  }}|j                  j                  |      }|jt        |j                  t              rO|j                  j                  s8|j                  j                  s!| j                  j                  d| d|       y y y y y y y )Nr   r   )maxsplitr  zN" is considered instance variable, to make it class variable use ClassVar[...])r   r   r   r   r   r  r   rq   r  is_classvarr  note)r  rC  rs  rN  r  var_namer   s          r   r   z0ExpressionChecker.missing_classvar_callable_note	  s     k:.:k83T'..sQ.?KAx##''1DJtyy#$>yy,,TYY5J5JHHMMH: &G G 6K, %? 4U.r   c	                P   |xs | j                   }t        | j                               }	t        ||      D ]  \  }
}t	        |
      }
|t
        j                  k(  r-| j                  |
      s| j                  j                  |
|       |t
        j                  k(  se| j                  |
      rwt        |
| j                  j                  d            }| j                  j                  |
||        t!        |      D ]  \  }}t	        |j"                  |         }d}|D cg c]  }||   	 }}t%        |      dkD  rAt	        ||d            }t'        |t(              rt%        |j*                        dk(  rt'        |j*                  d   t,              r|t
        j                  gt
        j.                  gt%        |      dz
  z  z   k(  r|j*                  d   g|dd D cg c]  }||   	 c}z   }t'        |t,              r}t	        |j0                        }t'        |t(              rX|j*                  sJ |j*                  }t
        j                  gt
        j.                  gt%        |j*                        dz
  z  z   }d}|sK|D cg c]  }||   	 }}t'        |t,              rt	        |j0                        }t'        |t(              r_t3        |j*                        }|!|j*                  }t.        gt%        |      z  }n|j*                  |   }t'        |t,              sJ t	        |j0                        }t'        |t4              rH|j*                  }t7        t%        |j*                              D cg c]  }||k7  rt.        nt         }}n<t'        |t8              sJ |j0                  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 |j0                  j:                  dk(  sJ |j<                  d   gt%        |      z  }t.        gt%        |      z  }n+|gt%        |      z  }|j>                  |   gt%        |      z  }t%              t%        |      cxk(  rt%        |      k(  sJ  J t%              t%        |      k7  rgt%        |      t%        |      kD  r'| j                  j                  jA                  ||       n'| j                  j                  jC                  ||d       zt%        |      t%        |      k(  sJ t%        |      t%              k(  sJ t        |||||      D ]V  \  }}}}} ||	jE                  |||jF                     | t'        |t,                    }! ||!||||dz   |dz   ||||   |
       X  yc c}w c c}w c c}w c c}w )	zCheck argument types against a callable type.

        Report errors if the argument types are not compatible.

        The check_call docstring describes some of the arguments.
         _typeshed.SupportsKeysAndGetItemFr   r   NTr  )allow_unpack)$	check_argr   r  r  r   r   r5   is_valid_var_argr  invalid_var_argr6   is_valid_keyword_var_argr   r  r3  invalid_keyword_var_argrQ  r  r~  r   r   r   r   r4   r   r   r   r  r   r   rp  r|  r0  r  expand_actual_typer}  )"r  r  r|  rp  rz  r  rN  r>  rC  mapperrK  r  
is_mappingrq  rZ  orig_callee_arg_typeexpanded_tupler  r'  p_actual_typer&  p_callee_typecallee_arg_typescallee_arg_kindsunpacked_typeinner_unpack_indexinner_unpackinner_unpacked_typer[  r5  actual_kindcallee_arg_typecallee_arg_kindexpanded_actuals"                                     r   r  z&ExpressionChecker.check_argument_types	  s   " /	 !<!<!>?"%i";Hh&x0H5>>)$2G2G2Q((7;5??*43P3PQY3Z'dhh112TU
 00:wO #< $$45JAw#263C3CA3F#G  #N29:'QIaL'L:7|a /	'!*0E F}i8M//0A5"=#6#6q#9:F$(8EMM?cRYl]^N^;_(__$1$7$7$:#;U\]^]_U`>aU`PQy|U`>a#aL!"6
C(78L8Q8Q(R%mY?#0#6#66#6/</B/B,05/?5==/ #M$7$7 81 <C 0, .2N!6=>g	!g>2J?$34H4M4M$NM!-;-@ATAT-U*-5/</B/B,07y3w</G,+8+>+>?Q+RL#-lJ#GG#G2A,BSBS2T/)*=?OP 4A3F3F 0 .33}7J7J3K-L4"-L 014F/FGH$T-L !1 4" (22Ex'P P'P':'?'?'H'HL\'\ \'\$1$7$78K9K$L':'?'?'B&C'*7|c-:M:M6N'NQR'R'T%T '4&9&9:Lq:P:R&S%T !1 5<9s7|3K 0#M3CD,@+A(,4:()-BBB,11::>NNNN,9,>,>q,A+BS\+Q(,39s7|+C((<'=G'L$(.(8(8(;'<s7|'K$|$GIL8IIIIII#$L(99|$s+;'<<HHLL33FGDHHLL2267DI'(C,===='(C0@,AAAAVY|5EGWWR[/? &"(";";$$Q'#!+OZ!H #< # ##QJELWm 6 ; ?b  ? 4"s   !X!XX5X#c           
     :   t        |      }t        |      }t        |      }t        |t              r| j                  j	                  ||	       y| j                  ||      r| j                  j                  ||	       yt        ||| j                  j                        s|| j                  j                  |||||||	|
      }| j                  j                  |||	|       | j                  j                         s| j                  j                  |||	|       yyy)z.Check the type of a single argument in a call.)r  )rC  rN  outer_contextr  N)r   r   r   r  deleted_as_rvaluehas_abstract_type_partconcrete_only_callr   r  r  incompatible_argumentincompatible_argument_noteprefer_simple_messagescheck_possible_missing_await)r  caller_typeoriginal_caller_typecaller_kindr  rZ  mrz  rC  rN  rU  r  s               r   r>  zExpressionChecker.check_arg.
  s    &k2./CD%k2k;/HH&&{G<((kBHH''W=Kdhh>N>NO8811$'+ 2 	D HH//$k7 0  8822455k;PWY]^ 5 Pr   c                b    |j                         } j                  |      } j                  ||||      }	d}
d} j                  ||	      }d}t	         fd|D              r	  j
                  j                         5   j                  |	||||||||	      }ddd       rPt        | \  }}t        t        |      |j                  |j                         j                  t        |            f}	  j!                  |	|||||||      }|6|4t#        |d   |d         r t%        t'        |d         t(              s|s|S |S ||S ||S  j+                  |	|||||      }
t-        |
      dkD  r|
d   }nVt)        t.        j0                        }t3        |      sd}nt4        j6                  } j
                  j9                  ||||        j;                  |||||||      }|r,|s* j<                  j?                  t@        jB                  |       |S # 1 sw Y   |xY w# t        $ r d}Y ;w xY w)z(Checks a call to an overloaded function.NFc              3  @   K   | ]  }j                  |        y wr   )
real_union)r   r  r  s     r   r   z8ExpressionChecker.check_overload_call.<locals>.<genexpr>v
  s     9yts#yr  Tr   r  rs  rC  )"r  r  plausible_overload_call_targetspossible_none_type_var_overlapr  r  r   union_overload_resultr  r   r  r;  r<  combine_function_signaturesr   r   infer_overload_return_typer   r   r   r   overload_erased_call_targetsr~  r   r7  is_operator_methodr  OPERATORno_variant_matches_argumentsr{  r  r  r   TOO_MANY_UNION_COMBINATIONS)r  rz  rp  r|  r}  rs  rC  rN  r  plausible_targetserased_targetsunioned_resultnone_type_var_overlapunion_interruptedunioned_returnreturnsinferred_typesinferred_resultre  r  r&  s   `                    r   r  z%ExpressionChecker.check_overload_callV
  su    ,,.99$?	 @@y)V
 5937
 !% C CIO` a!9y99XX++-%)%?%?)!!!%#-
&N ." ".1>.B+G^ .d7mW\\7>>Z889I.9YZ&N 99	
 &>+E ?1-~a/@A"??13E#FP-&&!!'!!("" ::y)Yg
 ~" *!,F Y112F%m4~~HH11&)WSW1X'# ! 
 %:HHMM*FFPE .- ! )$(!)s*   $H >HH HH H.-H.c           
     |   dd}g }g }d}d}	t        |      D ]-  \  }
}|
t        k(  r
 ||      sd}|
t        k(  s# ||      r,d}	/ |j                  D ]  }t	        |||j
                  |j                  fd      }| j                  j                         5  |j                         |j                  |       ng| j                  ||||d      rQ|r|j                  r|j                  |       n1|	r|j                  r|j                  |       n|j                  |       ddd        ||z   S # 1 sw Y   xY w)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.c                    t        |       } t        | t        t        f      xs( t        | t              xr | j
                  j                  S r   )r   r   r   r   r   r   is_named_tuplerz  s    r   	has_shapezDExpressionChecker.plausible_overload_call_targets.<locals>.has_shape
  s>    !#&CcI}#=> 3)Echh.E.Er   FTc                    |    S r   r   rq  r  s    r   rr  zCExpressionChecker.plausible_overload_call_targets.<locals>.<lambda>  s
    iXYlr   Nr[  r   returnbool)r  r5   r6   r   r   r|  r}  r  r   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   re  z1ExpressionChecker.plausible_overload_call_targets
  s/   $	 ')+-! Y	2ID#x	#$(!y 3#' 	 3 >>C59cmmS]]DZ  '')>>#/ NN3'..Iy:JD )S^^$++C0)cmm$++C0s+! *)	 ", g%%% *)s   B
D22D;	c	                   g }	g }
g }t        t        t        |            }g }|D ]0  }| j                  | j                  j                  u sJ | j                  j                         5 }| j                  j                         5 }| j                  |||||||      \  }}ddd       ddd       j                          }|s|s!| j                  j                         fc S t              }t        |t              r|	j                  |       n|	j                  |       |
j                         |j                  |       |j                         3 |	syt        |	|
|||      rt        |
      r(| j                  j                  |d          |
d   |d   fS t        |
D cg c]  }t!        |       c}      r:| j                  j                  |d          t!        |
d         t!        |d         fS | j                  t#        t$        j&                        ||||||      S | j                  j                  |d          |
d   |d   fS # 1 sw Y   xY w# 1 sw Y   xY wc c}w )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.
        )rz  rp  r|  r}  rN  rs  rC  Nr   )r  maphas_any_typer  r  r   r!  r{  r|  store_typesr   r   r   r  any_causes_overload_ambiguityall_same_typesr    r   r   r0  )r  ro  rp  r  r|  r}  rs  rC  rN  r  return_typesrv  args_contain_any	type_mapsr[  wr`  r:  
infer_typeis_matchp_infer_types                        r   ri  z,ExpressionChecker.infer_overload_return_type  sP   * ')#%%'s<;<24	$C88txx||+++'')QXX,,.!+/??"!"+"+ '&3$/ ,; ,(Hj / * ++--H (HH((+#Z//.z:lL9 NN<0NN3'##H-%%j1  #; %> *7L)YXab l+$$Yq\2#Aq(999L ILSCL IJ$$Yq\2!,q/2J~a?P4QQQ"9#9#9:''#"/ + '   HH  1.?N1$555i /. *)J !Js*   &III&I*III'	c           	     h    g }|D ]*  }| j                  ||||||      s|j                  |       , |S )zReturns a list of all targets that match the caller after erasing types.

        Assumes all of the given targets have argument counts compatible with the caller.
        )erased_signature_similarityr  )	r  ro  r  r|  r}  rp  rN  r  r[  s	            r   rj  z.ExpressionChecker.overload_erased_call_targetsk  sC     ')$C//9isG s#	 %
 r   c                R   |r|syd}t        |      D ]A  }t        |t              st        |j                        D ]  }t        |t              sd} A C |syt        d |D              }t        |      D ]-  t        fd|D              st        fd|D              s- y y)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  F   K   | ]  }t        |j                          y wr   )r~  r  r   r  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>  s     E3DaQ[[)3Ds   !c              3  j   K   | ]*  }t        t        |j                           t               , y wr   )r   r   r  r   r   r  rq  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>  s*      O`!
?1;;q>:HEO`   03c              3  j   K   | ]*  }t        t        |j                           t               , y wr   )r   r   r  r   r  s     r   r   zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>  s*      RcQ
?1;;q>:KHRcr  )r   r   r   r   r   minr  r  )r  r  ro  has_optional_argrK  r  
min_prefixrq  s          @r   rf  z0ExpressionChecker.possible_none_type_var_overlap  s     !	 (3Hh	2(8dH-'+$ 9 4  E3DEE
z"A O`  Rc   # r   c                <   |
t         k\  rt        t        |      D ]  \  }}| j                  |      s n: | j	                  ||      5  | j                  ||||||||	      }ddd       |gS y|sZ| j	                  ||      5  | j                  ||||||||	      }ddd       %t        t        |d         t        t        f      s|gS t        ||         }t        |t              sJ g }|j                         D ]I  }|j                         }|||<   | j                  |||||||||	|
dz   
      }||j                  |       I y t               }g }|D ])  }||vs|j                  |       |j!                  |       + |S # 1 sw Y   &xY w# 1 sw Y   xY w)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   rQ  rc  type_overrides_setri  r   r   r   r   r  copyrg  r5  r   r   r  )r  ro  rp  r  r|  r}  rs  rC  rr  rN  levelidxr[  r  directfirst_union	res_itemsr  new_arg_types
sub_resultseenr&  pairs                          r   rg  z'ExpressionChecker.union_overload_result  s   , J "),HCs# -
 ((y955%!	 : u %((y988%!	 : !*q	*Y,@+ x &in5+y111	..0D%NN,M!%M#33!%	J %  , ' 1, (+uD4d#  I :9$ :9s   FFFFc                t    t        |      }t        |t              xr t        |j	                               dkD  S r  )r   r   r   r~  r  r  r[  s     r   rc  zExpressionChecker.real_union  s1    c"#y)Kc#2D2D2F.G!.KKr   c              #     K   t        |      t        |      k(  sJ t        ||      D ]  \  }}|| j                  |<    	 d |D ]  }| j                  |=  y# |D ]  }| j                  |=  w xY ww)z5Set _temporary_ type overrides for given expressions.N)r~  r  r  )r  exprs	overridesr   r[  s        r   r  z$ExpressionChecker.type_overrides_set  s{     
 5zS^+++UI.ID#(+D% /	.''- ''- s   =A2 A A2A//A2c                ,   |sJ d       t        d |D              st        t        j                        S t	        d|      }t        |      dk(  r|d   S t        |      \  }}t        t        |d   j                              D cg c]  }g  }}t        |d   j                        }g }d}|D ]  }	t        |      t        |	j                        k7  rd} nt        t        ||	j                              D ];  \  }
\  }}||k(  r|j                         r|j                         r
t        ||
<   9d} n |r nNt        |	j                        D ]  \  }
}||
   j                  |        |j                  |	j                           t#        |      }|rAt        t        j                        }|d   j%                  ||gt&        t(        gddg||d	      S g }|D ]  }t#        |      }|j                  |         |d   j%                  ||||d
      S c c}w )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                y wr   )r   r   r  s     r   r   z@ExpressionChecker.combine_function_signatures.<locals>.<genexpr>&  s     >1:a.r  list[CallableType]r   r   FTN)r  r|  r}  r:  r	  r  )r  r|  r:  r	  r  )r   r   r   r0  r   r~  #merge_typevars_in_callables_by_namer  r  r  r|  rQ  r  r  r4   r  r:  r   r  r5   r6   )r  r   	callablesr	  r  r  	new_kindsnew_returnstoo_complexre  rq  new_kindtarget_kindr  union_returnr  
final_args	args_listnew_types                      r   rh  z-ExpressionChecker.combine_function_signatures  s/    444u>>>91122-u5	y>QQ<  C9M	927IaL<R<R8S2T%U2TQb2T%U1//0	"$F 9~V%5%5!66".7IvGWGW8X.Y**Hk{*++-+2K2K2M#*IaL"&K /Z #F$4$453""3' 6v//  2 -[9)001CQ<--*#Y/,%# .   
!I,Y7Hh' " |)) ! * 
 	
_ &Vs   	Hc           	     v   t        |||j                  |j                  fd      }| j                  j	                         5  | j                  ||||d      s
	 ddd       y	 ddd       	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd}	 | j                  ||||||       y# 1 sw Y   =xY w# t        $ r Y yw xY w)z^Determine whether arguments could match the signature at runtime, after
        erasing types.c                    |    S r   r   r}  s    r   rr  z?ExpressionChecker.erased_signature_similarity.<locals>.<lambda>|  s    PYZ[P\r   NFc
                (    t        | |      st        y r   )arg_approximate_similarityr   )
r]  original_ccaller_typer_  r  rZ  r`  rz  rC  rN  rU  s
             r   r>  z@ExpressionChecker.erased_signature_similarity.<locals>.check_arg  s     .k;G  Hr   )rN  r>  T)r]  r   r  r   r_  r<   r  r   rZ  intr`  r  rz  r   rC  Type | NonerN  rF   rU  rF   r  None)r   r|  r}  r  r   r  r  r   )	r  r  r|  r}  rp  rz  rN  r  r>  s	    `       r   r  z-ExpressionChecker.erased_signature_similarityp  s,    2y&"2"2F4D4DF\
 XX##%,,	9i9I4  &% &		#'	 !	 		
 	 	 !	 %	 	 #	 	"	%% # &  E &%F  		s   B B,  B),	B87B8c                ^    t        j                  ||| j                  j                  ||      S )z=Simple wrapper around mypy.applytype.apply_generic_arguments.r  )r   r  r  incompatible_typevar_value)r  r  r   rN  r  s        r   r  z)ExpressionChecker.apply_generic_arguments  s0     00HH//-
 	
r   c                *   | j                  |       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  r0  )r  rp  rz  s      r   r  z%ExpressionChecker.check_any_type_call  sq    --d3 (fg&	22vF	22vF 
 9112GI<R<R4SSSr   c                   | j                   j                         5  |j                         D cg c]  }| j                  |||||       }}d d d        t	        D cg c]  }|d   	 c}      |fS c c}w # 1 sw Y   ,xY wc c}w )Nr   )r  disable_type_namesr  r{  r   )	r  rz  rp  r|  r}  rN  subtyperesultsr  s	            r   r  z"ExpressionChecker.check_union_call  s     XX((*  &4466G y'9M6   + &&A#s1v&ABFKK +* 'Bs"   A7A2
A7B2A77B c                    | j                   j                  j                  t        |             | j	                  ||      }| j                  ||      }| j                   j                  |j                  |       |S )z'Visit member expression (of form e.id).)r  r!  r   r   analyze_ordinary_member_accessr#  warn_deprecatedr   )r  r%  r  r&  r'  s        r   visit_member_exprz#ExpressionChecker.visit_member_expr  sa    ##$9!$<=44Q	B//6:  +r   c                f   |j                   | j                  |      S | j                  |j                  | j                        }|j                  }d}t        |t              r0t        |j                  t              r|j                  j                  }t        |t              rIt        |j                  t              r/|j                  j                  xs |j                  j                  }nd}t        |j                  |||dd| j                  || j                   | j#                         ||      }|S )z+Analyse member expression or member lvalue.Nri  F)	r  r  r  r  r  r  r  module_symbol_tabler.  )r,  r"  rb  r   r  r   r_   r   rV   rS  rq   r.  is_clsr   r6  r  r  rJ  )r  r%  r  r  rf  r  r.  member_types           r   r  z0ExpressionChecker.analyze_ordinary_member_access  s    66((++ !KK$..KIM66D"&$(Z		8-L&*iioo#$(Z		3-G ))++?tyy/?/?/#!HH+HH#'#:#:#<$7K r   c                p    t        |||ddd| j                  || j                  | 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  rJ  )r  r  	base_typerN  s       r   analyze_external_member_accessz0ExpressionChecker.analyze_external_member_access  s@     %##668
 	
r   c                2    t        | j                  d         S )Nr+  )r   r  r  s    r   rJ  z$ExpressionChecker.is_literal_context  s    #D$5$5b$9::r   c                    | j                  |      }| j                         rt        ||      S |j                  t        |||j                  |j
                              S )az  Analyzes the given literal expression and determines if we should be
        inferring an Instance type, a Literal[...] type, or an Instance that
        remembers the original literal. We...

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

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

        3. ...Infer an Instance that remembers the original Literal if we're declaring
           a Final variable with an inferred type -- for example, "bar" in "bar: Final = 3"
           would be assigned an Instance that remembers it originated from a '3'. See
           the comments in Instance's constructor for more details.
        )r  rs  )r  rs  r;  r<  )rK  )r3  rJ  r   r  r;  r<  )r  r  fallback_namer[  s       r   rL  z)ExpressionChecker.infer_literal_expr_type  s\    " oom,""$US99$$!,#CHHSZZ" %  r   c                    t        |j                        rt        |j                        rJ t        |j                  |j                  z   | j                  d            S )z$Concatenate two fixed length tuples.r  )r   rs  )r   r   r   r3  )r  leftrights      r   concat_tupleszExpressionChecker.concat_tuples/  sI    '

38KEKK8XYY**u{{*T__EU5V
 	
r   c                :    | j                  |j                  d      S )z(Type check an integer literal (trivial).builtins.intrL  r  r  r%  s     r   visit_int_exprz ExpressionChecker.visit_int_expr6      ++AGG^DDr   c                :    | j                  |j                  d      S )z&Type check a string literal (trivial).r  r  r  s     r   visit_str_exprz ExpressionChecker.visit_str_expr:  r  r   c                :    | j                  |j                  d      S )z%Type check a bytes literal (trivial).r   r  r  s     r   visit_bytes_exprz"ExpressionChecker.visit_bytes_expr>  s    ++AGG5EFFr   c                $    | j                  d      S )z%Type check a float literal (trivial).zbuiltins.floatr3  r  s     r   visit_float_exprz"ExpressionChecker.visit_float_exprB  s    /00r   c                $    | j                  d      S )zType check a complex literal.zbuiltins.complexr  r  s     r   visit_complex_exprz$ExpressionChecker.visit_complex_exprF  s    122r   c                $    | j                  d      S )zType check '...'.zbuiltins.ellipsisr  r  s     r   visit_ellipsisz ExpressionChecker.visit_ellipsisJ  s    233r   c                   |j                   r| j                  |j                         S |j                  dk(  s|j                  dk(  r| j                  ||      S |j                  dk(  r+t	        |j
                  t              r| j                  |      S |j                  dk(  rt	        |j
                  t              r0| j                  j                  |j
                  |j                        S t	        |j
                  t              r0| j                  j                  |j
                  |j                        S | j                  |j
                        }t        |      }t	        |t              r|j                  dk(  r|j                  j                   j#                  d      }|r|j$                  dk(  rt        | j                  |j                              }t	        |t              re|j                  j                   j#                  d      }|Et'        |j(                        t'        |j(                        | j+                  ||      S t,        | j.                  j0                  j2                  v rt	        |t4              r| j.                  j7                  |      r|j                   j#                  d      }||j                  j                   j$                  d	k(  rwt'        |j(                        b| j.                  j9                  ||      }| j.                  j;                  d	|g      }|j=                  |j(                  t?        |      gz   
      S t@        }	|j                  dk(  rtC        |d      r:t        | j                  |j                              }t	        |tD              rtF        }	t	        |tD              r6t        | j                  |j                              }tC        |d      rtH        }	t,        | j.                  j0                  j2                  v r|j                  dk(  rt	        |t4              r|j                   j$                  d	k(  rt        | j                  |j                              }t	        |t              ra|j                  j                   j$                  d	k(  r>t'        |j(                        )|j=                  t?        |      g|j(                  z   
      S |j                  tJ        jL                  v rtJ        jL                  |j                     }
|	tN        jP                  u s|	tN        jR                  u r4| jU                  |
||j                  ||	tN        jP                  u       \  }}nk|	tN        jV                  u rN| jU                  tJ        jX                  |
   | 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__r  )r   |r6  )r  r  rN  allow_reverseFzUnknown operator )0r_  rb  opcheck_boolean_opr   r  rT   check_list_multiplyr@   r  check_str_interpolationr  re   r   r   partial_fallbackr   r  r   r   r   r  rt   r  r  enable_incomplete_featurer   type_is_iterableiterable_item_typer>  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_methodrH  r  use_reversemethodr&  r  s                r   visit_op_exprzExpressionChecker.visit_op_exprN  s   ::;;qzz**445=ADDDL((A..443;:affh7++A..443;!&&),**BB166177SS!&&'***BB166177SSKK'	*95&	2qtts{.??DDHHSO?#;#;?W#W$3DKK4H$I!/;(9(J(J(O(O(S(ST^(_%(0 00@0F0FGO23D3J3JKS#'#5#56FHY#ZZ'488+;+;+U+UU"#4h?112CD ):(>(>(B(B:(N%)1,==BBKKO__/0@0F0FGO$(HH$?$?@QST$U	!%!<!<=MPY{![/=="2"8"8Jv<N;O"O  >    #6443; !1?C %4DKK4H$I!/?"4K*M: %4DKK4H$I!$%6H"3K$(("2"2"L"LL /:$))226FF$3DKK4H$I!0)<)::??HHL\\+,=,C,CDL,::)*:;<?P?V?VV ;   449'''))!$$/Fj000K:CSCS4S&*mm'"-1C1C"C '4 '# 
 1 11&*mm008"kk!''2"' '4 '# [)'AMM!2144&9::r   c                J
   d}t        |j                  |j                  dd |j                        D ]  \  }}}| j                  |      }|dk(  s|dk(  r| j	                  |      }|| j                  |      }t        |      }|g}t        |t              rt        |j                               }| j                         }	g }
g }d}d}|D ]  }| j                  j                  d      5 }| j                  d||gt        g||	      \  }}| j                  j!                  |      }ddd       t        |t"              rd}wj%                         r| j'                  |      r| j                  j                  d      5 }| j                  j)                  ||      \  }}ddd       j%                         r-| j                  j+                  |j-                                d}t/        |gt0        j                  gdg| j                         | j3                  d
            }|j4                  j7                  |       |j7                         |j%                         s0r.|
j7                  |       |j4                  j7                         | j                  j+                  |j-                                d} |s|st        j8                  |      }t;        ||      s|
s | j                  j=                  d|||       nt        j8                  |
      }| j?                  |||d      r| j                  j?                  ||d|       n|t        j@                  v rt        j@                  |   }tC        | j                  jD                        5 }| jG                  ||||d      \  }	}|j4                  j7                  |       ddd       j%                         s|dv r| j                  |      }| j?                  ||      rtI        |      }tI        |      }| j                  j?                  ||d|       n|dk(  s|dk(  r| j                  |      }| j                         }	| j?                  ||      r4tI        |      }tI        |      }| j                  j?                  ||d|       |j4                  j7                  d       ntK        d|       |	}tM        jN                  |	      } |J |S # 1 sw Y   xY w# 1 sw Y   oxY w# 1 sw Y   PxY w)zType check a comparison expression.

        Comparison expressions are type checked consecutive-pair-wise
        That is, 'a < b > c == d' is check as 'a < b and b > c and c == d'
        Nr   inznot inFTsave_filtered_errors__contains__)r  r  rp  r|  rN  r  r*  )original_containerprefer_literal	container)r  )z==z!=equalityiszis notidentityzUnknown comparison operator )(r  operandsr   rb  find_partial_type_ref_fast_pathr   r   r   r  r  	bool_typer  r   check_method_call_by_namer4   r  analyze_container_item_typer   r|  r?  -analyze_iterable_item_type_without_expression
add_errorsfiltered_errorsr   r   r3  method_typesr  r  r   unsupported_operand_typesdangerous_comparisonr  r#   errorsr  r  r  r   
join_types)r  r%  r&  r  r  operatorr  
right_type
item_typesr  container_typesiterable_types
failed_outencountered_partial_typerH  container_errorsr  r  	cont_typeiterable_errorsitertypeiterable_typecontainer_typer  r  s                            r   visit_comparison_exprz'ExpressionChecker.visit_comparison_expr  s    # &)QZZ^Q[[%Q!D%D)I48x#7 "AA%H
%!%U!3J,Z8
.8\
j)4!%j&?&?&A!BJ!^^-
.0-/"
+0(!+I //T/JN^)-)G)G#1&/"&'.i$%*4 *H *; %)HH$H$H$S	 K ")[9370(779 --i8 "XX333NRa*.((*`*` )1+KAx O +99; HH//0O0O0QR)-J*6!*!&!% $ 0 $0C D+K NN11+>*11(;-<<>9'..y9--k:++,<,L,L,NO%)
g ",j 0
$-$8$8$HM%i?. HH>>tYPZ\]^-6-A-A/-RN#88 ) .3=/4	  9   !% = =$-~{A!" Y111"--h7!$((//2a.2mm	5!4 /< /+J NN))+6	 3 '')h,.F!%U!3J00JG$7	$B	%8%D
55iZYZ[T!X%9![[/
!^^-
,,Y
C 3I >I!4Z!@JHH11)ZUVW%%d+"%A(#LMM ~#<M &RP !!!S KJ4 ONX 32s$   *<S>> T5T>TTT"	c                   t        |t              syt        |j                  t              r_| j	                  |j                  |      }t        |t
              r3|j                  '| j                  j                  |t        |             |S y)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   rq   r1  r   r   r  r  r   )r  r   r&  s      r   r  z1ExpressionChecker.find_partial_type_ref_fast_pathP  sj     $(dii%))$))T:F&+.6;;3J##D*<V*DEr   T)r  
seen_typesr  c                  | j                   j                  j                  sy|
t               }||f|v ry|j	                  ||f       t        ||f      \  }}t        |d      st        |d      ry|rt        |      }t        |      }| j                   j                  j                         ryt        |t              st        |t              ryt        |t              r6t        |t              r&t        |      }t        |      }t        ||f      \  }}|rt        |      rt        |      ryt        |t              rt        |t              r|j                   j"                  }|j                   j"                  }|t$        v ri|t$        v ra| j                   j'                  d      }t)        ||      }t)        ||      }| j+                  |j,                  d   |j,                  d   |      S |j                   j/                  d      r|j                   j/                  d      r| j                   j'                  d      }	t)        ||	      }t)        ||	      }| j+                  |j,                  d   |j,                  d   |      xs. | j+                  |j,                  d   |j,                  d   |      S |dv r3||k(  r.| j+                  |j,                  d   |j,                  d   |      S |t0        v r	|t0        v ryt        |t2              rEt        |t2              r5t        |j4                  t6              rt        |j4                  t6              ryt9        ||d	       S )
a  Check for dangerous non-overlapping comparisons like 42 == 'no'.

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

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

        Return tuple (result type, inferred method type). The 'original_type'
        is used for error messages.
        FT)r  r  r  r  r  r  r  r  )	r   r   r   check_union_method_call_by_namer   r  r  rJ  check_method_call)r  r  r  rp  r|  rN  r  r  s           r   r  z+ExpressionChecker.check_method_call_by_name  s     &2#I.	i+77	4G]  ,'#668
 %%fidIW^__r   c           
     4   g }g }|j                         D ]`  }	| j                  j                         5  | j                  ||	||||      \  }
}ddd       |j	                  
       |j	                         b t        |      t        |      fS # 1 sw Y   CxY w)a  Type check a call to a named method on an object with union type.

        This essentially checks the call using check_method_call_by_name() for each
        union item and unions the result. We do this to allow plugins to act on
        individual union items.
        N)r  r  r  r  r  r   )r  r  r  rp  r|  rN  r  r  meth_resr[  r  	meth_items               r   rC  z1ExpressionChecker.check_union_method_call_by_name  s     !++-C ,,."&"@"@Cy'=#i / JJtOOI& . %S)+@+JJJ /.s   BB	c                    | j                  ||      }||nd}| j                  ||||||      }| j                  ||||||      S )zType check a call to a method with the given name and type on an object.

        Return tuple (result type, inferred method type).
        Nr  rd  )r  rv  r{  )	r  r  r  r  rp  r|  rN  rs  rC  s	            r   rD  z#ExpressionChecker.check_method_call  sp     ,,YD#0#<i$ 00;ik 1 
 '!  
 	
r   c           
     r    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        ||      rt        |t              rrt        |t              rb|j                  j                  ,|j                  j                  j                  |j                  u s  |||       |||
      k7  r|
|||f||||fg}n||||f|
|||fg}|D cg c]  \  }}}}|||||f }}}}}g }g }|D ]H  \  }}}} j                  j                  d      5 } j                  ||||gt         g      }d d d        j#                         r1|j%                  |j'                                |j%                         t        |t              rt        |j                  j)                  |      x}t*              r|j,                  D ]r  }t        |t.              st        |j0                  j                  x}t2              s;t5        |      d   k(  sM j6                  j9                  |j0                         t c S  t        |t              r|j                  j:                  s&t        |t              r3|j                  j:                  rt        t        j<                        }	|	|	fS |s j                  j                  d      5 } j?                  |||gt         g      }d d d        j#                         r1|j%                  |j'                                |j%                         nS  j                  jA                  |d          tC        |      dk(  r|d   S t        t        jD                        }||f}|S c c}}}}w # 1 sw Y   RxY w# 1 sw Y   xY w)
Nc                    j                  ||       syj                  j                         5 }t        | |ddd|j                  j                  j                         
      }|j                         rdn|cddd       S # 1 sw Y   yxY w)zYLooks up the given operator and returns the corresponding type,
            if it exists.NFT)
r6  r[  r  r  r  r  rN  r  r  r  )
has_memberr  r   r   r  rJ  r|  )op_namer  r  r  rN  r  s       r   lookup_operatorz>ExpressionChecker.check_op_reversible.<locals>.lookup_operator9  s     ??9g6'')Q. !#" $"+#'+'>'>'@  !//1tv *))s   ABBc                    | j                   j                  D ]+  }|j                  j                  |      s|j                  c S  y)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  rS  r  r   )r[  r  clss      r   lookup_definerz=ExpressionChecker.check_op_reversible.<locals>.lookup_definerS  s5     xx||99==+<<' $ r   r  Tr  r   r   )rL  r  r  r   r  r  )r[  r   r  r  r  
str | None)#r   r   r   r   r  r   r  op_methods_that_shortcutr~   r   r   r   alt_promoter  r   rD  r4   r|  r  r"  
get_methodr[   r   rG   r  r   r   r  r$  r  r0  r  r!  r~  r7  )r  rL  r  	left_exprr)  
right_exprrN  rM  rP  any_typerev_op_nameleft_opright_opvariants_rawnar  objr  variantsr&  r  r6  r  local_errorsr&  r  r  r[  	error_anys   `     `                      r   check_op_reversiblez%ExpressionChecker.check_op_reversible0  s   	>4	  $I.	$Z0
 i)y99iPHX%%j'*y99jQHX%%
  227;!'95";
; i888\)U_=` %gy*EFLz9-9h/:x0**6NN..33zFy'2nZQ\6]] h
I>'9j9L '9j9h
I>L BN`+=BCQSQ_RS#&` &."D&#s''T'Bl//fsegYX_` C**,l::<=v&c8,HH//55D7H2 !%

&tY7 *$))..+@3, O )#&) ; HH55diiI !+ # '/, y(+	0N0Nz8,1P1Py556HX%% ''T'Bl77Ywi C
 **,l::<=v& F1I&w<11:	 4 45I	)FMG a CB@ CBs$   .P
;P
3P !P- P*	-P6c                   |r|g}t        |      }t        |t              r"t        t	        |j                                     }| j                  |      }g }g }	| j                  j                         5 }
|D ]I  }| j                  ||t        ||      |||      \  }}|j                  |       |	j                  |       K 	 ddd       
j                         st        |      }t        |	      }||fS ||fg}t        |      }t        |t              r3t	        |j                               D cg c]  }|t        ||      f }}g }g }	| j                  j                  d      5 }
|D ]S  }|D ]L  \  }}| j                  ||t        ||      |||      \  }}|j                  |       |	j                  |       N U 	 ddd       |
j                         r| j                  j                  |
j                                |
j                         d   }t        t!                     }|j"                  |_        |j$                  |_        t'        |      dk\  r*t'        |      dk\  r| j                  j)                  |       nYt'        |      dk\  r| j                  j+                  d||       n,t'        |      dk\  r| j                  j+                  d	||       t        |      }| j-                  t/        |	            }||fS | j1                  |||gt2        g|
      S # 1 sw Y   axY wc c}w # 1 sw Y   txY w)zType check a binary operation which maps to a method call.

        Return tuple (result type, inferred operator method type).
        r  )rL  r  rU  r)  rV  rN  NTr  r+  r  LeftRight)r  r  rp  r|  rN  )r   r   r   r  r   r  rb  r  r   ra  rh   r  r|  r   r!  r"  r   r;  r<  r~  "warn_both_operands_are_from_unionswarn_operand_was_from_unionrh  r   r  r4   )r  r  r  r  rN  r  left_variantsr)  all_resultsall_inferredr_  left_possible_typer&  r  results_finalinferred_finalright_variantsr  right_possible_typerV  r  recent_contexts                         r   r  zExpressionChecker.check_op  s<    &KM'	2I)Y/ $%:9;S;S;U%V WS)J
 KL'')\*7&'+'?'? &"4"*+=w"O#-#& ' (@ ($FH  &&v. ''1 +8 *  ..0 5k B!6|!D$n44  *3/0N(4J*i0 !6j6O6O6Q R" R 8D':; R  "
 KL''T'Bl*7&;I7+Z+/+C+C$*&8&./A7&S':'1$+ ,D ,( $**62$++H5 <J +8 C **,##L$@$@$BC"224R8!)(*!5&)hh#(+

%}%*s>/Ba/GHH??O'1,HH88Tb8c(A-HH88^ 9  2+>M!==>N|>\]N .0011#U") 2  [ *)@" CBs    3AL"0L/(AL4"L,4L>c                2   | j                   d   }| j                  |j                  |      }t        | j                  |j                  |      d      }|j                  dv sJ |j
                  rd}i }n|j                  ri d}}no|j                  dk(  r)| j                  j                  |j                        \  }}n7|j                  dk(  r(| j                  j                  |j                        \  }}t        j                  | j                  j                  j                  v r><|j
                  s0| j                  j                  |j                  |j                         | j                  j                         r><|j                  s0| j                  j!                  |j                  |j"                         | j                  j%                  du       5  | j'                  ||j"                  |      }ddd       |
t)               S ||J |S ||J S |j                  dk(  rt+        |      }	|j,                   }
n'|j                  dk(  rt/        |      }	|j0                   }
t3        	t(              rS 
r|S t5        |	g      S # 1 sw Y   xY w)z/Type check a boolean operation ('and' or 'or').r+  rI  )r  r  Nr  r  )r   )r  rb  r  r   r  right_alwaysright_unreachabler  find_isinstance_checkr  REDUNDANT_EXPRr  enabled_error_codesr  redundant_left_operand should_report_unreachable_issuesunreachable_right_operandr  r   analyze_cond_branchr   r   can_be_truer   can_be_falser   r   )r  r%  rN  r-  r  expanded_left_typeleft_map	right_mapr)  restricted_left_typeresult_is_lefts              r   r  z"ExpressionChecker.check_boolean_opc  sT    #KK,	<KK$o
 tt}$$$>>-1H.0I  "$diHTTU]"&(("@"@"HIxTTT\"&(("@"@"HHi
   DHH$4$4$H$HH NNHH++ADD!&&9 HH557!''HH..qttQWW=
 XX##)t2C#D11)QWWFXYJ E 	 1"$$'''(((445=#-.@#A !3!?!??NTTT\#,-?#@ !3!@!@@N*O<(*>
)KLL; EDs   JJc                N   | j                  |j                        }t        || j                  d            r+| j                  |j                  | j
                  d         }n| j                  |j                        }| j                  d||j                  |      \  }}||_        |S )zzType check an expression of form '[...] * e'.

        Type inference is special-cased for this common construct.
        r  r+  r  __mul__)rb  r  r   r3  r  r  r  r  )r  r%  r)  r  r&  r  s         r   r  z%ExpressionChecker.check_list_multiply  s    
 [[)
j$//."AB AFF9J9J29NOIAFF+I"mmIy!''1M#r   c                j   | j                  |j                        }| j                  j                  |j                  |j                         | j                  j                  |       t        |      s&| j                  j                  |j                  |       | j                  |j                         |S r   )	rb  r  r  check_assignmentre  check_finalr  r  r  )r  r%  r  s      r   visit_assignment_exprz'ExpressionChecker.visit_assignment_expr  s{    AGG$!!!((AGG4Q(/ HH%0,,QXX6r   c                2   | j                  |j                        }|j                  }|dk(  r8| j                         }| j                  j                  ||j                         |S t        j                  |   }| j                  ||g g |      \  }}||_	        |S )z7Type check an unary operation ('not', '-', '+' or '~').not)
rb  r   r  r  r  check_for_truthy_typer   unary_op_methodsr  r  )r  r%  operand_typer  r&  r  r  s          r   visit_unary_exprz"ExpressionChecker.visit_unary_expr  s    {{166*TT;>>+FHH**<@
  //3F"&"@"@WY[]_`"aFK'AMr   c                    | j                  |      }| j                  ||      }t        |      }| j                         r(t	        |t
              r|j                  |j                  }|S )zgType check an index expression (base[index]).

        It may also represent type application.
        )visit_index_expr_helperr#  r   rJ  r   r   rK  )r  r%  r&  p_results       r   visit_index_exprz"ExpressionChecker.visit_index_expr  sb    
 --a0--a8"6*##%8X.))5..Fr   c                    |j                   r| j                  |j                         S | j                  |j                        }| j                  ||      S r   )r_  rb  rf  visit_index_with_type)r  r%  r  s      r   r  z)ExpressionChecker.visit_index_expr_helper  sA    ::;;qzz**KK'	)))Q77r   c           
     P   |j                   }t        |      }| j                  |       t        |t              r(t        d |j                  D              rt        |i       }t        |t              r@|xs |}t        |j                         D cg c]  }| j                  |||       c}d      S t        |t              r,| j                  j                         rt        |t              r| j                  ||      S | j!                  |      }|g }|D ]  }| j#                  ||      }	|	|j%                  |	       )| j                  j'                  t(        j*                  |       t        d |j                  D              r0| j-                  |      }
| j                  j/                  d|
 |       t1        t2        j4                        c S  t        |      S | j7                  ||      S t        |t8              r| j;                  ||j                         d   S t        |t<              r|j?                         r|jA                         jB                  r+| jE                  |jA                         |j                   |      S | j                  jF                  jH                  dk\  rH|jA                         jJ                  s|jA                         jL                  dk(  r| jO                  d	      S t        |tP              r9| jS                  |jT                  d
      s| j                  |jT                  ||      S t        |tV              r*|jX                  jL                  dk(  r| jO                  d      S | j[                  d
||j                   gt\        g||      \  }}||_/        |S c c}w )zAnalyze type of an index expression for a given type of base expression.

        The 'original_type' is used for error messages (currently used for union types).
        c              3  <   K   | ]  }t        |t                y wr   r  r   s     r   r   z:ExpressionChecker.visit_index_with_type.<locals>.<genexpr>  s      4
1@2Jr:&r  F)contract_literalsc              3  <   K   | ]  }t        |t                y wr   r  r  s     r   r   z:ExpressionChecker.visit_index_with_type.<locals>.<genexpr>  s     R/Qz!Z8/r  zVariadic tuple can have length r   )   	   r  ztypes.GenericAlias__getitem__rF  r  )0r;  r   rb  r   r   r  r   r%   r   r   r  r  r  r4  rc   visit_tuple_slice_helpertry_getting_int_literalsvisit_tuple_index_helperr  r  r   TUPLE_INDEX_OUT_OF_RANGEmin_tuple_lengthr9  r   r   r7  nonliteral_tuple_index_helperr   visit_typeddict_index_exprr   r  r  r  visit_enum_index_exprr  python_versionr  r   r3  r   rK  r  r   r   r  r4   r  )r  r  r%  r  r;  r[  nsoutrZ  r  min_lenr&  r  s                r   r  z'ExpressionChecker.visit_index_with_type  s)    #I.	 	Ei+ 4
1:4
 1
 $Ir2Ii+)6YM(  )7799 ..sA}E9 #(  	9-$((2N2N2P %+44YFF..u5B~A88AFD'

4(&6&O&OQRSR)//RR&*&;&;I&FG HHMM,KG9*UWXY&y';';<<  -S1199)UKK	=1229aggFqII	<0Y5J5J5L$$&..11)2G2G2I177TUVV!!00F:%%'11((*33F';<<i-doo!!=7
 --i.C.CQVV	8,1H1HLa1a??#899"&"@"@y177)gYQ^ #A #FK (AMMgs   N#c                @   t        |j                        }||j                         S |j                  |   }t        |t              sJ t        |j
                  t              r*|j                         dz
  |j
                  j                  z   S |j                         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;;= L)&*---fkk#3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 y |j                  |   S y |j                  |   }t        |t              sJ t        |j                        }t        |t              rRt        |j                        }t        |t              sJ |j                  j                  dk(  sJ |j                  d   }n<t        |t              sJ |j                  j                  dk(  sJ |j                  d   }| j                  |      |j                         z
  dz   }|dk\  r{|| j                  |      k\  ry ||k  r|j                  |   S t        j                  |g|j                  |dz   t!        ||z
  dz   |dz          z   |j"                  |j$                        S || j                  |      z  }|dk  ry |||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   rp  r  r  r   r  maxr;  r<  r  )	r  r  rZ  r  r  unpackedboundmiddleextra_itemss	            r   r  z*ExpressionChecker.visit_tuple_index_helperG  s>   *4::61uS_$A'DJJ' zz!}$L)&*---"6;;/h 01 $H$8$89EeX...::&&*::::ZZ]Fh111==))-====]]1%F++D1DKKMAAE6D))$// <zz!}$''**\A-AOa4GXYIY0Z[\			  	
T""4((q5{**::a+o122##JJs1l+l;vhF		SWS^S^
 	
r   c           	        d g}d g}d g}|j                   r1| j                  |j                         }|| j                  ||      S |}|j                  r1| j                  |j                        }|| j                  ||      S |}|j                  r1| j                  |j                        }|| j                  ||      S |}g }	t        j                  |||      D ]  \  }
}}|j                  |
||| j                  d            }|E| j                  j                  t        j                  |       t        t        j                        c S |	j!                  |        t#        |	      S )Nr  rs  )begin_indexr  r  	end_indexstride	itertoolsproductslicer3  r  r  r   !AMBIGUOUS_SLICE_OF_VARIADIC_TUPLEr   r   r7  r  r   )r  r  slicbeginendr  	begin_rawend_raw
stride_rawr   br%  sr  s                 r   r  z*ExpressionChecker.visit_tuple_slice_helperw  sR   '+f%)F(,v55d6F6FGI 99)TJJE>>33DNNCG99)TJJC;;66t{{CJ!99)TJJF ((V<GAq!??1aT__EU5V?WD|.PPRVWy3344LL = %U++r   c                    t        |t              r|j                  gS t        |t              rs|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        | j                  |            }t        |t              r|j                  |j                  }t        |t              r't        |j                  t              r|j                  gS t        |t              reg }t        |j                        D ]I  }t        |t              r6t        |j                  t              r|j                  |j                         I y |S y)a  If the given expression or type corresponds to an int literal
        or a union of int literals, returns a list of the underlying ints.
        Otherwise, returns None.

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

        1. 'expr' is a IntExpr or a UnaryExpr backed by an IntExpr
        2. 'typ' is a LiteralType containing an int
        3. 'typ' is a UnionType containing only LiteralType of ints
        -r+  r  N)r   rQ   r  rp   r  r   r   rb  r   rK  r   r  r   r   r   r  )r  r;  operandr[  r  r  s         r   r  z*ExpressionChecker.try_getting_int_literals  s*    eW%KK= y)xx3**gw/.//xx3**gw/#MM?*dkk%01c8$)=)=)I&&Cc;'Jsyy#,FII;c9%C(3dK0Z

C5PJJtzz*	 4
 Jr   c                    | j                  d||gt        g|       | j                  |      }t        |t              r| j
                  j                  d|g      S |S )Nr  r  r  )r  r4   union_tuple_fallback_itemr   rc   r  r>  )r  r  r;  unions       r   r  z/ExpressionChecker.nonliteral_tuple_index_helper  sY    &&}i%7)]b&c..y9eY'88../?%IIr   c                   g }|j                   D ]  }t        |t              rt        |j                        }t        |t
              rt        |j                        }t        |t              r8|j                  j                  dk(  r|j                  |j                  d          t        |j                  |        t        |      S )Nr  r   )r   r   r   r   r   r   r  r   r   r  rp  NotImplementedErrorr   )r  r  r   r  rL  s        r   r  z+ExpressionChecker.union_tuple_fallback_item  s    OOD$
+ /		 :m-=>$3M4M4M$NM}h7%**337GGLL!3!3A!67--T" $ %U++r   c                   t        |t              r|j                  g}n&t        | j	                  |            }t        |t
              rt        |j                        }n|g}g }t        |      D ]  }t        |t              r|j                  |j                  }t        |t              rYt        |j                  t              r?|j                  j                  j                  dk7  r|j!                  |j                         | j"                  j%                  ||       t'        t(        j*                        t-               fc S  g }|D ]s  }	|j                  j/                  |	      }
|
C| j"                  j1                  ||	||       t'        t(        j*                        t-               fc S |j!                  |
       u t3        |      t-        |      fS )Nr   )r   re   r  r   rb  r   r  r   r   r   rK  r   r  rs  r   r   r  r  $typeddict_key_must_be_string_literalr   r   r7  r   r  typeddict_key_not_foundr   )r  td_typer;  setitem	key_namesr[  	key_typesr  value_typeskey_namer  s              r   r  z,ExpressionChecker.visit_typeddict_index_expr  sp    eW%I!$++e"45C#y)(,SYY	 E	I,Y7h1h6O6O6['88H x5"8>>37 ))..77;KK$$X^^4HHAA'5Q"9#7#78#%?? 8 !H **84J!00(E7Sy334ce;;"":. " %[13y>AAr   c                    | j                  d      }| j                  j                  | j                  |      ||dd       t	        |g       S )Nr  zEnum index should be a stringzactual index type)r3  r  check_subtyperb  r   )r  	enum_typer;  rN  string_types        r   r  z'ExpressionChecker.visit_enum_index_expr  sK     !OON;KK+	
 	2&&r   c                .   | j                  |j                  t        t        j                        dd      }|j
                  }| j                  j                  }|j                  r:t        t        |      t              s!||k(  r| j                  j                  ||       |j                  r(t        |      r| j                  j                  d||       t!        || j                  j                  | j                  j"                  | j                  |       |S )zType check a cast expression.Tr  r^  rt  zTarget type of castr  )rb  r   r   r   r0  r   r  r  warn_redundant_castsr   r   r  redundant_castdisallow_any_unimportedr   unimported_type_becomes_anyr   is_typeshed_stub)r  r   source_typetarget_typer  s        r   visit_cast_exprz!ExpressionChecker.visit_cast_expr
  s    kkII !7!78"!	 " 
 ii((""(({;WE{*HH##K6**/KK/XHH001FUYZ))488+D+DdhhX\	
 r   c                   | j                  |j                  | j                  d   dd      }| j                  j                  r|S |j
                  }t        |      }t        |t        j                  j                        r|j                  |j                  }t        ||      s]| j                  j                         s&| j                  j                  d|j                         | j                  j!                  |||       |S )Nr+  Tr  zC"assert_type" expects everything to be "Any" in unchecked functions)rb  r   r  r  rI  r   r   r   r  r   r   rK  r~   r4  r  r9  assert_type_fail)r  r   r  r  proper_source_types        r   visit_assert_type_exprz(ExpressionChecker.visit_assert_type_expr!  s    kkII**2."!	 " 
 88))ii,[9)4::+>+>?"33?,==KK588//1YII HH%%k;Er   c                   |j                   t        k(  r|j                  J | j                  |j                  | j                  d   d      }| j
                  j                  sw| j                  j                  ||j                         | j
                  j                         s&| j                  j                  d|j                         | j                  |       |S | j
                  j                  sj|j                  /|j                  D ci c]  }|j                  |j                   c}ni }| j                  j                  ||       | j                  |       t!               S c c}w )z$Type check a reveal_type expression.r+  Tr  r^  z9'reveal_type' always outputs 'Any' in unchecked functions)r,  r;   r   rb  r  r  rI  r  reveal_typer4  r9  check_reveal_importedlocal_nodesr6  r   reveal_localsr   )r  r   revealed_typevar_nodenames_to_typess        r   visit_reveal_exprz#ExpressionChecker.visit_reveal_expr;  s3   99#99((( KK		(9(9"(=QU ( M 8811$$]DII>xx335HHMMSUYU^U^ **40   8811 ''3 CGBRBRSBRhX]]HMM1BRS  &&~t<**40: Ts   E&c                   t         j                  | j                  j                  j                  vry d}|j
                  t        k(  rd}n#|j
                  t        k(  r|j                  sd}ny | j                  j                  d| d|t         j                         |dk(  rg| j                  j                  j                  dk\  rdnd	}d
j                  ||      }| j                  j                  ||t         j                         y y )N r  r  zName "z" is not definedr  )r     typingtyping_extensionszXDid you forget to import it from "{module}"? (Suggestion: "from {module} import {name}"))moduler6  )r  UNIMPORTED_REVEALr  r  ru  r,  r:   r;   is_importedr  r  ry  r9  )r  r   r6  r  hints        r   r  z'ExpressionChecker.check_reveal_importedZ  s    ""$((*:*:*N*NN99%"DYY+%d.>.> Dtf$45t%BYBYZ=  HH,,;;wFL_ ?fFf.  HHMM$5+B+BMC !r   c                   t        |j                  t              rt        |j                  j                  t              r|j                  j                  j
                  r| j                         S t        |j                  j                  |j                  | j                  j                  |j                  j                  j                  || j                  j                        }t        |      }t        |t              r=t        |j                   | j"                        }| j%                  ||j&                  |      S t        |t(              rq|j*                  j                   j,                  rQt        |j*                  j                   | j"                        }| j%                  ||j*                  j&                  |      S t        |t.              r| j1                  |      S | j                  j                  t2        j4                  |       t7        t8        j:                        S t        | j=                  |j                              }t        |t>        t@        f      rW|jC                         s*| j                  j                  t2        j4                  |       | j%                  ||j                  |      S t        |t6              rt7        t8        jD                  |      S t7        t8        jF                        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   r3   apply_type_arguments_to_callablerp  r   r  rz  r   r  r   ONLY_CLASS_APPLICATIONr   r   r7  rb  r   r   r  r  r0  )r  tappr  r  s       r   visit_type_applicationz(ExpressionChecker.visit_type_applicationq  s    dii)j.Syy~~440022)		

		&&  D #4(D$)%diiA<<RDQQD),1F1F1K1K1Z1Z%d&;&;&@&@$//R<<RAVAVA[A[]abbD-0;;DAA.EEtLy3344 T[[34b<45>>#.EEtL88TZZNNb'"955"EEy--..r   c                >    | j                  |j                  |d      S )a  Right hand side of a type alias definition.

        It has the same type as if the alias itself was used in a runtime context.
        For example, here:

            A = reveal_type(List[T])
            reveal_type(A)

        both `reveal_type` instances will reveal the same type `def (...) -> builtins.list[Any]`.
        Note that type variables are implicitly substituted with `Any`.
        Tr,  )rA  r   )r  aliass     r   visit_type_alias_exprz'ExpressionChecker.visit_type_alias_expr  s!     11%**%Z^1__r   )r.  c               `   |j                   r| j                         S t        |j                  t              r/|j                  j
                  rt        t        j                        S | j                  j                  j                  xr | j                  }t        t        |g |j                  |j                   | j                  j                  || j"                  j$                              }t        |t              rKt'        |j(                  | j*                        }|j,                  r|S | j/                  ||j0                  |      S t        |t2              rKt5        |      j(                  j6                  dk7  r)t'        t5        |      j(                  | j*                        S t        |t8              r| j;                  |      S t        |t<              r"t?        ||j                  |j                         S t        |t              rt        t        j@                  |      S t        |tB              rU|jD                  rI| j                  j                  jF                  dk\  r&| j                  jI                  d|jJ                        S |rt        t        jL                        S | j+                  d      S )a  Get type of a type alias (could be generic) in a runtime expression.

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

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

            x = A()
            y = cast(A, ...)
        )disallow_anyr  r  r;  r<  r  )r  
   ztypes.UnionTyperF  )'r  r  r   re  r   invalidr   r   r7  r  r  disallow_any_genericsr  r   r   r;  r<  r  r  r   r   r3  r  r  rp  r   r   r   r   r  r   r   r  r   r  r  r>  r   r0  )r  r  r-  r.  r  r  r  s          r   rA  z/ExpressionChecker.alias_type_in_runtime_context  s     '',,..ellH-%,,2F2F9//00
 xx''==P$..

  )XX]]

 dH% "$))T__=B}}	88TYYLLtY' 4 %%..2BB#N4$8$=$=tOOm,77==h'DtyyEEg&955$GGtY'''  //7:88../@$**MMy5566??#899r   c                   |j                         r%|j                         j                  j                  }nt	        |j
                        }t        |      }t        |j
                  |      D ]  \  }}t        |t              st        t        |      t        t        t        t        f      rA| j                  j                  dt!        || j                  j"                         |       t        t$        j&                        gt)        |      z  c S  |rt+        d |D              st	        |      S |j                         sJ |j                         }t-        |||j.                  |j0                        }t3        || j                  j                  d      sat5        || j                  j                  | j                  j6                  d| j                  j"                         t	        |j8                        }t;        d t=        |      D              }	t)        |      |	z
  d	z
  }
||	   }t        |t>              sJ tA        tC        |      |	|
      \  }}}t	        |      tE        t	        |      |jF                        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                y wr   r   r   r  s     r   r   z7ExpressionChecker.split_for_callable.<locals>.<genexpr>  s     M1z!-=>r  r  T)empty_tuple_indexF)r  r  c              3  H   K   | ]  \  }}t        |t              s|  y wr   r	  )r   rq  r  s      r   r   z7ExpressionChecker.split_for_callable.<locals>.<genexpr>   s     YoFQAGW9Xao   ""r   )$r  r  r  r  r  r	  r   r  r   r   r   r   r   r   r  r  r2   r  r   r7  r~  r  r   r;  r<  r   r   r9  rp  nextrQ  r   r   tupler   r   )r  r   rp  r-  varstvr  r  fakeprefixsuffixtvtstartr  r  s                  r   split_for_callablez$ExpressionChecker.split_for_callable  s    ==?==?''11D$D$T* 1;;-GB"m,!#C(:}g{*[ HHMM33>sDHHDTDT3U2VX
 $I$8$89:SYFF . 3MMM:}}}}d#**E !txx}}MdhhmmTXX]]PTPXPXP`P` 		?DYioYYTV#a'6l#/0009%+vvVvsE{iVc6H6HIJJTRUYVVr   c                   t        |      }t        |t              r|j                         r%|j	                         j
                  j                  }nt        |j                        }t        d |D              }t        d |D              }t        |      |k  st        |      t        |      kD  r	|s|j                         r|j	                         j                  dk(  rt        t        t        |      | j                  j                  d            gt         gdgt        t        |      | j                  j                  d            |j"                  d|j$                  |j&                        S | j(                  j+                  |t        |      t        |      |       t-        t.        j0                        S | j3                  || j5                  |||      |      S t        |t6              r7|j8                  D ]  }|j                         r%|j	                         j
                  j                  }nt        |j                        }t        d |D              }t        d |D              }t        |      |k  st        |      t        |      kD  s|r| j(                  j+                  |t        |      t        |      |       t-        t.        j0                        c S  t7        |j8                  D cg c]&  }| j3                  || j5                  |||      |      ( c}      S t-        t.        j:                        S c c}w )	a{  Apply type arguments to a generic callable type coming from a type object.

        This will first perform type arguments count checks, report the
        error as needed, and return the correct kind of Any. As a special
        case this returns Any for non-callable types, because if type object type
        is not callable, then an error should be already reported.
        c              3  >   K   | ]  }|j                            y wr   has_defaultr  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>A  s     GYAMMO 3Y   c              3  <   K   | ]  }t        |t                y wr   r	  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>B  s     $XiZ3C%Dir  r  r  N)r6  
definition
bound_argsc              3  >   K   | ]  }|j                            y wr   r  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>b  s     #KA$7r  c              3  <   K   | ]  }t        |t                y wr   r	  r  s     r   r   zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>c  s     (\R[QA7G)HR[r  )r   r   r   r  r  r  r  r  r	  sumr  r~  r   r   r  r3  r4   rs  r  r  r  incompatible_type_applicationr   r   r7  r  r  r   r   r0  )r  r  rp  r-  r  min_arg_counthas_type_var_tupler   s           r   r  z2ExpressionChecker.apply_type_arguments_to_callable'  s    R b,'~~ NN,11;;	 .	GYGGM!$$Xi$X!XD	M)SYY-G(>>#(8(A(AEU(U ("4:txx/B/B7/KLM 	!$t*dhh.A.A'.JK$#%==#%==	 	 66!3y>3t9c y3344//D4K4KBPTVY4Z\_``b*%hh>># " 0 5 5 ? ?I $R\\ 2I ##K#K K%((\R[(\%\"I-TS^1K,HH::%s9~s4y# #9#7#788   !hh& 00T5L5LRQUWZ5[]`a&  y--..s   4+L?c                (    | j                  |dd      S )z#Type check a list expression [...].r3  z<list>check_lst_exprr  s     r   visit_list_exprz!ExpressionChecker.visit_list_exprs  s    ""1ox@@r   c                (    | j                  |dd      S )Nr   z<set>r&  r  s     r   visit_set_exprz ExpressionChecker.visit_set_exprw  s    ""1ng>>r   c                   | j                   d   }|ry| j                  j                  |d      }|t        |t              r|S dS g }|j
                  D ]K  }t        |t              rt               | j                  |<    y|j                  | j                  |             M t        j                  |      }t        |      st               | j                  |<   y| j                  j                  ||g      }|| j                  |<   |S )aY  
        Fast path to determine the type of a list or set literal,
        based on the list of entries. This mostly impacts large
        module-level constant definitions.

        Limitations:
         - no active type context
         - no star expressions
         - the joined type of all entries must be an Instance or Tuple type
        r+  N)r  r  r  r   r   r   rd   r   r  rb  r   r  r   r  r>  )	r  r%  container_fullnamer-  rtr  r  vtcts	            r   fast_container_typez%ExpressionChecker.fast_container_typez  s     ###At,>#B12;t;GGD$)(0
""1%MM$++d+,    (+B/$,JDq!XX(();bTB "1	r   c                   | j                  ||      }|r|S t        ddt        dd      g | j                         t	        t
        j                              }t        |gt        j                  gd g| j                  j                  ||g      | j                  d      ||g      }| j                  ||j                  D cg c]   }t        |t               r|j"                  n|" c}|j                  D cg c]2  }t        |t               rt        j                  nt        j$                  4 c}|      d   }t'        |      S c c}w c c}w )	NTr+  z<lst>	namespacer  r  r  defaultr*  r6  r	  r   )r0  r   r   rC  r   r   from_omitted_genericsr   r   r5   r  r>  r3  r{  r   r   rd   r   r4   r!   )	r  r%  r   tagr   r  constructorrq  r  s	            r   r'  z ExpressionChecker.check_lst_expr  s/   $$Q1H w/((*I;;<
 #D^^FHH''2$7OO/0d
 ooABIA
1h/affQ6IUVU\U\]U\PQ
1h 7ennU]]JU\]	

  155	 J]s    %E
57Ec           	        t        |j                        }|Jt        |j                  D cg c]  }t        |t              r| c}      t        |j                        k  S t        |j                  D cg c]  }t        |t              s| c}      dk7  ryt        d t        |j                        D              }t        |j                        t        |j                        k(  xr ||k(  S c c}w c c}w )Nr   Fc              3  H   K   | ]  \  }}t        |t              s|  y wr   )r   rd   )r   rq  lvs      r   r   z:ExpressionChecker.tuple_context_matches.<locals>.<genexpr>  s"     `.CUQzRTV^G_q.Cr  )r   r   r~  r   rd   r  rQ  )r  r   r-  ctx_unpack_indexr%  expr_star_indexs         r   tuple_context_matchesz'ExpressionChecker.tuple_context_matches  s    .syy9# 4::M:aZ85L:MNRUVYV_V_R``` 4::A:aAx)@:ABaG`i

.C``4::#cii.0X5E5XX N Bs   C1C15C6C6c                R   t        | j                  d         }d}t        |t              rit	        |j
                        D cg c]6  }t        |t              r| j                  ||      st        |t              r|8 }}t        |      dk(  r|d   }n	 t        |t              r| j                  ||      r|j
                  }nV|rTt        |t              rDt        |t              sJ |j                  r&|j                  d   gt        |j
                        z  }d}|t        |      du}d}|xs& t        | j                  j                   j"                  v }g }	d}
t%        t        |j
                              D ]  }|j
                  |   }t        |t&              rh|r(|sJ ||
   }t        |t(              sJ |j*                  }nd}| j-                  |j.                  |      }t        |      }t        |t              rjt        |j
                        |r| j1                  |dd      c S d}|	j3                  |j
                         |r|
dz  }
|
t        |j
                        z  }
|r|st        |t              rr| j                  j5                  |      rW| j                  j7                  ||      }| j                  j9                  d|g      }|	j;                  t)        |             d}w| j1                  |dd      c S |r|
t        |      k\  r| j-                  |      }n| j-                  |||
         }|
dz  }
|	j;                  |        t=        t>        j@                        }t        |	| j                  j9                  d|g            }|rtC        |i       }|S c c}w )	zType check a tuple expression.r+  Nr   r   Fr  z<tuple>T)"r   r  r   r   r   r   r   r@  r   r   r~  r   rp  r   rt   r  r  r   r  rd   r   r   rb  r   r'  r5  r  r  r>  r  r   r   r0  r%   )r  r%  r  type_context_itemsr   tuples_in_contextunpack_in_contextseen_unpack_in_itemsallow_precise_tuplesr   r  rq  r  ctx_itemr-  ttrH  r  fallback_itemr&  s                       r   visit_tuple_exprz"ExpressionChecker.visit_tuple_expr  sh    't'8'8'<=!lI. *,*<*<=!=Aq),1K1KAq1Q$Q(AB =  ! $%*03 lI.43M3MaQ]3^!-!3!3/>WXlH555  &2&7&7&:%;c!''l%J" ") 34F Gt S$b!48H8H8b8b!b 	 s177|$A771:D$) %---1!4H%h
;;;"--CC[[C0$R(b),*2884@/ $(#6#6q:JI#VV370LL*(Q S]*+4H%b(38Q8QRT8U(,(C(CB(JI%)XX%@%@AQT]S^%_F!LLF);<370$  ..q2BINN)Q#6H2I-IT*BT+=a+@ABFAR i %l  	 6 67&488../?-Q
   ,FC!s   ;N$c                   | j                   d   }|ry| j                  j                  |d      }|t        |t              r|S dS g }g }d}|j
                  D ]  \  }}|t        | j                  |            }	t        |	t              rP|	j                  j                  dk(  r7t        |	j                        dk(  r|	j                  d   |	j                  d   f}t               | j                  |<    y|j                  | j                  |             |j                  | j                  |              t        j                  |      }
t        j                  |      }t!        |
      rt!        |      st               | j                  |<   y|r(|d   |
k7  s|d   |k7  rt               | j                  |<   y| j"                  j%                  d|
|g      }|| j                  |<   |S )a~  
        Fast path to determine the type of a dict literal,
        based on the list of entries. This mostly impacts large
        module-level constant definitions.

        Limitations:
         - no active type context
         - only supported star expressions are other dict instances
         - the joined types of all keys and values must be Instance or Tuple types
        r+  Nr6  r  r   r   )r  r  r  r   r   r   r   rb  r   r   r~  rp  r   r  r   r  r   r  r>  )r  r%  r-  r-  r  r  stargsr  r  stktr.  dts                r   fast_dict_typez ExpressionChecker.fast_dict_type5  s    ###At,>#B12;t;+/''JC{$T[[%78r8,((O;BGG) ggaj"''!*5F,4JD&&q)DKK,-dkk%01 "   &  (,R05QRT5U$,JDq!vayB&)r/$,JDq!XX((2r(C "1	r   c                    | j                  ||j                  |d       }t        |      }t        |t              r|j                         S |j                         S )N)rz  r  rN  r  )r  r   r   r   r   r  )r  r%  typeddict_contextr(  r:  s        r   "check_typeddict_literal_in_contextz4ExpressionChecker.check_typeddict_literal_in_contextd  sZ     ;;$QWWaT < 
 #=1h.))++ ..00r   c           
        | j                  | j                  d   |      }|rt        |      dk(  r| j                  ||d         S |D ]  }| j                  j                         5 }| j                  j                         5 }| j                  ||      }ddd       ddd       j                         rl| j                  j                         c S  | j                  j                  ||       | j                  |      }|r|S t        ddt        dd      g | j                         t        t         j"                              }t        d	d	t        d
d      g | j                         t        t         j"                              }	g }
g }|j$                  D ]  \  }}|?|
j'                  |       |j'                  | j                  j)                  d||	g             Ht+        ||g      }|j,                  dk\  r#|j,                  |_        |j.                  |_        n"|j,                  |_        |j.                  |_        |j0                  |_        |j2                  |_        |
j'                  |       |j'                  t5        ||	g| j7                  d                   
 t9        |t:        j<                  gt        |      z  dgt        |      z  | j                  j)                  d||	g      | j7                  d      d||	g      }| j?                  ||
t:        j<                  gt        |
      z  |      d   S # 1 sw Y   xY w# 1 sw Y   xY w)zoType check a dict expression.

        Translate it into a call to dict(), with provisions for **expr.
        r+  r   r   NKT<dict>r3  r5  VTr<  r  r6  r*  r7  ) find_typeddict_contextr  r~  rS  r  r   r  r!  r|  r  typeddict_context_ambiguousrP  r   r   rC  r   r   r8  r   r  r>  ri   r;  r<  end_line
end_columnr   r3  r   r   r4   r{  )r  r%  typeddict_contextsrR  r  tmapr:  rO  rN  r.  rp  r  r  r  tupr:  s                   r   visit_dict_exprz!ExpressionChecker.visit_dict_expro  s    "889J9J29NPQR%&!+>>qBTUVBWXX%7!XX++-dhh6M6M6OSW#FFqJ[\H 7P-%%'$$T* &8 HH001CQG   #I x0((*I;;<
 x0((*I;;<
 "$%'''JC{E"%%HH//0RUWY[T\]  e-88q="xxCH!$CJ$zzCH!&CJ$~~!&!1!1C %%iR$//JZ:[&\]# "* #]]Oc.11FS((HH''"bBOO/02h
 {D5==/CI2MqQRSTTC 7P6O--s$   $M?L:M:M?MM	c                   t        |      }t        |t              r|gS t        |t              r]g }|j                  D ]J  }| j                  ||      }|D ]1  }| j                  ||j                  |      s!|j                  |       3 L |S g S r   )r   r   r   r   r   rY  r  r  )r  rN  	dict_exprr   r  item_contextsitem_contexts          r   rY  z(ExpressionChecker.find_typeddict_context  s     "'*g}-9+E $ ; ;D) L$1L::$iooy \2	 %2 & L	r   c                   | j                   j                  |d       | j                  |      \  }}|s6| j                   j                  j	                  t        t        j                               | j                   j                  j                  dd      5  | j                   j                  j                  |      5  |j                  j                  dd D ]  }|j                  | j                           | j                  |j                         d      }ddd       ddd       | j                  d	      }| j                   j                  j!                          t#        ||      S | j                   j                  j	                  |j$                         | j                   j&                  j)                  |      5  | j                   j+                  ||
       ddd       | j                   j-                  |j                               sQ| j                   j                  j                  dd      5  | j                  |j                         d       ddd       | j                   j/                  |j                               }| j                   j                  j!                          t1        ||      S # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)zType check lambda expression.F)body_is_trivialTr   can_skipfall_throughNr+  r]  r*  )type_override)r  check_default_argsinfer_lambda_type_using_contextr  r  r   r   r0  r  frame_contextr/  push_functionbodyrb  r   r3  popr   r:  tscopefunction_scopecheck_func_itemr  r  replace_callable_return_type)r  r%  r  rj  stmtr:  rs  s          r   visit_lambda_exprz#ExpressionChecker.visit_lambda_expr  s   ##Au#='+'K'KA'N$}HH!!((1G1G)HI ..A / xx~~++A. FFKK,DKK) -  ;;qvvx4;H / ':;HHH!!%%' Hh77 HH!!(()?)?@//2((-(H 388$$QVVX.XX__22Dq2QKKDKA Rxx++AFFH5HHH!!%%'/xHH/ /. " 32 RQs=   &K>AJ8K?K5"K8K	=KKKK'c                   t        | j                  d         }t        |t              rJt	        |j                               D cg c]  }t        |t              s| }}t        |      dk(  r|d   }|rt        |t              sy| j                  j                  j                  sg }|j                  D ]Y  }t        |      D cg c]  }|j                  j                         s|! }}|j                  |D cg c]	  }||vs| c}       [ |j!                  t#        |j$                  t'                     t)        |j*                        |z         }	n8t#        |t'                     }
t        |
t,              rt        |
t              sJ |
}	|	j!                  | j/                  d            }	|	j0                  |	j2                  y|j4                  D cg c]  }|j6                   }}|	j8                  s|j;                         Q|	j!                  d	t=        t>        j@                        gt        |      z  ||jB                  jE                         
      }	tF        |v stH        |v r|	dfS |	jJ                  |k7  r+| j                  jM                  tN        jP                  |       y|	j!                  |jB                        |	fS c c}w c c}w c c}w c c}w )zTry to infer lambda expression type using context.

        Return None if could not infer type.
        The second item in the return type is the type_override parameter for check_func_item.
        r+  r   r   NN)r:  r	  r*  r  NF)is_ellipsis_argsr  r|  r}  )r}  ))r   r  r   r   r   r  r   r~  r  r  r  r  r   r  is_meta_varr5  r  r"   r:  r   r  r	  r   r3  r  r  	argumentsr,  ry  r  r   r   r0  r}  r  r5   r6   r|  r  r   CANNOT_INFER_LAMBDA_TYPE)r  r%  r-  r   r  
extra_varsr  r  	meta_varscallable_ctxr  r|  s               r   rl  z1ExpressionChecker.infer_lambda_type_using_context  s    d//34c9%+C,>,>,@AAaZPQS_E`A   9~"l*S,7 xx22 J}}*;C*@X*@BBEEDUDUDWR*@	X!!	"R	"Rz=Q2	"RS % ,,*3<<Fs}}-
: - L
 +3
=Jj*5*ZQ]:^^^%L $114??K^;_1`"".,2F2F2R )*5#SXX	5((CNN,<,H'55!&"9#9#9:;c)nL#++**,	 6 L y I$:%%!!Y.HHMM*CCQG ))AKK)@,NN( Y"R( 6s*   KKK	$K	9	K
K
Kc                   | j                  |      }t        |t              r|\  }}n|S t        |      }|C| j                  j                  t        j                  |       t        t        j                        S t        |      }|C| j                  j                  t        j                  |       t        t        j                        S |j                  }d}||v r|j                  |      }n| j                  j                  j                         }	|	bt!        ||	j"                        rK|j$                  r?||j$                  j                  v r'|j$                  j                  }|j                  |      }|c|j&                  r||k7  r|j&                  sd}nC| j                  j                  t        j(                  |       t        t        j                        S t+        |      |dz   k(  rC| j                  j                  t        j,                  |       t        t        j                        S ||dz   d D ]  }
|j.                  |
j0                  v s	|
|d   k(  s$|j$                  r9|j$                  j2                  r#|
|d   k(  rt        t        j4                        c S t7        |j.                  |ddd||
|| j8                  | j                  | j;                               c S  J d       )	z+Type check a super expression (non-lvalue).N)is_classmethodr+  r   FT)r6  r[  r  r  r  r  override_inforN  r  r  r  r  )_super_arg_typesr   r  type_info_from_typer  r  r   UNSUPPORTED_ARG_1_FOR_SUPERr   r   r7  UNSUPPORTED_ARG_2_FOR_SUPERr  r;  r/  top_functionr   is_classr  r  !SUPER_ARG_2_NOT_INSTANCE_OF_ARG_1r~  TARGET_CLASS_HAS_NO_BASE_CLASSr6  rS  r  r0  r   r  rJ  )r  r%  r   	type_typeinstance_type	type_infoinstance_infor  r;  r  rf  s              r   visit_super_exprz"ExpressionChecker.visit_super_exprD  sf    %%a(eU#',$I}L (	2	HHMM*FFJ9//00+M: HHMM*FFJ9//00 IIi(EXX^^002F !&7foo' 66i166::5&&**CIIi0E=))!Y.!--
 .PPRSTy3344s8uqy HHMM*II1M9//00	$Dvv#ts2w66aff44R #9#9#9::,%#! %"/"&'+'>'>'@  %* 	$m#ur   c                "   | j                   j                         st        t        j                        S t        |j                  j                        dk(  rL|j                  st        t        j                        S | j                   j                  j                         rC| j                   j                  t        j                  |       t        t        j                        S t        |j                        }t!        |      }| j                   j                  j#                         }|J |j$                  r)|j$                  d   j&                  j(                  xs |}n0| j                   j                  t        j*                  |       t        t        j                        S t,        |j                  j.                  v rC| j                   j                  t        j0                  |       t        t        j                        S t3        |j                  j.                        t4        hk7  rC| j                   j                  t        j6                  |       t        t        j                        S t        |j                  j                        dk(  rC| j                   j                  t        j8                  |       t        t        j                        S t        |j                  j                        dk(  rZt;        | j=                  |j                  j                  d               }| j=                  |j                  j                  d         }nC| j                   j                  t        j>                  |       t        t        j                        S tA        |t              rF|j                  rt!        t        |j                              }nt        t        jB                  |      S tA        |t               rb|jD                  }tA        |t              rF|j                  rt!        t        |j                              }nt        t        jB                  |      S tA        |t               sUtA        |tF              r|jI                         s5| jJ                  jM                  ||       t        t        j                        S t;        |      }tA        |t              r@|j                  rt        |j                        }||fS t        t        jB                  |      S tA        |t               re|jD                  }tA        |t              rI|j                  r"t!        t        |j                              }||fS t        t        jB                  |      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   r   r  r  )'r  r4  r   r   r   r~  callrp  r  r7  r/  active_classr  r   %SUPER_OUTSIDE_OF_METHOD_NOT_SUPPORTEDr   r   r  r{  variabler   (SUPER_ENCLOSING_POSITIONAL_ARGS_REQUIREDr5   r|  SUPER_VARARGS_NOT_SUPPORTEDr   r4   SUPER_POSITIONAL_ARGS_REQUIRED#SUPER_WITH_SINGLE_ARG_NOT_SUPPORTEDr   rb  TOO_MANY_ARGS_FOR_SUPERr   r  r  r   r  r  %first_argument_for_super_must_be_type)r  r%  current_typer  r  r  	type_iteminstance_items           r   r  z"ExpressionChecker._super_arg_types  s    xx++-90011"66y3344,,..TTVWXy3344 )0L$,\$:I XX^^002F%%%&,&6&6q&9&B&B&G&G&W<.WWYZ[y3344)))HHMM*FFJ9//00!!"wi/HHMM*II1M9//00"HHMM*NNPQR9//00"'AFFKKN(CDI KKA7MHHMM*BBAF9//00 i)vv$]166%:;	y99iPP	8,!I)W-66 (qvv)> ?I"9#=#=)TT)X.y,/I4I4I4KHH::9aH9//00 (6mW-vv -aff 5 -'' y99mTTx0)..M-166$,]166-B$CM -'' #9#=#=-XX-''r   c                   	 | j                   j                  d      }t        |      }g }|j                  |j
                  |j                  fD ]l  }|rO| j                  |      }| j                   j                  |||t        j                         |j                  |       T|j                  t                      n | j                   j                  d|      S # t        $ r | j                   j                  d      }Y w xY w)Nztyping_extensions.SupportsIndexr  zbuiltins.slice)r  r3  rR  r   r  r  r  rb  r  r   INVALID_SLICE_INDEXr  r   r>  )r  r%  supports_indexexpected	type_argsr;  r   s          r   visit_slice_exprz"ExpressionChecker.visit_slice_expr  s    	A!XX001RSN &n5	mmQ[[!((;EKK&&&q(E;K;_;_`  #  , < xx**+;YGG  	A!XX00@N	As   C $C?>C?c                <    | j                  |j                  dd      S )Nr3  z<list-comprehension> check_generator_or_comprehension	generatorr  s     r   visit_list_comprehensionz*ExpressionChecker.visit_list_comprehension  s!    44KK*@
 	
r   c                <    | j                  |j                  dd      S )Nr   z<set-comprehension>r  r  s     r   visit_set_comprehensionz)ExpressionChecker.visit_set_comprehension  s!    44KK)>
 	
r   c                >   t        |j                        sPt        |j                        s;t        d |j                  dd  D              st        d |j
                  D              rd}t               g}nd}t               t               g}| j                  ||d|      S )Nc              3  2   K   | ]  }t        |        y wr   r   )r   sequences     r   r   z9ExpressionChecker.visit_generator_expr.<locals>.<genexpr>
  s     R/h'1/r   r   c              3  @   K   | ]  }|D ]  }t        |         y wr   r   )r   condlistconds      r   r   z9ExpressionChecker.visit_generator_expr.<locals>.<genexpr>  s"     _k(V^d'-V^-ks   ztyping.AsyncGeneratortyping.Generatorz<generator>)additional_args)r  is_asyncr   rU  	sequences	condlistsr   r  )r  r%  r[  r  s       r   visit_generator_exprz&ExpressionChecker.visit_generator_expr  s     

O#AKK0R!++ab/RR_akk__)C+3:,O$C'z8:6O44sM? 5 
 	
r   c                F   |xs g }| j                   j                  j                  dd      5  | j                  |       t	        ddt        dd      g | j                         t        t        j                              }|g}t        |t        j                  gd	g| j                   j                  |||z         | j                   j                  d
      ||g      }| j                  ||j                   gt        j                  g|      d   cd	d	d	       S # 1 sw Y   y	xY w)z:Type check a generator expression or a list comprehension.Tr   rg  r2  r+  z<genexp>r3  r5  Nr*  r7  )r  r  rm  check_for_compr   r   rC  r   r   r8  r   r   r4   r>  r3  r{  rU  )r  genr  id_for_messagesr  r  tv_listr:  s           r   r  z2ExpressionChecker.check_generator_or_comprehension  s     */RXX__**Dq*I$ R:6 ,,.	 ? ?@B $&$G&++Iw7PQ##$78$$K ??;%--RUVWXY/ JIIs   CDD c                   | j                   j                  j                  dd      5  | j                  |       t	        ddt        dd      g | j                         t        t        j                              }t	        d	d	t        d
d      g | j                         t        t        j                              }t        ||gt        j                  t        j                  gddg| j                   j                  d||g      | j                   j                  d      d||g      }| j                  ||j                   |j"                  gt        j                  t        j                  g|      d   cddd       S # 1 sw Y   yxY w)z&Type check a dictionary comprehension.Tr   rg  rU  r+  rV  r3  r5  rW  rX  Nr6  r*  z<dictionary-comprehension>r7  )r  r  rm  r  r   r   rC  r   r   r8  r   r   r4   r>  r3  r{  r  r  )r  r%  ktdefvtdefr:  s        r   visit_dictionary_comprehensionz0ExpressionChecker.visit_dictionary_comprehension:  sB   XX__**Dq*I"  R84 ,,.	 ? ?@E  R84 ,,.	 ? ?@E '.t++OeU^L##$781 %.K ??aeeQWW-u}}/Mq= JIIs   E	E;;Fc                   t        |j                  |j                  |j                  |j                        D ]'  \  }}}}|r| j
                  j                  |      \  }}n| j
                  j                  |      \  }}| j
                  j                  ||d|       |D ]  }| j                  |       | j
                  j                  |      \  }	}
|	r| j
                  j                  |	       t        j                  | j
                  j                  j                  v s|	| j                   j#                  d|       |
| j                   j#                  d|        * y)zCheck the for_comp part of comprehensions. That is the part from 'for':
        ... for x in y if z

        Note: This adds the type information derived from the condlists to the current binder.
        TNF)r  indicesr  r  r  r   analyze_async_iterable_item_typeanalyze_iterable_item_typeanalyze_index_variablesrb  rs  push_type_mapr  rt  r  ru  r  $redundant_condition_in_comprehension)r  r%  r;  r  
conditionsr  r  sequence_type	conditiontrue_map	false_maps              r   r  z ExpressionChecker.check_for_comp^  s    69IIq{{AKK6
1E8Z #'88#L#LX#V =#'88#F#Fx#P =HH,,UM4K'	I& '+hh&D&DY&O#)HH**84''488+;+;+O+OO'EEeYW"*EEdIV (6
r   c                   | j                  |j                         | j                  d   }| j                  j	                  |j                        \  }}t
        j                  | j                  j                  j                  v rQ|'| j                  j                  d|j                         n(|&| j                  j                  d|j                         | j                  ||j                  ||      }t        t        |            xs |}| j                  ||j                  ||      }t         j"                  j%                  |      sH|}	t        t        |	            xs |	}
|t'        |
|      sG| j                  ||j                  |
|      }n'||k(  r|}	n| j                  ||j                  ||      }	t)        |      rt)        |	      s|}	t+        ||	g      }t-        |      rrt/        t        | j                  d         t0              sLt3        j4                  ||	      }t        |      }t/        |t6              r|j8                  j:                  dk7  r|}|S )Nr+  FT)rN  r^  rQ  )rb  r  r  r  rs  r  rt  r  ru  r  redundant_condition_in_ifry  if_exprr   r   	else_exprr  r  r=  r}   r   r   r  r   r   r   r'  r   r   r   )r  r%  r^  r-  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)   AFF#  8899!&&A488#3#3#G#GG~225!&&A!224@**AIIs>O + 
 /w/GHSG "&!9!9akk3BS ": "
 ||227;.I "5_Y5O!P!]T] {-0BC"H 22II.&7	 3  $ /I 00("3	 1 I   67@TU^@_.I)7I*>?$S)*D--b12I3
 //'9=K#K0EeX.%**2E2EIZ2Z!
r   c                ,   | j                   j                  j                  dd      5  |'| j                  |||       t	               cd d d        S | j                   j                  |       | j                  |||      cd d d        S # 1 sw Y   y xY w)NTr   rg  r  )r  r  rm  rb  r   r  )r  r  r   rN  r^  s        r   ry  z%ExpressionChecker.analyze_cond_branch  s|     XX__**Dq*I{ DwJ[\&( JI HH""3';;t'M^;_ JIIs    B
.B

Bc                    || j                   v r| j                   |   S d}| j                  r)| j                  st        j                         }d| _        d}| j
                  j                  |       | j                  }|| _        	 |r$t        |t              r| j                  |d      }	n|r$t        |t              r| j                  |d      }	n]|r$t        |t              r| j                  |d      }	n7|r$t        |t              r| j!                  |d      }	n|j#                  |       }	|| _        | j
                  j3                          	J | j(                  j5                  ||	       | j(                  j0                  j6                  ro|sm| j(                  j8                  sW| j(                  j;                         r=t=        |	      r2| j(                  j>                  s| j@                  jC                  |	|       | j(                  j;                         r| j(                  j>                  rtE        tF        jH                        }n|	}|r=| jJ                  |j.                  xx   t        j                         z
  z  cc<   d| _        |S # t$        $ rj}
t'        |
| j(                  j*                  j,                  |j.                  | j(                  j*                  | j(                  j0                         Y d}
~
d}
~
ww xY w)zType check a node in the given type context.  If allow_none_return
        is True and this expression is a call, allow it to return None.  This
        applies only to this expression and not any subexpressions.
        FTr]  N)&r  r  r  timeperf_counter_nsr  r  r  r   rA   rc  rs   visit_yield_from_exprrE   r  r?   visit_await_exprrb  	Exceptionr$   r  r&  filer;  r  rp  r  disallow_any_expris_stubr4  r  rI  r  disallowed_any_typer   r   r   r  )r  r   r  r^  rt  r  record_timet0old_is_calleer[  r  r&  s               r   rb  zExpressionChecker.accept  s^    4&&&&&t,,++D4F4F%%'B!%DK  ."	 Zh%?**44*H"z$'F000N"z$'H11$$1O"z$	'B++DD+Ikk$'
 'D#& HH..$HH$$,,.S!HH22HH((d3xx++-1O1O"9#8#89FF**49959M9M9ORT9TT5!&D5  	!TXX__))499dhhootxxGWGW 	s   B)J
 
	K=AK88K=c                8    | j                   j                  |      S )z}Return an instance type with type given by the name and no type
        arguments. Alias for TypeChecker.named_type.
        )r  r3  )r  r6  s     r   r3  zExpressionChecker.named_type  s     xx""4((r   c                    | j                   j                  j                  dk\  r| j                  d      S | j                  d      S )zFReturns a `typing.TypeAliasType` or `typing_extensions.TypeAliasType`.)r     ztyping.TypeAliasTypeztyping_extensions.TypeAliasType)r  r  r  r3  r  s    r   r  z&ExpressionChecker.type_alias_type_type%  s:    88**g5??#9::@AAr   c           	         t        |      }t        |t        t        t        t
        f      xs> t        || j                  j                  dt        t        j                        g            S )z$Is a type valid as a *args argument?r  )r   r   r   r   r   r   r   r  r>  r   r0  r  s     r   r?  z"ExpressionChecker.is_valid_var_arg+  sW    c"#	7M:NO 
S],,->I_I_A`@abT
 	
r   c           
     6   t        || j                  j                  d| j                  d      t	        t
        j                        g            xsJ t        || j                  j                  dt               t               g            xs t        |t              S )z'Is a type valid as a **kwargs argument?r<  r  )
r   r  r>  r3  r   r   r0  r   r   r   r  s     r   rA  z*ExpressionChecker.is_valid_keyword_var_arg2  s     ++6__^4gi>T>T6UV . ++69JOL]8^. #}-	
r   c                    t        |      }t        |t              rt        |j                        }t        |t              rt        |      }t        |t              r|j                  }t        |t              r|j                  j                        S t        |t              r5|j                         r%|j                  j                  j                        S t        |t              ryt        |t              r%t         fd|j!                         D              }|S t        |t"              r|j$                  }t        |t              rt        |j                        }t        |t              rt        |      }t        |t              r<|j                  j&                  & j)                  |j                  j&                        S t        |t              ryyy)z*Does type have member with the given name?Tc              3  B   K   | ]  }j                  |        y wr   )rK  )r   xr  r  s     r   r   z/ExpressionChecker.has_member.<locals>.<genexpr>Z  s     R=QF3=Qs   F)r   r   r   r  r   r   r   rs  r   r   has_readable_memberr   r  r   r   r   r  r   r  metaclass_typerK  )r  r[  r  r&  r  s   ` `  r   rK  zExpressionChecker.has_memberE  sZ    c"c;'!#//2Cc9% %Cc;',,Cc8$88//77c<(S__-><<$$88@@W%Y'RS=O=O=QRRFMX& 88D$,&t'7'78$	*%d+$)dii.F.F.Rtyy'?'?HH$(r   c                <    | j                   j                  ||       y)zCalled when we can't infer the type of a variable because it's not ready yet.

        Either defer type checking of the enclosing function to the next
        pass or report an error.
        N)r  r5  )r  r6  rN  s      r   not_ready_callbackz$ExpressionChecker.not_ready_callbackl  s     	--dG<r   c                   | j                   j                  d   }| j                   j                  |d      }|j                  dt	        t        |      t        t        f      s| j                   j                         ru| j                   j                  t        j                  |       nJ| j                  |j                  |      }| j                   j                  |||t        j                  dd       | j                   j                  |d      S )Nr+  Factual typeexpected type)r  r  get_generator_yield_typer   r   r   r   r   r4  r  r   YIELD_VALUE_EXPECTEDrb  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_exprt  s    hh++B/!XX>>{ER66>/ABXwDWXHH002.CCQG#{{1663EFHH"" " << xx22;FFr   c                   | j                   d   }|| j                  j                  d|g      }t        | j	                  |j
                  |            }t        |t              rt        t        j                  |      S | j                  ||t        j                        }|s?t        t        |      t              r&| j                  j                  j                  d |       |S )Nr+  typing.Awaitabler  )r  r  r>  r   rb  r   r   r   r   r  check_awaitable_exprr   INCOMPATIBLE_TYPES_IN_AWAITr   r  r  )r  r%  r^  expected_typer5  r?  s         r   r  z"ExpressionChecker.visit_await_expr  s    ))"-$ HH778J]O\M%dkk!&&-&HIk7+955+NN'',HH
 !Z0Dh%OHHLL..tQ7
r   c                   | j                   j                  || j                  d      ||dd      st        t        j
                        S | j                  d|g g |      d   }| j                   j                  |d      }t        |      }|s@t        |t              r0|j                  s$| j                   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  r3  r   r   r0  r  get_generator_return_typer   r   r   r  r  r  )r  r   r-  r  ignore_binderr  r:  s          r   r  z&ExpressionChecker.check_awaitable_expr  s     xx%%t12Cm_
 9112266{Ar2sSTUVIxx99)UKH&x0H!x9 **++-Or   c                   | j                   j                  d   }t        | j                  |j                              }t        |t              rt        t        j                  |      }n | j                   j                  |      rt        |      r1t        |      s&| j                   j                  j                  ||       t        t        j                        }| j                   j                  d|||g      }| j!                  d|g g |      \  }}nwt        |      rt        |      s@| j                   j                  j                  ||       t        t        j"                        }n!| j%                  ||t&        j(                        }| j                   j+                  |d      }	| j                   j+                  |d      }
| j                   j-                  |
|	|t&        j(                  dd       t        |      }| j                   j/                  |d	      }|s?t        t        |      t0              r&| j                   j                  j3                  d |       |S )
Nr+  r  r  __iter__r  Fr  r  )is_coroutine)r  r  r   rb  r   r   r   r   r  r  is_async_defhas_coroutine_decoratorr  yield_from_invalid_operand_typer0  r>  r  r7  r  r    INCOMPATIBLE_TYPES_IN_YIELD_FROMr  r  r  r   r  )r  r%  r^  r  subexpr_type	iter_typerW  generic_generator_typer  r  r  	expr_types               r   r  z'ExpressionChecker.visit_yield_from_expr  s    hh++B/
 't{{166':; lG,%i&@&@\ZIXX&&|4L)2I+2V<<\1My556H%)XX%@%@"Xx$B&"  99L"b:P : LIq !.3J;3W<<\1M#I$8$89	 55 !%5%V%V	 "XX>>{ER88<<YN==	
 $I.	HH66yu6U	 Z	0JH%UHHLL..tQ7r   c                    |j                   S r   r   r  s     r   visit_temp_nodez!ExpressionChecker.visit_temp_node      vvr   c                   t        |j                        t        t              rj                  t
        j                  k(  sxt        |j                        s| j                  j                  d|       |j                  r:t        fd|j                  D              s| j                  j                  d|       t        t
        j                        S )Nz3TypeVar default must be a subtype of the bound typec              3  (   K   | ]	  }|k(    y wr   r   )r   r  	p_defaults     r   r   z8ExpressionChecker.visit_type_var_expr.<locals>.<genexpr>  s     #MH5I$6Hs   z3TypeVar default must be one of the constraint types)r   r6  r   r   type_of_anyr   r8  r   r  r  r  r  r  r0  )r  r%  r  s     @r   visit_type_var_exprz%ExpressionChecker.visit_type_var_expr  s    #AII.	y'*%%)H)HHi7SUVWxx#MAHH#M MSUVWy--..r   c                4    t        t        j                        S r   r   r   r0  r  s     r   visit_paramspec_exprz&ExpressionChecker.visit_paramspec_expr      y--..r   c                4    t        t        j                        S r   r  r  s     r   visit_type_var_tuple_exprz+ExpressionChecker.visit_type_var_tuple_expr  r  r   c                4    t        t        j                        S r   r  r  s     r   visit_newtype_exprz$ExpressionChecker.visit_newtype_expr  r  r   c                x   |j                   j                  }|r| j                  j                  j                  r(t        |      r| j                  j                  d||       t        || j                  j                  | j                  j                  | j                  |       t        t        j                        S )NzNamedTuple typer  )r  
tuple_typer  r  r  r   r  r  r   r  r   r   r0  )r  r%  r%  s      r   visit_namedtuple_exprz'ExpressionChecker.visit_namedtuple_expr  s    VV&&
xx77<X= 445F
TUV"DHH,,dhh.G.G[\ y--..r   c                d   t        |j                  |j                        D ]u  \  }}|	| j                  |      }t	        t        |      t              r4|j                  j                  |   j                  }t	        |t              sh||_        d|_        w t        t        j                        S NT)r  r   r  rb  r   r   r   r  rS  r   rq   r   r  r   r0  )r  r%  r6  r  r[  r@  s         r   visit_enum_call_exprz&ExpressionChecker.visit_enum_call_expr  s    qww1KD% kk%(!/#"6@&&,,t,11C!#s+
 $'*. 2 y--..r   c                4    t        t        j                        S r   r  r  s     r   visit_typeddict_exprz&ExpressionChecker.visit_typeddict_expr  r  r   c                    |j                   S r   r  r  s     r   visit__promote_exprz%ExpressionChecker.visit__promote_expr  r  r   c                8    | j                  |j                        S r   )rb  r   r  s     r   visit_star_exprz!ExpressionChecker.visit_star_expr"  s    {{166""r   c                $    | j                  d      S )zReturn instance type 'object'.rQ  r  r  s    r   rC  zExpressionChecker.object_type&  s    011r   c                $    | j                  d      S )zReturn instance type 'bool'.rI  r  r  s    r   r  zExpressionChecker.bool_type*  s    //r   c                     y r   r   )r  r   
known_types      r   r#  z)ExpressionChecker.narrow_type_from_binder.  s    SVr   c                     y r   r   )r  r   r3  r  s       r   r#  z)ExpressionChecker.narrow_type_from_binder1  s     r   c                   t        |      t        k\  rs| j                  j                  j	                  |      }|rLt        t        |      t              r| j                  j                  s|rt        ||d      syt        ||      S |S )zNarrow down a known type of expression using information in conditional type binder.

        If 'skip_non_overlapping' is True, return None if the type and restriction are
        non-overlapping.
        T)prohibit_none_typevar_overlapN)r,   r9   r  r  r  r   r   r   rI  r.   r/   )r  r   r3  r  restrictions        r   r#  z)ExpressionChecker.narrow_type_from_binder6  st     4=L(((//--d3K ?:6@TXXEcEc (0D41  +JDDr   c                     t        |t              rBt        |t              r2t         fdt        |j                  |j                        D              S  j                  ||      S )Nc              3  l   K   | ]+  \  }}j                  t        |      t        |             - y wr   )has_abstract_typer   )r   callerrz  r  s      r   r   z;ExpressionChecker.has_abstract_type_part.<locals>.<genexpr>Q  s5      &ONFF &&v'>PV@WX&Os   14)r   r   r  r  r   r:  r  r]  r  s   `  r   rW  z(ExpressionChecker.has_abstract_type_partN  sX    k9-*[)2T &)+*;*;[=N=N&O   %%k;??r   c                   t        |t              xr t        |t              xr |j                         xr |j	                         j
                  xs |j	                         j                  xrw t        |j                  t              xr[ |j                  j                  j
                  xs  |j                  j                  j                  xr | 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_typeW  s    {L1 1;11'')1 ((*66_+:Q:Q:S:_:_1 ;++X6	1
 !!&&22Wk6F6F6K6K6W6W1 HH000	
r   )
r  r
  r  r1   r  ry   r  dict[int, int]r  r  r  r  )r%  rX   r  r   F)r%  r_   rD  r  r  r   )r@  rq   rN  rF   r  r   )r   rV   r  r   )r%  rA   r^  r  r  r   )rf  rL   r  r  )r%  rA   r  r  )rC  r   r  r  r  rQ  r   rL   r  r  )r  zSymbolNode | Noner  r  )rz  r   r|  list[ArgKind]r}  zSequence[str | None]rp  list[Expression]rN  rF   r  r  r  r   )r  z.Iterable[tuple[Expression | None, Expression]]rz  r   r  z3tuple[dict[str, list[Expression]], set[str]] | None)
r  rL   rz  r   r&  dict[str, list[Expression]]r  set[str]r  r  r[  r   r  r  )rz  r   r  *list[tuple[Expression | None, Expression]]rN  rF   r  r  )
rz  r   r  rH  rN  rF   r  r  r  r   )r  rm   r  r   )rz  r   r  r   )rz  r   r  rE  rN  rF   r  r  r  rF  r  r   )r   rU   r  z
Var | None)rE  r_   r  z%tuple[Var, dict[Var, Context]] | None)r%  rA   rJ  r  r@  rq   r  zInstance | None)rz  r   r|  rC  r  
list[Type]r}  Sequence[str | None] | Noner  list[list[int]]rp  rD  r   r  rC  r  rN  rF   r  r   )rz  r   rp  rD  r|  rC  r}  rJ  re  z>Callable[[list[list[Expression]], CallableType], FunctionLike]r  r   )rz  r   rp  rD  r|  rC  rN  rF   r}  rJ  rj  z,Callable[[FunctionSigContext], FunctionLike]r  r   )rz  r   rp  rD  r|  rC  rN  rF   r}  rJ  rC  r   rj  z*Callable[[MethodSigContext], FunctionLike]r  r   rx  )rs  rQ  rz  r   rp  rD  r|  rC  rN  rF   r}  rJ  rC  r  r  r   )r  r   rp  rD  r  zOverloaded | None)r  r   r}  r   r-  rF   r  tuple[Type, Type] | Noner   )r  r   r%  rA   rs  rQ  rC  r  r  rQ  r  r   )r%  rA   rC  r   r  r  r  r   )NNNNN)rz  r   rp  rD  r|  rC  rN  rF   r}  rJ  r  Expression | Noners  rQ  rC  r  r  r  r  tuple[Type, Type])rz  r   rp  rD  r|  rC  rN  rF   r}  rJ  r  rM  rs  rQ  rC  r  r  rN  )r   rm   r  r  r  r  )r  r   rN  rF   r  r   )rp  rD  r  rI  )r  r   r  r  )
rz  r   rp  rD  r|  rC  r  rK  r  rI  )r  r   r  rF   r  r   )r  r   rp  rD  r|  rC  r}  rJ  r  rK  r  r  rN  rF   r  r   )r  r   rp  rD  r|  rC  r}  rJ  r  rK  r  Sequence[Type | None]r  r  rN  rF   r  z&tuple[CallableType, list[Type | None]])r  r)   )rz  r   rp  rD  r  rI  r  rK  r  r  r  	list[int])r  r   r~  rO  rN  rF   r  r   )rz  r   r&  rI  r'  rC  r(  rJ  r  rK  rN  zContext | NonerC  r  rs  rQ  r  r  )rz  r   r&  rI  r'  rC  r(  rJ  r)  r?  rN  rF   r  ztuple[bool, bool])rC  r   rs  r  rN  rF   r  r  )r  rI  r|  rC  rp  rD  rz  r   r  rK  rN  rF   r>  zArgChecker | NonerC  r  r  r  )r]  r   r^  r   r_  r<   r  r   rZ  r  r`  r  rz  r   rC  r  rN  rF   rU  rF   r  r  )rz  r   rp  rD  r|  rC  r}  rJ  rs  rQ  rC  r  rN  rF   r  rN  )
r  rI  r|  rC  r}  rJ  r   r   r  r  )ro  r  rp  rD  r  rI  r|  rC  r}  rJ  rs  rQ  rC  r  rN  rF   r  rL  )ro  r  r  rI  r|  rC  r}  rJ  rp  rD  rN  rF   r  r  )r  rI  ro  r  r  r  )r   )ro  r  rp  rD  r  rI  r|  rC  r}  rJ  rs  rQ  rC  r  rr  r  rN  rF   r  r  r  zlist[tuple[Type, Type]] | Noner~  )r  zSequence[Expression]r  Sequence[Type]r  zIterator[None])r   zlist[ProperType]r  zAnyType | CallableType)r  rI  r|  rC  r}  rJ  rp  rD  rz  r   rN  rF   r  r  )
r  r   r   rO  rN  rF   r  r  r  r   )rp  rD  rz  r   r  rN  )rz  r   rp  rD  r|  rC  r}  rJ  rN  rF   r  rN  )r%  rU   r  r  r  r   )r  r  r  r   rN  rF   r  r   )r  r  )r  r   r  r  r  r   )r  r   r  r   r  r   )r%  rQ   r  r   )r%  re   r  r   )r%  r@   r  r   )r%  rM   r  r   )r%  rD   r  r   )r%  rJ   r  r   )r%  rZ   r  r   )r%  rC   r  r   )r   rL   r  r  )r  r   r  r   r  r  r7  zset[tuple[Type, Type]] | Noner  r  r  r  )r  r  r  r   rp  rD  r|  rC  rN  rF   r  r  r  rN  )r  r  r  r   rp  rD  r|  rC  rN  rF   r  r  r  rN  )r  r  r  r   r  r   rp  rD  r|  rC  rN  rF   r  rN  )rL  r  r  r   rU  rL   r)  r   rV  rL   rN  rF   r  rN  )r  r  r  r   r  rL   rN  rF   r  r  r  rN  )r%  rZ   rN  rF   r  r   )r%  r>   r  r   )r%  rp   r  r   )r%  rP   r  r   )r  r   r%  rP   r  zProperType | Noner  r   )r  r   r  r  )r  r   rZ  r  r  r  )r  r   r  rc   r  r   )r;  rL   r  zlist[int] | None)r  r   r;  rL   r  r   )r  r   r  r   )r  r   r;  rL   r  r  r  ztuple[Type, set[str]])r  rm   r;  rL   rN  rF   r  r   )r   rB   r  r   )r   r=   r  r   )r   r`   r  r   )r   r`   r  r  )r  rk   r  r   )r  rj   r  r   )r  r   r-  rF   r.  r  r  r   )r   r   rp  rQ  r-  rF   r  rI  )r  r   rp  rQ  r-  rF   r  r   )r%  rT   r  r   )r%  rb   r  r   )r%  ListExpr | SetExpr | TupleExprr,  r  r  r  )r%  rR  r   r  r9  r  r  r   )r   ri   r-  r   r  r  )r%  ri   r  r   )r%  rH   r  r  )r%  rH   rR  r   r  r   )r%  rH   r  r   )rN  r  rb  rH   r  zlist[TypedDictType])r%  rR   r  r   )r%  rR   r  z/tuple[CallableType | None, CallableType | None])r%  rf   r  r   )r%  rf   r  zType | tuple[Type, Type])r%  rc   r  r   )r%  rS   r  r   )r%  ra   r  r   )r%  rO   r  r   )
r  rO   r  r  r  r  r  zlist[Type] | Noner  r   )r%  rI   r  r   )r%  z'GeneratorExpr | DictionaryComprehensionr  r  )r%  rE   r^  r  r  r   )
r  zdict[Expression, Type] | Noner   rL   rN  r  r^  r  r  r   )NFFF)r   rL   r  r  r^  r  rt  r  r  r  r  r   )r6  r  r  r   )r  r   )r[  r   r  r  r  r  )r6  r  rN  rF   r  r  )r%  rr   r  r   )r%  r?   r^  r  r  r   )
r   r   r-  rF   r  zstr | ErrorMessager  r  r  r   )r%  rs   r^  r  r  r   )r%  rh   r  r   )r%  rn   r  r   )r%  r\   r  r   )r%  ro   r  r   )r%  rY   r  r   )r%  rW   r  r   )r%  rK   r  r   )r%  rl   r  r   )r%  r^   r  r   )r%  rd   r  r   )r   rL   r3  r   r  r   )r   rL   r3  r   r  r  r  r  )r]  r   r  r   r  r  )r   r   r   r   __annotations__r  r  r(  r"  r1  r?  rc  rg  ra  r  r  r  r  r  r  r{  r  r  r  r  r  r9  r  r  r1  r4  r7  r  r9  r:  r^  rd  rk  ro  rv  rx  r  r  r  r{  r"  r  r  r  r  r  r  r*   r  r  r  r  r  r  r   r  r>  r  re  ri  rj  rf  rg  rc  r   r  rh  r  r  r  r  r  r  r  rJ  rL  r  r  r  r  r  r  r  r  r5  r  r%  r  rC  rD  ra  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rA  r  r  r(  r*  r0  r'  r@  rJ  rP  rS  r`  rY  rv  rl  r  r  r  r  r  r  r  r  r  r  ry  rb  r3  r  r?  rA  rK  r  r  r  r  r  r  r  r  r!  r#  r&  r)  r+  r-  r/  rC  r  r   r#  rW  r:  r   r   r   r	  r	  (  s    
"!	## 0/**N O% O  O 	 O
 $2 O 
 OD 	CJ3$2	R
SjG.8,,	M_(-(- !(- (	(-
 (- (- !(- 
(-T0+D0+N[0+	<0+d66 6 ,	6
 &6 
6pR ; 	
 
11 ;1 	1
 !1 
1(
0

]] ,] 	]
 !] &] 
]~0 #	*1I- 
 #_$56"_$56$,.?#@!NO#DE	AN= &+P	"))'*)14)	)VGG !G 	G
 /G *G G G !G G 
GR%% % !	%
 /% M% 
%@

 
 !	

 
 /
 E
 

$

 
 !	

 
 /
 
 C
 

> 26#''!' ' 	'
 !' ' /' !' 
'R'/?	&='=5?=FM=	!=H "22 2 "	2
 !2 2 
2h*F 26+/$(#'%)uYuY uY !	uY
 uY /uY )uY "uY !uY #uY 
uYny'y' y' !	y'
 y' /y' )y' "y' !y' 
y'v0,-\  #%#% #% !	#%
 *#% 
#%JN
$N
5<N
	N
`IR!IR IR !	IR
 /IR *IR IR IR 
IRV6*!6* 6* !	6*
 /6* *6* 16* 6* 6* 
06*p

-- - 	-
 *- - 
-^Q'Q8MQX_Q	Q8 $($(EE !E $	E
 2E *E  E !E "E 
EN;+;+ !;+ $	;+
 2;+ $;+ ;+ 
;+z03>E	, (,#'MM !M 	M
 M *M M %M !M 
M^&_&_ #&_ 	&_
 &_ &_ &_ &_ !&_ &_ &_ 
&_PDD D !	D
 /D "D !D D 
DL9&9& !9& /	9&
 9& 
9&vR6-R6 R6 	R6
 !R6 /R6 "R6 !R6 R6 
"R6h-  !	
 /   
*$#$8J$	$b d-d d 	d
 !d /d "d !d  $d d d 
(dLL .).6D.	. .P
d33 !3 /	3
 3 3 3 
3t "'

 %
 	

 
 

 	TLL L !	L
 /L L 
L #J

&*
5<
	
(;6
EEG134k;ZSj* +/48#oNoN oN
 (oN 2oN oN 
oNp &*#`#` #` 	#`
 !#` #` ##` 
#`X &*KK K 	K
 !K K #K 
K8

 
 	

 
 !
 
 

<BB B 	B
 B B B 
BT $mm m 	m
 m m 
m^MM^ 	 8 QUJJ"+J<MJ	JX!.
`,@$L,( JO#B$#B-7#BBF#B	#BJ'!'*4'?F'	'.4>D.)/V` KPC:C:(/C:CGC:	C:J6W6W%36W:A6W	6WpJ/J/,J/3:J/	J/XA? / EH 	 D!6FYgR-^	1	1.;	1		1PUd"/7	&!IFKOKO	8KOZR$hP(dH 




2 .2 Z Z  Z 	 Z
 + Z 
 ZD"HW:Ol #(`*` ` 	`
  ` 
`. %)"'!&== "=  	=
 = = 
=~)B

&%N=G* UZ#*<MQ	.9v
////
///#20 V V,0HL	 
 PU,0HL	0@	
r   r	  c                6    | j                  t        |            S )zWhether t contains an Any type)rb  
HasAnyType)r   ignore_in_type_objs     r   r  r  c  s    88J12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 )rU  c                N    t         |   t        j                         || _        y r   )superr  r   ANY_STRATEGYrV  )r  rV  	__class__s     r   r  zHasAnyType.__init__i  s    ++,"4r   c                <    |j                   t        j                  k7  S r   )r  r   r0  r  r   s     r   	visit_anyzHasAnyType.visit_anym  s    }}	 6 666r   c                \    | j                   r|j                         ryt        |   |      S )NF)rV  r  rY  visit_callable_type)r  r   r[  s     r   r`  zHasAnyType.visit_callable_typep  s'    ""q}}w*1--r   c                    |j                         r|j                  gng }| j                  |j                  g||j                  z         S r   )r  r6  query_typesr  r  r  r   r6  s      r   visit_type_varzHasAnyType.visit_type_varu  s=    !"199+b 9 9AHH DEEr   c                |    |j                         r|j                  gng }| j                  |j                  g|      S r   r  r6  rb  r  rc  s      r   visit_param_speczHasAnyType.visit_param_specy  4    !"199+b 9 9::r   c                |    |j                         r|j                  gng }| j                  |j                  g|      S r   rf  rc  s      r   visit_type_var_tuplezHasAnyType.visit_type_var_tuple}  rh  r   )rV  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`  rd  rg  rj  __classcell__r[  s   @r   rU  rU  h  s"    57.
F;;r   rU  c                n    t        |       } t        | t              xr | 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"Uqvv:U'UUr   c                    t        |       } t        | t              rI| j                  j                  dk(  r0t        | j                        dk\  rt        | j                  d         } t        | t              xr | j                  j                  dk(  S )z9Whether t came from a function defined using `async def`.ro     r  ztyping.Coroutine)r   r   r   r   r   r~  rp  r   s    r   r  r    sk     	A1hFFOO::K1AFF1I&a"Lqvv:L'LLr   c                f    t        |       } t        | t              xr t        | j                        S r   )r   r   r   r  r   r   s    r   r/  r/    s&    Aa#5QWW5r   c                    t        |       dkD  xr] t        |       dk(  xr4 | d      t        j                  k(  xr | d      t        j                  k(   xr t	        fd| D               S )Nr   r  r   c              3     K   | ]9  }|   t         j                  k(  xr t        t        |         t                ; y wr   )r   r6   r   r   r   )r   r`  r'  r&  s     r   r   z'is_duplicate_mapping.<locals>.<genexpr>  sJ      
  Ou. P|A?OOPs   ?A)r~  r   r5   r6   r   )mappingr&  r'  s    ``r   r"  r"    s     	Gq 	
 LA <WQZ(ENN:<WQZ(EOO;
	
  
 
 
 
r   c                &    | j                  |      S )z>Return a copy of a callable type with a different return type.r  )r  )r  r  s     r   rt  rt    s    ??L?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.
    c                @    t         |   t        j                         y r   rY  r  r   rZ  r  r[  s    r   r  z ArgInferSecondPassQuery.__init__      ++,r   c                R    | j                  |j                        xs t        |      S r   )rb  r  r   r]  s     r   r`  z+ArgInferSecondPassQuery.visit_callable_type  s!    ,@a0@@r   r@  rk  )r   r   r   r   r  r`  rl  rm  s   @r   r  r    s    -Ar   r  c                @    | d uxr | j                  t                     S r   )rb  HasErasedComponentsQueryr   s    r   r  r    s    D=AQXX&>&@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.c                @    t         |   t        j                         y r   ry  rz  s    r   r  z!HasErasedComponentsQuery.__init__  r{  r   c                     yr(  r   r]  s     r   visit_erased_typez*HasErasedComponentsQuery.visit_erased_type      r   r@  )r   r   r  r  )r   r   r   r   r  r  rl  rm  s   @r   r~  r~    s    F-r   r~  c                @    | d uxr | j                  t                     S r   )rb  HasUninhabitedComponentsQueryr   s    r   r  r    s    D=FQXX&C&E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.c                @    t         |   t        j                         y r   ry  rz  s    r   r  z&HasUninhabitedComponentsQuery.__init__  r{  r   c                     yr(  r   r]  s     r   visit_uninhabited_typez4HasUninhabitedComponentsQuery.visit_uninhabited_type  r  r   r@  )r   r   r  r  )r   r   r   r   r  r  rl  rm  s   @r   r  r    s    O-r   r  c                     t                t              t         t              rt                t        t              rt              dd}t        t              rt         t        t
        t        f      ry |       r	 |      ryt         t              r"t        fd j                         D              S t        t              r"t         fdj                         D              S t         t              r't        t              ry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y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.
    c                    t        | t              xsO t        | t              xr | j                         xs+ t        | t              xr | j
                  j                  dk(  S r  )r   r   r   r  r   r   r   rz  s    r   is_typetype_likez4arg_approximate_similarity.<locals>.is_typetype_like  sQ    sH% T3-C#//2CT3)Rchh.?.??.R	
r   Tc              3  6   K   | ]  }t        |        y wr   r  )r   r  rY  s     r   r   z-arg_approximate_similarity.<locals>.<genexpr>  s     `H_-dF;H_   c              3  6   K   | ]  }t        |        y wr   r  )r   r  r[  s     r   r   z-arg_approximate_similarity.<locals>.<genexpr>  s     `H_-fd;H_r  r   rG  )r   r   r   r   r   r   r   r   r  r  r   r  rs  r   r   r   r   r   r  r   r   r    )r[  rY  r  s   `` r   r  r    s    V$FV$F &+&(0&+&(0
 &,'f|ZBC$4V$< &)$`H]H]H_```&)$`H]H]H_``` &-(fm,)&//6BB &(#fl+__Ffj)\\!_--Ffi(#F+Ffh'FKK6;;??,J i**62I4H4H4PQQr   c                   t        |      ry| D cg c](  }t        |||j                  |j                  fd      * }}t	              D ]  \  }}t        |d      st	        |      D 	
cg c]  \  }	}
|
|   r|	|
|   f }}	}
g }g }|D ]J  \  }	}| |	   }|j                  |j                         |D ]   }|j                  |j                  |          " L t        |      rt        |      r y yc c}w c c}
}	w )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                    |    S r   r   r}  s    r   rr  z/any_causes_overload_ambiguity.<locals>.<lambda>F  s
    IVWLr   T)rV  )	r  r   r|  r}  rQ  r  r  r:  r  )r   r  r  r|  r}  r  actual_to_formalarg_idxrK  item_idxlookupmatching_formals_unfilteredmatching_returnsmatching_formalsformalsmatched_callablerY  s     `              r   r  r  .  s7   & l# 	 D 	y$..$..BX	
 	   'y1 T: )22B(C+(C$Hf'? 6'?+(C ( +  "!%@!'#(?  ''(8(A(AB &F$++,<,F,Fv,NO & &A ""23NK[<\3 24 C+s   -C6.C;c                8      syt         fd dd  D              S )NTc              3  <   K   | ]  }t        |d            yw)r   N)r~   )r   r   r   s     r   r   z!all_same_types.<locals>.<genexpr>k  s     <)Q|AuQx()s   r   )r   )r   s   `r   r  r  h  s     <%)<<<r   c                |   g }i }g }| D ]  }|j                         rt        |      }i }|j                  D ]c  }|j                  }||vr?t	        |t
        t        f      r*t	        |t              sJ |||<   |j                  |       ||   ||j                  <   e t        ||      }|j                  |        ||fS )a<  Takes all the typevars present in the callables and 'combines' the ones with the same name.

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

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

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

    Returns both the new list of callables and a list of all distinct TypeVarType objects used.
    )r  r(   r	  r   r   r   r   r   r  r  r%   )r  r   unique_typevarsr	  re  renamer  r6  s           r   r  r  n  s    & "$F.0O#%I/7FF&&{{.!"}6F&GH %b+666,.OD)$$R( / 5ruu ' !0Ff# & 9r   c                l    t        |       } t        | t              r| j                  | j                  S | S )z>If possible, get a more precise literal type for a given type.)r   r   r   rK  rz  s    r   r  r    s2    
#
C#x S%9%9%E###Jr   c                &   t        | t              r0| j                  }t        |t              xr |j                  t
        v S t        | t              rA| j                  }t        |t              xr# t        t        |j                        t              S y)z-Returns 'true' if the given node is a LiteralF)r   rP   rf  r_   r   r   rX   r   r   r   re  r   )r   rf  
underlyings      r   r  r    st    $	"yy$(PT]]>P-PP$!YY
*i0 
ZJ--.6
 	
 r   c                    t        |       } ddh}t        | t              rt        d | j                  D              S t        | t
              r| j                  j                  |v ryy)z?Is this one of builtin byte types, or a union that contains it?r   r   c              3  2   K   | ]  }t        |        y wr   )r=  r  s     r   r   z&has_bytes_component.<locals>.<genexpr>  s     =9a&q)9r   TF)r   r   r   r  r   r   r   r   )r[  
byte_typess     r   r=  r=    sW    
#
C"$89J#y!=399===#x SXX%6%6*%Dr   c                j   t        |       } t        | t              r | j                         r| j	                         S t        | t
              r| j                  } t        | t              rt        | j                        } t        | t              rt        |       } t        | t              r| j                  S y)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   rz  s    r   r  r    s    
#
C#|$):  #x hh#{#coo.#y!S!#x xx r   c                    | sy| j                  d      d   }|t        j                  j                         v xsB |t        j                  j                         v xs  |t        j
                  j                         v S )NFr   r+  )splitr   r  r  r  r  )r   
short_names     r   rk  rk    so    $R(Ji**1133 	=55<<>>	=33::<<r   c                D    | t        | t              r| j                  y | S r   )r   r   r   r   s    r   r<  r<    s     y
1k2affnHr   c                    t        |       } t        | t              ryt        | t              rt	        d | j
                  D              S y)NTc              3  2   K   | ]  }t        |        y wr   )r=  )r   r  s     r   r   z'is_type_type_context.<locals>.<genexpr>  s     H-$'--r   F)r   r   r   r   r  r   r  s    r   r=  r=    s;    g&G'8$'9%H'--HHHr   )r   r   r  r  )r   r_   r  rF  rA  )r   r   rV  r  r  r  )ru  rP  r&  rI  r'  rC  r  r  )r  r   r  r   r  r   )r   r  r  r  )r[  r   rY  r   r  r  )r   r  r  rI  r  rI  r|  rC  r}  rJ  r  r  )r   rI  r  r  )r  zSequence[CallableType]r  z,tuple[list[CallableType], list[TypeVarType]])r[  r   r  r   rB  r~  )r[  r   r  zTypeInfo | None)r   rQ  r  r  )r   r  r  zPartialType | None)rN  r  r  r  (  r   
__future__r   enumr  r  collectionsr   
contextlibr   r  r   r   r   r	   r
   r   r   r   r   r  r   r   r   r   mypy.checkerr  mypy.errorcodes
errorcodesr  r   r   r   r   r   r   r   mypy.argmapr   r   r   mypy.checkmemberr   r   r   mypy.checkstrformatr   mypy.erasetyper    r!   r"   mypy.errorsr#   r$   mypy.expandtyper%   r&   r'   r(   
mypy.inferr)   r*   r+   mypy.literalsr,   mypy.maptyper-   	mypy.meetr.   r/   mypy.message_registryr0   mypy.messagesr1   r2   
mypy.nodesr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   mypy.optionsrt   mypy.pluginru   rv   rw   rx   ry   mypy.semanal_enumrz   
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   
mypy.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mypy.types_utilsr   r   r   r   mypy.typestater   mypy.typevarsr   	mypy.utilr   mypy.visitorr   r  r   rS  r   r   r   r  r   r   r   r   uniqueEnumr   r  r  r  r  r  r  r	  r  BoolTypeQueryrU  r  r  r/  r"  rt  r  r  r~  r  r  r  r  r  r  r  r  r=  r  rk  r<  r=  r   r   r   <module>r     s   M "    # % ` ` ` M M   V V V W W Z Z 6 [ [ ;  a ` ! 2 @ . 5C C C C C C C C C C C C C C C C CH -  )   0      $) ) ) ) ) ) ) ) ) ) )T  & ' ( * "	4$S,QXY[__
J  
E 
	& U 	& U I @Oy O    (// U /&-- E -%++ 5 +x\
)$/ x\
vy4
;$$ ;4VM06
&0@M	22
Ae11 A Bu22 GE$7$7 <R~777 7 	7
 +7 
7t=*%*1*Z
&r   