o
    2gi                    @  s  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lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ 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. d.eZdd3d4Zdd8d9ZG d:d; d;eZejG d<d= d=ejZejZd'ed>< ejZd'ed?< ej Zd'ed@< G dAdB dBee ZdddEdFZG dGdH dHe$jZddIdJZddKdLZddMdNZddUdVZ	ddZd[Z
G d\d] d]e$jZG d^d_ d_e$jZddadbZG dcdd dde$jZddedfZG dgdh dhe$jZddkdlZddtduZddwdxZdd|d}ZdddZdddZdddZdddZdddZdddZdddZdS )zGExpression type checker. This file is conceptually part of TypeChecker.    )annotationsN)defaultdict)contextmanager)	CallableClassVarFinalIterableIteratorListOptionalSequencecast)	TypeAliasassert_neveroverload)	applytype	erasetypejoinmessage_registrynodes	operatorstypes)ArgTypeExpandermap_actuals_to_formalsmap_formals_to_actuals)analyze_member_accessfreeze_all_type_varstype_object_type)StringFormatterChecker)
erase_type!remove_instance_last_known_valuesreplace_meta_vars)ErrorWatcherreport_internal_error)expand_typeexpand_type_by_instancefreshen_all_functions_type_varsfreshen_function_type_vars)ArgumentInferContextinfer_function_type_argumentsinfer_type_arguments)literal)map_instance_to_supertype)is_overlapping_typesnarrow_declared_type)ErrorMessage)MessageBuilderformat_type)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)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is_named_instancesplit_with_prefix_and_suffix)is_generic_instanceis_overlapping_noneis_self_type_likeremove_optional)
type_state)fill_typevars)split_module_names)ExpressionVisitor
_TypeAlias
ArgChecker   r   
MAX_UNIONS)builtins.setzbuiltins.frozensetztyping.KeysViewztyping.ItemsViewzbuiltins._dict_keyszbuiltins._dict_itemsz_collections_abc.dict_keysz_collections_abc.dict_itemsOVERLAPPING_TYPES_ALLOWLIST>   builtins.memoryviewbuiltins.bytesbuiltins.bytearrayOVERLAPPING_BYTES_ALLOWLISTc                   @     e Zd ZdZdS )TooManyUnionszyIndicates that we need to stop splitting unions in an attempt
    to match an overload in order to save performance.
    N__name__
__module____qualname____doc__ r   r   F/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/checkexpr.pyr          r   tr   returnboolc                 C  sD   t | tr
| jr
dS t| } t | tp!t | to!tdd | jD S )NFc                 s      | ]}t |V  qd S N)allow_fast_container_literal.0itr   r   r   	<genexpr>       z/allow_fast_container_literal.<locals>.<genexpr>)
isinstancer   is_recursiver   r   r   allitemsr   r   r   r   r      s   
r   exprr^   set[str]c                 C  s   t  }t| jts| jrvt| jtr| jr|| j t| trRt| jto)| jj}t| jt	r<|
t| jj 	 |S d| jv rO|sO|| jddd  	 |S t| trdt| jtra| j} n	 |S tdt|  t| jts| js|S )zRecursively extracts all module references from a reference expression.

    Note that currently, the only two subclasses of RefExpr are NameExpr and
    MemberExpr..   r   zUnknown RefExpr subclass: )setr   noderU   fullnameaddrW   rp   is_suppressed_importrl   updater   module_namersplitrT   r   r^   AssertionErrortype)r   outputr   r   r   r   extract_refexpr_names   s,   

r   c                   @  r   )FinishedzDRaised if we can terminate overload argument check early (no match).Nr   r   r   r   r   r     r   r   c                   @  s   e Zd ZdZdZdZdZdS )
UseReversezCUsed in `visit_op_expr` to enable or disable reverse method checks.r   r      N)r   r   r   r   DEFAULTALWAYSNEVERr   r   r   r   r     s
    r   USE_REVERSE_DEFAULTUSE_REVERSE_ALWAYSUSE_REVERSE_NEVERc                   @  s
  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< dJddZdKddZdLddZdMdNdd ZdOd%d&Z	dPd*d+Z
dMdQd.d/ZdRd2d3ZdMdQd4d5ZdSd6d7ZdTd<d=ZdUd>d?ZdVdBdCZdSdDdEZdSdFdGZdWdRdSZdXdWdXZdYd^d_ZdZdbdcZd[dedfZd\dgdhZd]dldmZd^dndoZd_dpdqZd`dudvZdwgdxdygdzZd{ed|< d}d~giddgiddgiddd~gidZded< dSddZ daddZ!dbddZ"dcddZ#ddddZ$deddZ%dfddZ&		dgdhddZ'diddZ(djddZ)	dkdlddZ*dmddZ+					dndoddZ,dpddZ-dqddZ.drddńZ/dsddǄZ0dtddɄZ1dudd˄Z2dvddτZ3dwdd҄Z4dxddׄZ5dyddڄZ6dzdd߄Z7d{ddZ8		dgd|ddZ9d}ddZ:d~ddZ;		dgdddZ<dddZ=dddZ>dd dZ?dddZ@dddZAdddZB		ddddZCdddZDeEdddZFdddZGdddZH	dMdd d!ZIdd"d#ZJdd$d%ZKdMdd'd(ZLdd)d*ZMdd,d-ZNdd.d/ZOdd3d4ZPdd8d9ZQdd;d<ZRdd>d?ZSddAdBZTddDdEZUddGdHZVddJdKZWddMdNZXddPdQZYddRdSZZdddTdUddZd[Z[	dkdd]d^Z\	dkdd_d`Z]ddbdcZ^ddidjZ_	dMddmdnZ`ddodpZaddqdrZbddtduZcddwdxZdddzd{Zedd|d}Zf	dkdddZgdddZhdddZidddZjdddZkdddZldddZm	dMdddZndddZodddZpdddZqdddZrdddZsdddZtdddZudddddZvdddZwdddZxdddZydddZzdddZ{dddÄZ|ddŐdƄZ}ddǐdȄZ~ddʐd˄Zdd͐d΄ZddϐdЄZddӐdԄZdÐd֐dׄZdĐdِdڄZdŐdܐd݄ZdƐdߐdZdǐddZdȐddZdɐddZdʐddZ	dkdːddZd̐ddZd͐ddZdMdΐddZ	dMdϐddZ				dАdѐddZdҐddZdӐddZdd	d
ZdddZdԐddZdՐddZd֐ddZdMdאddZ	dMdؐddZdMdِddZdڐdd Zdېd"d#Zdܐd%d&Zdݐd(d)Zdސd+d,Zdߐd.d/Zdd1d2Zdd4d5Zdd7d8Zdd:d;ZdӐd<d=ZdӐd>d?ZeddAdBZeddDdBZ	dMddEdBZddFdGZddHdIZdS (  ExpressionCheckerz^Expression type checker.

    This class works closely together with checker.TypeChecker.
    mypy.checker.TypeCheckerchkr0   msgzlist[Type | None]type_contextzdict[Expression, ProperType]resolved_typer   strfrm_checkerrx   pluginper_line_checking_time_nsdict[int, int]r   Nonec                 C  sj   || _ || _|| _|| _|jjdu| _d| _dg| _i | _	t
| | j | j| _i | _d| _| j jj t_dS )z%Construct an expression type checker.NF)r  r  r  r  optionsline_checking_statscollect_line_checking_statsin_expressionr  type_overridesr   r
  r	  	is_calleeold_type_inferencer   infer_polymorphic)selfr  r  r  r  r   r   r   __init__9  s   zExpressionChecker.__init__c                 C  s
   i | _ d S r   )r	  r  r   r   r   reset[     
zExpressionChecker.reseterW   r   c                 C  s(   | j jt| | |}| ||S )z_Type check a name expression.

        It can be of any kind: local, member or global.
        )r  module_refsr   r   analyze_ref_exprnarrow_type_from_binder)r  r  resultr   r   r   visit_name_expr^  s   
z!ExpressionChecker.visit_name_exprFr^   lvaluer   c                 C  s  d }|j }t|tr|jrttjS t|tr,| ||}t|t	r+| j
||||}nt|tr:t|| d}nt|tr^|jd u rZ| j
 rT|jrT| j
|j| ttj}n|j}nt|tr|jrl| |}n|jdkrwtt }nt|| j}t|trt|jtr|j |j_ |j!|j_!t"| j#d rt$%|}nRt|t&r| '|}nGt|t(r| |j)|}n:t|t*r| j+|||j,p|d}n)t|t-r| dS t|t.t/fr| 0 }nt|t1rJ d|jdttj}|d usJ |S )	Nbuiltins.functionztypes.NoneTypectxalias_definitionztyping.TypeVarFzPlaceholderNode z leaked to checker)2r   r   rW   is_special_formr   r   special_formrp   analyze_var_refr   r  handle_partial_var_typerM   r   
named_typerZ   r   in_checked_functionr   handle_cannot_determine_typename
from_errorrl   typeddict_typetypeddict_callabler   r   r   r   r   ret_typer   linecolumnis_type_type_contextr  r   erase_typevarsrU   module_typerF   varr   alias_type_in_runtime_contextis_alias_rvaluerm   r[   rn   object_typer\   )r  r  r"  r   r   r   r   r   r  g  s`   


















z"ExpressionChecker.analyze_ref_exprr9  rp   contextrE   c                 C  s   |j r4t|j }t|tr1|jdkr| dS |  r#|jd ur#|jS |jdv r1| 	|jdkdS |j S |j
sD| j rD| j|j| ttjS )Nz
typing.Anytyping._SpecialForm>   TrueFalser?  builtins.bool)r   r   r   r   r   r,  is_literal_contextlast_known_valuer/  infer_literal_expr_typeis_readyr  r-  r.  r   r   r)  )r  r9  r=  var_typer   r   r   r*    s   





z!ExpressionChecker.analyze_var_refr   rU   r   c                 C  s   z|  d}W n ty   |  d}Y nw i }t }|j D ]+\}}|js(q t|jtr7|jj	r7|
| | j|}|rD|||< q ttj||< q t|||j|_|S )Nztypes.ModuleTypebuiltins.object)r,  KeyErrorr   namesr   module_publicr   r   rp   is_finalr   r  determine_type_of_memberr   r   r)  r   r   extra_attrs)r  r   r   module_attrs	immutabler/  ntypr   r   r   r8    s$   

zExpressionChecker.module_typer@   allow_none_returnc                 C  sF   |j rt|j tr|j js| | | |j | jd S | j||dS )zType check a call expression.r$  rR  )analyzedr   rV   is_typedvisit_call_expr_inneracceptr  )r  r  rR  r   r   r   visit_call_expr  s
   
z!ExpressionChecker.visit_call_exprbaserK   c                 C  sH   t |tsdS t |jtr|jjd urdS t |jto#t t|jjtS )NFT)	r   r^   r   rl   r1  r   r   targetr   )r  rY  r   r   r   refers_to_typeddict  s   
z%ExpressionChecker.refers_to_typeddictc              	     s    jst jtr;  jjr;tj jdd}t|tr;t|j}t|t	s.J 
| j j j |S t jtr jjdv rt jdkrtj jd D ]}d }t|trvz	j|j}W n	 tyu   Y nw t|rj jjd  qZ|rt|jtrt|jj}t|trj jjd  qZt|trqZt|trt|jt t!fst|tr|rt|jtr|jj"stt|jj }t#r|j$sۈj%  t|t&rt|jt'r|jj(rj jjd  qZ|jj)rj jjd	  qZ*  d }	t jt+rKt, j j jj jj fd
d fddt-t jjD }
t|
 jj jj. /dd}	tj j|	ddd}d }d }d t jt&r jj0pjd t jjtrt jjj}t|t1r|j2j0st jt3rj4 jj5r jj}j6 jj5}jj7j8rj9 rt|tr|j:r|jt;krd u r|d ur|d usJ <||rt=fddjj7j>D sj?|  @| ||}t jt&rt jdkr jj0dv rA   jj0dkrB  t jt3r2 jjdkr2C  t|}t|t#rAtD|jE}t|tFrQ|jGsQjjHI  |snt|trnJ jrnjjK|  ttLjMS |S )NTr  )r   
issubclassr   r   LiteralAny	TypedDictNewTypec                   s     j|  S r   rW  argsir  r  r   r   <lambda>+      z9ExpressionChecker.visit_call_expr_inner.<locals>.<lambda>c                   s*   g | ]}t  fd d| D qS )c                   s   g | ]
}  j| qS r   rb  )r   jrf  r   r   
<listcomp>/  s    zFExpressionChecker.visit_call_expr_inner.<locals>.<listcomp>.<listcomp>)r   join_type_listr   re  )r  formal_to_actualr  r   r   rj  .  s    z;ExpressionChecker.visit_call_expr_inner.<locals>.<listcomp>r#  )r3  fallback)always_allow_anyr  c                 3  s(    | ]} |kp  | d V  qdS )r   N)
startswith)r   p)r   r   r   r   `  
    
z:ExpressionChecker.visit_call_expr_inner.<locals>.<genexpr>)zbuiltins.isinstancebuiltins.issubclassrs  format)Nr[  calleer   rO   rY  r   rW  r   r3  r   check_typeddict_call	arg_kinds	arg_namesrc  rW   r/  lenmypycheckerflattenr  lookup_qualifiedrH  is_expr_literal_typer  cannot_use_function_with_typer   r   rZ  r   r   rT  rj   ri   no_argsr   uses_pep604_syntaxtype_arguments_not_allowedr^   rl   r1  
is_newtypetry_infer_partial_typerQ   r   ranger<  r,  r   r   r   rT   has_typer   lookup_typer  disallow_untyped_callsr-  implicitr7   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   r0  )r  r  rR  r2  r1  rQ  r   rZ  union_targetr  	arg_typescallee_typer<  memberr3  r   )r  rm  r   r  r   rV    s  








	











z'ExpressionChecker.visit_call_expr_innerc                 C  s   t |jtsJ d}t |jjtr|jjj}nL| j|jjrct| j	|jj}t |t
rQ|jjrQt |jtrQt |jjtrQ|jj|jj j}t |trQt|}t|}t |trct |jtrc|j}|durp| j|| dS dS )z>More precise type checking for str.format() calls on literals.N)r   ru  rT   r   rd   valuer  r  r   r  r   r   is_enumrC  r   strrI  r   try_getting_literalr
  r  )r  r  format_valuerQ  
value_typebase_typr   r   r   r    s.   

z'ExpressionChecker.check_str_format_callr<  method_namer  
str | Nonec                 C  s   t |}t|tr| rt |j}nt|tr|j}d}t|tr'|jj	}n#t|t
tfr?|jj|}|dur<|j	nd}nt|trJt|jj	}|rS| d| S dS )zConvert a method name to a fully qualified name, based on the type of the object that
        it is invoked on. Return `None` if the name of `object_type` cannot be determined.
        Nr   )r   r   r   is_type_objr3  r   itemr   r   r   r   r   rn  get_containing_type_infor   r   )r  r<  r  	type_nameinfor   r   r   r    s    



z!ExpressionChecker.method_fullnamec                 C  s   t |tr| |jrdS t |trT|jdu rTt| j|j}t |t	r)|j
}nt |trB| rBt|j}t |t	r@|j
}ndS dS ||j}|rT| |jrTdS dS )zPCheck if `node` refers to something explicitly annotated as only returning None.TNF)r   r^   defn_returns_noner   rT   r   r  r  r   r   r   r   r  r3  getr/  )r  r   rQ  r  r3  symr   r   r   r    s"   



z%ExpressionChecker.always_returns_nonedefnSymbolNode | Nonec                   s   t |trt |jtot t|jjtS t |tr%t fdd|j	D S t |t
rVt|j}|jsAt |trAt t|jtrAdS t |trV|jd}|rV |jrVdS dS )z'Check if `defn` can _only_ return None.c                 3      | ]}  |V  qd S r   )r  r   r  r  r   r   r         z6ExpressionChecker.defn_returns_none.<locals>.<genexpr>T__call__F)r   rM   r   r   r   r3  r   rZ   r   r   rp   is_inferredr   r  r  r   )r  r  rQ  r  r   r  r   r    s(   




z#ExpressionChecker.defn_returns_nonec                 C  sb   t j|jd D ]%}t| j|}t|tr.|	 r.|
 jr.|
 js.| jtj| q	d S Nr   )rz  r{  r|  rc  r   r  r  r   r   r  type_objectis_protocolruntime_protocolfailr   RUNTIME_PROTOCOL_EXPECTED)r  r  r   tpr   r   r   r    s   z-ExpressionChecker.check_runtime_protocol_testc                 C  sn   t j|jd D ]+}t| j|}t|tr4|	 r4|
 jr4t|
 }|r4| jj|
 || q	d S r  )rz  r{  r|  rc  r   r  r  r   r   r  r  r  r   r  report_non_method_protocol)r  r  r   r  attr_membersr   r   r   r    s   z+ExpressionChecker.check_protocol_issubclassru  r   rw  list[ArgKind]rx  Sequence[str | None]rc  list[Expression]orig_calleeType | Nonec                 C  s   |r2t dd |D r2tdd |D |}| j||d}|d ur-|\}	}
| ||	|||
S ttjS t|dkre|d tkre|d }t	|t
rP| ||j||S t	|tret	|jt
re| ||jj||S |sq| |i ||t S | jtj| ttjS )Nc                 s  s    | ]	}|t tfv V  qd S r   )r2   r5   )r   akr   r   r   r         z9ExpressionChecker.check_typeddict_call.<locals>.<genexpr>c                 S  s    g | ]}|d urt |nd qS r   )rd   )r   rP  r   r   r   rj          z:ExpressionChecker.check_typeddict_call.<locals>.<listcomp>kwargsru  r   r   )r   zipvalidate_typeddict_kwargs check_typeddict_call_with_kwargsr   r   r0  ry  r3   r   rG   check_typeddict_call_with_dictr   r@   rT  r   r  r  r   INVALID_TYPEDDICT_ARGS)r  ru  rw  rx  rc  r=  r  r  r   validated_kwargsalways_present_keys
unique_argr   r   r   rv    s.   	




z&ExpressionChecker.check_typeddict_callr  .Iterable[tuple[Expression | None, Expression]]3tuple[dict[str, list[Expression]], set[str]] | Nonec                 C  s  t t}t }d }|D ]L\}}|rJ| |}t||}	d }
|	r)t|	dkr)|	d }
|
d u r?|p0|}| jjtj	|t
jd  d S |g||
< ||
 q|}| ||||sW d S q| jjjr|d urg }|jD ]}||jvrv||vrv|| qf|r| j|| ||fS )Nr   r   code)r   listr   rW  r   ry  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  ru  r   r  last_star_founditem_name_expritem_argkey_typevaluesliteral_valuekey_contextabsent_keyskeyr   r   r   r    sF   




z+ExpressionChecker.validate_typeddict_kwargsr  r   dict[str, list[Expression]]r  r   c                   sZ  t | j||d}g }t|tr|g}n7t|tr=t| D ]}t|tr,|| q| |s;| j	
||  dS qn| |sK| j	
|| dS t }|D ]	}	||	j O }qP|D ]N tt fdd|D }
|
| t fdd|D r|  |  r|  d }t|ts||
g| < q\|
g| < q\|
g| < q\|  |
 q\dS )	zUpdate keys/expressions from a ** expression in TypedDict constructor.

        Note `result` and `always_present_keys` are updated in place. Return true if the
        expression `item_arg` may valid in `callee` TypedDict context.
        r  Fc                   s    g | ]} |j v r|j   qS r   r   r   tdr  r   r   rj  n  r  zBExpressionChecker.validate_star_typeddict_item.<locals>.<listcomp>c                 3  s    | ]} |j v V  qd S r   r  r  r  r   r   r   q  r  zAExpressionChecker.validate_star_typeddict_item.<locals>.<genexpr>r   T)r   rW  r   r   r   r   relevant_itemsr  valid_unpack_fallback_itemr  %unsupported_target_for_star_typeddictr   r   keysrg   
make_unionset_liner   r   )r  r  ru  r   r  inferredpossible_tdsr  all_keysr  argfirstr   r  r   r  O  sD   







z.ExpressionChecker.validate_star_typeddict_itemrQ  r   c                 C  sR   t |trdS t |tr|jdsdS t|| jd}tdd t	|j
D S )NTtyping.MappingFc                 s      | ]}t |tV  qd S r   )r   r   r   ar   r   r   r     r  z?ExpressionChecker.valid_unpack_fallback_item.<locals>.<genexpr>)r   r   r   r   has_baser,   r  lookup_typeinfor   r   rc  )r  rQ  mappedr   r   r   r    s   
z,ExpressionChecker.valid_unpack_fallback_item*list[tuple[Expression | None, Expression]]c                 C  sN   | j ||d}|d ur%|\}}|jt|   ko"t|j kS   S dS )Nr  F)r  r  r   r  r   )r  ru  r  r=  r   r  _r   r   r   match_typeddict_call_with_dict  s
   ,z0ExpressionChecker.match_typeddict_call_with_dictc                 C  s<   | j ||d}|d ur|\}}| j|||||dS ttjS )Nr  )r  r=  r  r  )r  r  r   r   r0  )r  ru  r  r=  r  r   r  r  r   r   r   r    s   
z0ExpressionChecker.check_typeddict_call_with_dictr  rl   r   c                 C  sx   |j dusJ |j j}t|trt|tsJ t|j }tj	gt
| }t|j }t||||| d|jjdS )a  Construct a reasonable type for a TypedDict type in runtime context.

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

        Note it is not safe to move this to type_object_type() since it will crash
        on plugin-generated TypedDicts, that may not have the special_alias.
        Nbuiltins.type	variables)special_aliasrZ  r   r   r   r  r   r  r;   r2   ry  r  r   r,  r  	type_vars)r  r  rZ  expected_typeskindsrI  r   r   r   r2    s   	z$ExpressionChecker.typeddict_callablec                   s:   t t j  fdd jD t j  | dS )Nc                   s"   g | ]}| j v rtjntjqS r   )r  r;   r2   ARG_NAMED_OPT)r   r/  ru  r   r   rj    s    zEExpressionChecker.typeddict_callable_from_context.<locals>.<listcomp>r   )r   r  r   r  r  r,  )r  ru  r   r  r   typeddict_callable_from_context  s   
z1ExpressionChecker.typeddict_callable_from_contextc                   s  |   jr j@ }|r| jj||d j|kr" j  ksj j  ks@| jj fddj  D t |d j|ks`| jjfddj  D fdd|D |d j krjt	t
jS t|}t|trv|}njjjd ur| jj}n| }| j < | j ' | |dd | D tjgt| |t|  d d d \}}	W d    n1 sw   Y  W d    n1 sw   Y  t|}
t|
tsވ}
|
j D ])\}}||v r|| }|D ]}| jj|||ttj j!t"j#dd	| d
dd qq|S )Nr=  c                   s"   g | ]}|j v s| v r|qS r   r  r   r  actual_keysru  r   r   rj    s
    zFExpressionChecker.check_typeddict_call_with_kwargs.<locals>.<listcomp>)expected_keysr  r=  c                      g | ]	}| j v r|qS r   r  r  r  r   r   rj        c                   r  r   r  r  r  r   r   rj    r  c                 S     g | ]}|d  qS r   r   )r   rc  r   r   r   rj        r  zTypedDict item ""
expression)lvalue_typervaluer=  r  lvalue_namervalue_name)$r  to_be_mutatedreadonly_keysr  readonly_keys_mutatedr  r   unexpected_typeddict_keysr  r   r   r0  r   r   r   rn  r   r  r2  r	  filter_errorsr  local_type_mapcheck_callable_callr  r;   r2   ry  r   check_simple_assignmentr/   r   INCOMPATIBLE_TYPESr  r  TYPEDDICT_ITEM)r  ru  r  r=  r  r  assigned_readonly_keysinfer_calleeorig_ret_typer  r3  	item_nameitem_expected_typeitem_values
item_valuer   r  r   r    s   











 



z2ExpressionChecker.check_typeddict_call_with_kwargsr   rT   
Var | Nonec                 C  sx   t |jtrt |jjtr|jjjsdS | jj }|r"|j	|j
vr$dS |j
|j	 }t |jtr:t |jjtr:|jS dS )zGet variable node for a partial self attribute.

        If the expression is not a self attribute, or attribute is not variable,
        or variable is not partial, return None.
        N)r   r   rW   r   rp   is_selfr  scopeenclosing_classr/  rI  r   r   )r  r   r  r  r   r   r   get_partial_self_var3  s   
z&ExpressionChecker.get_partial_self_varr  r   discard)builtins.listr   zClassVar[dict[str, list[str]]]	item_argsextendr1  r   builtins.dictr   )r1  r4  zcollections.OrderedDictr   z)ClassVar[dict[str, dict[str, list[str]]]]container_argsc                 C  sd  t |jtsdS |j}t |jtr=| |j}|du rdS |\}}| ||j|}|dur9||v r;||_||= dS dS dS t |jt	rt |jj
tr|jjdurRdS |jj
}|jj}| |}|du redS |\}}t|j}	|	du sw|	jdu rydS | ||j|}
|
dur| |}tj|r|	jdusJ |	jj}| j|||
g|_||= dS dS dS dS dS )z-Try to make partial type precise from a call.N)r   ru  rT   r   r^   get_partial_var&try_infer_partial_value_type_from_callr/  r   rO   rY  rT  indexget_partial_instance_typer  rW  rz  r{  is_valid_inferred_typer   r  named_generic_type)r  r  ru  retr9  partial_typesrQ  rY  r8  partial_typer  r  typenamer   r   r   r  U  sH   




z(ExpressionChecker.try_infer_partial_typeref%tuple[Var, dict[Var, Context]] | Nonec                 C  sP   |j }|d u rt|tr| |}t|tsd S | j|}|d u r$d S ||fS r   )r   r   rT   r/  rp   r  find_partial_types)r  r@  r9  r=  r   r   r   r6  }  s   

z!ExpressionChecker.get_partial_var
methodnameInstance | Nonec           	      C  s@  | j jrdS t|j}|du rdS |jr|jjj}n|jdus!J |jj}|| jv rO|| j| v rO|jtgkrO| 	|j
d }tj|rM| j ||gS dS || jv r|| j| v r|jtgkrt| 	|j
d }t|tr|jj}|| j| | v rtdd |j
D r| j |t|j
S dS t|tr| j |S dS )zCTry to make partial type precise from a call such as 'x.append(y)'.Nr   c                 s  s    | ]	}t j|V  qd S r   )rz  r{  r:  )r   	item_typer   r   r   r     s
    

zKExpressionChecker.try_infer_partial_value_type_from_call.<locals>.<genexpr>)r  current_node_deferredr9  r   r  r   r2  rw  r3   rW  rc  rz  r{  r:  r;  r5  r   r   r   r   r  r   r,  )	r  r  rC  r9  r>  r?  rE  arg_typearg_typenamer   r   r   r7    s>   




z8ExpressionChecker.try_infer_partial_value_type_from_callr  
list[Type]Sequence[str | None] | Nonerm  list[list[int]]r   c
                 C  sP  t |j}
dd t|
D }dd t|
D }dd t|
D }dd t|
D }t|D ]7\}}|D ]0}|| ||  || ||  |rS|| ||  n|| d || ||  q3q-|du r| j|}|dusuJ |t|||j||j	||	| j
dS | j|}|dusJ t|}|t||||j||j	||	| j
d	S )	a  Use special case logic to infer the return type of a specific named function/method.

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

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

        Return the inferred return type.
        c                 S     g | ]}g qS r   r   r   r  r   r   r   rj    rh  z;ExpressionChecker.apply_function_plugin.<locals>.<listcomp>c                 S  rL  r   r   rM  r   r   r   rj    rh  c                 S  rL  r   r   rM  r   r   r   rj    rh  c                 S  rL  r   r   rM  r   r   r   rj    rh  N)r  rw  callee_arg_namesrx  default_return_typerc  r=  api)	r   r  rw  rN  rx  rO  rc  r=  rP  )ry  r  r  	enumerater  r  get_function_hookrt   rx  r3  r  get_method_hookr   rv   )r  ru  rw  r  rx  rm  rc  r   r<  r=  num_formalsformal_arg_typesformal_arg_exprsformal_arg_namesformal_arg_kindsformalactualsactualcallbackmethod_callbackr   r   r   apply_function_plugin  sZ   
	z'ExpressionChecker.apply_function_pluginr   hook>Callable[[list[list[Expression]], CallableType], FunctionLike]c                   s   t |tr>t|j}t|||j|j fdd}dd t|D }t|D ]\}	}
|
D ]}||	  |  q,q&|||S t |t	sEJ g }|j
D ]}| |||}t |ts\J || qJt	|S )z@Helper to apply a signature hook for either a function or methodc                        |  S r   rW  rd  rc  r  r   r   rg        z8ExpressionChecker.apply_signature_hook.<locals>.<lambda>c                 S  rL  r   r   rM  r   r   r   rj    rh  z:ExpressionChecker.apply_signature_hook.<locals>.<listcomp>)r   r   ry  rw  r   rx  r  rQ  r  r   r   apply_signature_hook)r  ru  rc  rw  rx  r_  rT  rm  rV  rY  rZ  r[  r   r  adjustedr   rc  r   re    s,   
	


z&ExpressionChecker.apply_signature_hooksignature_hook,Callable[[FunctionSigContext], FunctionLike]c              	     s    |||| fddS )zKApply a plugin hook that may infer a more precise signature for a function.c                   s   t | | jS r   )ru   r  rc  sigr=  r  rg  r   r   rg  +  r  zAExpressionChecker.apply_function_signature_hook.<locals>.<lambda>)re  )r  ru  rc  rw  r=  rx  rg  r   rk  r   apply_function_signature_hook  s   
z/ExpressionChecker.apply_function_signature_hook*Callable[[MethodSigContext], FunctionLike]c              
     s(   t ||||| fddS )zIApply a plugin hook that may infer a more precise signature for a method.c                   s   t | | jS r   )rw   r  ri  r=  pobject_typer  rg  r   r   rg  @  s    z?ExpressionChecker.apply_method_signature_hook.<locals>.<lambda>)r   re  )r  ru  rc  rw  r=  rx  r<  rg  r   rn  r   apply_method_signature_hook.  s   z-ExpressionChecker.apply_method_signature_hookNcallable_namec           
   	   C  st   t |}|dur8t|tr8|dur&| j|}|r$| |||||||S |S | j|}	|	r8| ||||||	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.
        N)r   r   r   r  get_method_signature_hookrp  get_function_signature_hookrl  )
r  rq  ru  rc  rw  r=  rx  r<  method_sig_hookfunction_sig_hookr   r   r   transform_callee_typeF  s   
z'ExpressionChecker.transform_callee_typer  Overloaded | Nonec              	   C  s   |j sJ t|jdkst|dkrdS tt|jd ts dS tt|jts*dS | j ( | j	
  t| j|d dd}W d   n1 sKw   Y  W d   n1 sZw   Y  t|trf|S dS )zSCheck if this looks like an application of a generic function to overload argument.r   Nr   r  )r  ry  r  r   r   r   r3  r  r  r  r  rW  r   )r  r  rc  rG  r   r   r   "is_generic_decorator_overload_callo  s    

z4ExpressionChecker.is_generic_decorator_overload_call
overloadedr   r&  tuple[Type, Type] | Nonec              	   C  s   g }g }|j D ]K}t|d}| j }| ||gtg|\}	}
W d   n1 s*w   Y  | r4qt|	}t|t	s>qt|
}t|t	sHq|
| |
| q|rW|sYdS t|t|fS )a  Type-check application of a generic callable to an overload.

        We check call on each individual overload item, and then combine results into a new
        overload. This function should be only used if callee_type takes and returns a Callable.
        rQ  N)r   rg   r  r  
check_callr3   has_new_errorsr   r   r   r  r   )r  r  ry  r&  r   inferred_argsr  r  erritem_resultinferred_argp_item_resultp_inferred_argr   r   r   handle_decorator_overload_call  s(   




z0ExpressionChecker.handle_decorator_overload_callr  c              
   C  s   |du r|dur|dusJ |  ||}t|}|r)| |||j|j||j|}n|dur9t|tr9| |||S | j	||j|j||j|j
||d\}}t|}t|j
trot|tro|jdure|j|j
_|jduro|j|j
_|S )a?  Type check call expression.

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

        The 'member', 'callable_name' and 'object_type' are only used to call plugin hooks.
        If 'callable_name' is None but 'member' is not None (member call), try constructing
        'callable_name' using 'object_type' (the base type on which the method is called),
        for example 'typing.Mapping.get'.
        N)callable_noderq  r<  )r  r   rv  rc  rw  rx  r   r   check_union_call_exprr|  ru  r^   r   
type_guardtype_is)r  r  r  rq  r<  r  r3  proper_calleer   r   r   r    s6   





z2ExpressionChecker.check_call_expr_with_callee_typer   c           
      C  s   g }|  D ]O}| j  t|||ddd| j|| j|  |d}W d   n1 s+w   Y  | j|j|dd}|du r>q| ||}|rH|nd}	|	| 
||||	 qt|S )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  rB  r  ru  r  r  r  r   )
r  r  r<  r  resrQ  r  narrowedrq  item_object_typer   r   r   r    s4   z'ExpressionChecker.check_union_call_exprr  Expression | Noner  tuple[Type, Type]c
                 C  s  t |}t|tr/|jr#| ||}
|
dur#| ||
|}|dur#|S | ||||||||S t|tr?| |||||||S t|t	sI| j
 sO| ||S t|tr]| |||||S t|trtd||ddd| j|	pn|| j
|  d
}|jjd }| |||||||}| ||||||||}|r| j
|| |S t|tr| |j|||||S t|tr| |j|}| ||||||S t|tr| jt|||||||||d	S | j||t	t j!fS )a  Type check a call.

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

        Return (result type, inferred callee type).

        Arguments:
            callee: type of the called value
            args: actual argument expressions
            arg_kinds: contains nodes.ARG_* constant for each argument in args
                 describing whether the argument is positional, *arg, etc.
            context: current expression context, used for inference.
            arg_names: names of arguments (optional)
            callable_node: associate the inferred callable type to this node,
                if specified
            callable_name: Fully-qualified name of the function/method to call,
                or None if unavailable (examples: 'builtins.open', 'typing.Mapping.get')
            object_type: If callable_name refers to a method, the type of the object
                on which the method is being called
        Nr  FTr  r  r  r  r  r  r  z	.__call__r  )"r   r   r   r  rx  r  r   r   check_overload_callr   r  r-  check_any_type_callr   check_union_callr   r   r  rB  r   r   rv  r|  
store_typer   upper_boundr   analyze_type_type_calleer  r   r   not_callabler   r0  )r  ru  rc  rw  r=  rx  r  rq  r<  r  ry  overloaded_resultcall_functionr   r  r   r   r   r|    s    








zExpressionChecker.check_callc	                   s.  |   }|du r|jr|j}t|j}	| r"t|	tr"|	jj	}t|t
r1|j	tv r1|j|fS | rL| jrL|jsLjtj| j| n;| r| jr|js| js| }
i }|
jD ]\}}|tkrw|
|||< qfd||< qfj| j|| | }|rt|jtrd}t |D ]6\}}|tkrqt |}t|t!rt"dd |j#D r|rΈjjd|t$j%d t&t'j(|f  S d}qt)|||j*|j+ fdd	}t|j}	t|	t,r|	j-rt.|j}t/| |j0|d
}|1 rDt"dd |j-D }t2|}3||}|r't)|||j*|j+ fdd	}4| |||||}|rDt)|||j*|j+ fdd	}|5 }|dur|tt6gkrt7|dkr  d }  d }t|t8rt|t8r|j9t:j;kr|j9t:j<kr|j=|j=  kr|j=krn n|j|fS >| ||}?|||||||| j@|| ||||d | rt7|dkrtA|jBdr|j0tCD|d d
}|rjE|| |r|du rjFG|s|durjFH|rI||||| |||	}|j0|d
}|j|fS )zxType check a call that targets a callable value.

        See the docstring of check_call for more information.
        NFc                 s  r  r   r   r   r   r   r   r   r   r         

z8ExpressionChecker.check_callable_call.<locals>.<genexpr>z<Passing multiple variadic unpacks in a call is not supportedr  Tc                   ra  r   rb  rd  rc  r   r   rg    rd  z7ExpressionChecker.check_callable_call.<locals>.<lambda>r3  c                 s  s    | ]
}t |ttfV  qd S r   )r   r   r   r   vr   r   r   r     s    
c                   ra  r   rb  rd  rc  r   r   rg    rd  c                   ra  r   rb  rd  rc  r   r   rg    rd  r   r   r   r<  r   )Jwith_unpacked_kwargswith_normalized_var_argsr/  r   r3  r  r   r   r   r   r^   ry   r  r  from_type_typer  r  r   CANNOT_INSTANTIATE_PROTOCOLrt  is_abstractfallback_to_anyabstract_attributesr6   can_return_noner  !cannot_instantiate_abstract_classvar_argrQ  r   r  r4   rW  r   r  r   r  CALL_ARGr   r   r0  r   rw  rx  r   r  r&   r   copy_modified
is_genericr'   +infer_function_type_arguments_using_contextr)   
param_specr5   ry  r   flavorr   ARGSKWARGSidinfer_arg_types_in_contextcheck_argument_countcheck_argument_typesr|   r,  r   make_normalizedr  r  rR  rS  r^  )r  ru  rc  rw  r=  rx  r  rq  r<  r3  r   r  	attr_nameabstract_statusr  seen_unpackr  arg_kindrG  rm  fresh_ret_typeneed_refreshr  arg1arg2r  new_ret_typer   rc  r   r   f  s  






"

z%ExpressionChecker.check_callable_callr   r  c                 C  s   t jsdS |jD ]<}|j|}|du rq|j}t|tr |j}t|t	r(|j
}t|trD|jdurDt|jts:J tt |jj  S qdS )zIs the given attribute a method with a None-compatible return type?

        Overloads are only checked if there is an implementation.
        FN)rz   strict_optionalmrorI  r  r   r   rZ   implrF   funcrM   r   r   r~   r   r3  )r  r   r  rY  symnoder   r   r   r   r  !  s"   




z!ExpressionChecker.can_return_noner  c                   sN  t trttjdS t tr5tjj}t |tr#|j	dd}t
|}t |tr3|j	g d}|S t trJt fdd D jS t tr|tj }t|}t |tri|j	d}|S t |trztfdd|jD }|S t trtjjd	krt S t trS j  ttjS )
zzAnalyze the callee X in X(...) where X is Type[item].

        Return a Y that we can pass to check_call(Y, ...).
        
source_anyT)r  r  c                   s   g | ]
} t| qS r   )r  r   r   r  r=  r  r   r   rj  L      z>ExpressionChecker.analyze_type_type_callee.<locals>.<listcomp>r  c                   s   g | ]}|j  d qS )r  r  r   c)r  r   r   rj  \      builtins.tuple)r   r   r   from_another_anyr   r   r   r,  r   r  r%   r   r  r4  r   r  r   r  r   r   r   r   r   r   r	  r  unsupported_type_typer0  )r  r  r=  r  expandedru  r   )r=  r  r  r   r  9  s@   











z*ExpressionChecker.analyze_type_type_calleec                 C  s<   g }|D ]}|  |}t|r|t  q|| q|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.
        )rW  has_erased_componentr  r   )r  rc  r  r  rG  r   r   r    infer_arg_types_in_empty_contextg  s   
z2ExpressionChecker.infer_arg_types_in_empty_contextc                 C  s   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  oldr   r   r   $infer_more_unions_for_recursive_typew  s   z6ExpressionChecker.infer_more_unions_for_recursive_typec                 C  s   dgt | }t|D ]&\}}|D ]}||  s0|j| }	| |	}
| || |	||< |
t_qqt|D ]\}}|sE| || ||< q6tdd |D sQJ 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                 s  s    | ]}|d uV  qd S r   r   r  r   r   r   r     r   z?ExpressionChecker.infer_arg_types_in_context.<locals>.<genexpr>)ry  rQ  is_starr  r  rW  r   r  r   r   r
   r   )r  ru  rc  rw  rm  r  re  rZ  airG  r  r   r   r   r   r    s    

z,ExpressionChecker.infer_arg_types_in_contextcallableerror_contextc           	      C  s   | j d }|s	|S t|t }|j}t|r"t|r"t|}t|}t|tr3t|s3t	|s3|
 S t|j||dd}g }|D ]}t|sJt|rP|d q@|| q@| j|||d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   r3  r   r   r   r   r   r   r  r*   r  has_uninhabited_componentr  r  apply_generic_arguments)	r  r  r  r&  
erased_ctxr3  rc  new_argsr  r   r   r   r    s,   
	

z=ExpressionChecker.infer_function_type_arguments_using_contextr  c              
     sD  j  rj   ||}W d   n1 sw   Y   ||t }	g }
t|D ]\}}|	| dkrD|
d q4|
| q4t	|
|||
 j  d\}}d|	v rn ||||||\}jdkrt|dkrt|v st|v rt|d }t|ttfrd|d< n|rtd|sj tj| j jjstfdd	|D r|rt||jj fd
d}t	||||
 j  dd\}||}t |}|durt!dd	 |D rt"| |S t d_#fdd|D }nt$t%j&gtj' }(||S )zInfer the type arguments for a generic callee type.

        Infer based on the types of arguments.

        Return a derived callable type that has the arguments applied.
        Nr   )r=  strictr   dictr   builtins.strc                 3  s<    | ]}|d u pt t|tptt|t j@ V  qd S r   )r   r   r   r   r   r  r  )r  r   r   r   I  s    
zBExpressionChecker.infer_function_type_arguments.<locals>.<genexpr>c                   ra  r   rb  r  rc  r   r   rg  X  rd  zAExpressionChecker.infer_function_type_arguments.<locals>.<lambda>T)r=  r  allow_polymorphicc                 s  s(    | ]}|d uot t|t V  qd S r   )r   r   r   r  r   r   r   r   n  rr  c                   s:   g | ]}|d urt |fddt j D nd qS )Nc                   s   i | ]}|j  qS r   )r  r  )unknownr   r   
<dictcomp>z  r  zNExpressionChecker.infer_function_type_arguments.<locals>.<listcomp>.<dictcomp>)r$   r  r  r  )r  	free_varsr  r   r   rj  w  s    zCExpressionChecker.infer_function_type_arguments.<locals>.<listcomp>))r  r-  r  r  r  get_arg_infer_passesry  rQ  r  r)   argument_infer_context#infer_function_type_arguments_pass2special_sigr2   r5   r   r   r   r   r,  r~   r  r   &KEYWORD_ARGUMENT_REQUIRES_STR_KEY_TYPEr  r  r  r   rw  rx  r  r   
apply_polyr   r   r  r   r   unannotatedr  apply_inferred_arguments)r  r  rc  rw  rx  rm  r  r=  r  arg_pass_nums
pass1_argsre  r  r~  r  	first_argpoly_inferred_argspoly_callee_typeappliedr   )rc  r  r  r  r  r   r)     s   





z/ExpressionChecker.infer_function_type_argumentsold_inferred_argsSequence[Type | None]&tuple[CallableType, list[Type | None]]c	                   s   t |}	tt|	D ]\}
}t|ttfst|rd|	|
< q
||	|}|r6t|||j	|j
 fdd}j  | ||}W d   n1 sNw   Y  t||||| d\}	}||	fS )a^  Perform second pass of generic function type argument inference.

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

        Return (the callee with type vars applied, inferred actual arg types).
        Nc                   ra  r   rb  r  rc  r   r   rg    rd  zGExpressionChecker.infer_function_type_arguments_pass2.<locals>.<lambda>r
  )r  rQ  r   r   r   r   r  r  r   rw  rx  r  r  r  r)   r  )r  r  rc  rw  rx  rm  r  r  r=  r~  re  r  r  r  r   rc  r   r    s8   	
	z5ExpressionChecker.infer_function_type_arguments_pass2r(   c                 C  s   t | jd| jdS )Nr  typing.Iterable)r(   r  r,  r  r   r   r   r    s   z(ExpressionChecker.argument_infer_contextnum_actualsint	list[int]c                 C  s   dg| }t |jD ]^\}}d}	t|j| }
t|
trU|
 rU|| D ]0}t|| }t|trAtd||dd}|durAt|}t|trT|jsTt|| t	sTd}	 nq$|	sh|
t rh|| D ]}d||< qaq
|S )a  Return pass numbers for args for two-pass argument type inference.

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

        Two-pass argument type inference primarily lets us infer types of
        lambdas more effectively.
        r   Fr  T)r  Nr   )rQ  r  r   r   r   r  r   r{   r  rQ   rW  ArgInferSecondPassQuery)r  ru  rc  r  rm  r  r  re  r  skip_param_specp_formalri  p_actualcall_methodr   r   r   r    s2   

	
z&ExpressionChecker.get_arg_infer_passesr~  c                 C  sT   t |D ]\}}|rt|r"| j||d | ttjgt| }q| |||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   r0  ry  r  )r  r  r~  r=  re  inferred_typer   r   r   r    s   
z*ExpressionChecker.apply_inferred_argumentsactual_typesactual_kindsactual_namesContext | Nonec	                 C  s  |du rt ttj}i }	|D ]}
|
D ]}|	|dd |	|< qq| |||||	|\}}t|jD ]\}}| rn|| sn|sn|	 r\| j
||| |r[|r[d|v r[| ||| n|j| pbd}| j
||| d}q2| st|| ||r| j stt||| d  tr| j
||| d}q2| r|| r||| d  tjtjfvr| j
|| d}q2| dur|| s| j
||| d}q2|S )aO  Check that there is a value for all required arguments to a function.

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

        Return False if there were any errors. Otherwise return True
        Nr   r   r   ?F)rg   r   r   r)  r   check_for_extra_actual_argumentsrQ  rw  is_requiredis_positionalr  too_few_argumentsmissing_classvar_callable_noterx  missing_named_argumentr  is_duplicate_mappingr  r-  r   r   r   duplicate_argument_valueis_namedr   r2   r5   too_many_positional_argumentsr  )r  ru  r  r  r  rm  r=  r<  rq  all_actualsrZ  r  okis_unexpected_arg_errorre  kindargnamer   r   r   r  	  sR   

z&ExpressionChecker.check_argument_countr  tuple[bool, bool]c                 C  s4  d}d}t |D ]\}	}
|	|vrO|
tjkst||	 rO|
tjkrOd}|
tjkr/| j|| q|s5J d||	 }|dus?J ||	 }| j|||| d}q|
tjkrZtj|j	vs_|
tjkrt
||	 }t|ttfr||	dt|jk r|
tjkst|ts| j|| n
| j||| d}d}q||fS )zCheck for extra actual arguments.

        Return tuple (was everything ok,
                      was there an extra keyword argument error [used to avoid duplicate errors]).
        FTz/Internal error: named kinds without names givenNr   )rQ  r   r4   is_non_empty_tupler5   r2   r  too_many_argumentsunexpected_keyword_argumentrw  r   r   r   r   r  ry  r   "too_many_arguments_from_typed_dict)r  ru  r  r  r  r  r=  r  r  re  r  act_nameact_typeactual_typer   r   r   r  J	  s:   


z2ExpressionChecker.check_for_extra_actual_argumentsc                 C  s   t |tr8t |tr:|jddd\}}|j|}|d ur<t |jtr>|jjs@|jj	sB| j
d| d| d S d S d S d S d S d S d S )Nr   r   )maxsplitr  zN" is considered instance variable, to make it class variable use ClassVar[...])r   r   r   r   r   r  r   rp   r  is_classvarr  note)r  r<  rq  r=  r  var_namer   r   r   r   r  	  s   
z0ExpressionChecker.missing_classvar_callable_note	check_argArgChecker | Nonec	                   sH  |p| j }t|  }	t|D ]\}
}t|j|
 }d} fdd|D }t|dkrt|d  }t|trt|j	dkrt|j	d t
r|tjgtjgt|d   kr|j	d gfdd|dd D  }t|t
rt|j}t|tr|j	sJ |j	}tjgtjgt|j	d   }d}|sefd	d|D }t|t
rTt|j}t|tr$t|j	du r|j	}tgt| }n|j	 }t|t
sJ t|j}t|tr|j	}fd
dtt|j	D }nyt|tsJ |jjdksJ |j	d |jd gt|t|j	 d   |j	d d  }tgt| }nAt|tr1|g}tg}n4t|ts9J |jjdksBJ |jd gt| }tgt| }n|gt| }|j|
 gt| }t|t|  krxt|ks{J  J t|t|krt|t|kr| jj|| n	| jj||d qt|t|ksJ t|t|ksJ t|||||D ]b\}}}}}|du r̐q|tjkr| |s| j|| |tjkr| |st|| j d}| j!||| |	j"|||j#|
 |t|t
d}||||||d |
d |||| |
 qqdS )zCheck argument types against a callable type.

        Report errors if the argument types are not compatible.

        The check_call docstring describes some of the arguments.
        Fc                      g | ]} | qS r   r   r  )rw  r   r   rj  	  r  z:ExpressionChecker.check_argument_types.<locals>.<listcomp>r   r   c                   r/  r   r   r  r  r   r   rj  	  r  NTc                   r/  r   r   r  r0  r   r   rj  	  r  c                   s   g | ]
}| kr
t ntqS r   )r3   r4   rl  )inner_unpack_indexr   r   rj  	  r  r   _typeshed.SupportsKeysAndGetItem)allow_unpack)$r-  r   r  rQ  r   r  ry  r   r   r   r   r   r4   r3   r   r   r   r  r   r   rc  rw  r  r  r#  r  r  is_valid_var_arginvalid_var_argr5   is_valid_keyword_var_argr~   r,  invalid_keyword_var_argexpand_actual_typerx  )r  r  rw  rc  ru  rm  r=  r-  r<  mapperre  rZ  orig_callee_arg_typeexpanded_tupler  p_actual_typer  p_callee_typecallee_arg_typescallee_arg_kindsunpacked_typeinner_unpackinner_unpacked_typer[  r(  actual_kindcallee_arg_typecallee_arg_kind
is_mappingexpanded_actualr   )rw  r  r1  r   r  	  s   
	 &










,

z&ExpressionChecker.check_argument_typescaller_typeoriginal_caller_typecaller_kindr;   rP  mouter_contextc              
   C  s   t |}t |}t |}t|tr| j||	 dS | ||r)| j||	 dS t||| jj	dsZ| jj
|||||||	|
d}| jj|||	|d | j s\| j|||	| dS dS dS )z.Check the type of a single argument in a call.)r  )r<  r=  rL  r  N)r   r   r   r  deleted_as_rvaluehas_abstract_type_partconcrete_only_callr~   r  r  incompatible_argumentincompatible_argument_noteprefer_simple_messagescheck_possible_missing_await)r  rH  rI  rJ  r  rP  rK  ru  r<  r=  rL  r  r   r   r   r-  "
  s2   


zExpressionChecker.check_argc                   s  |  } |} ||||}	d}
d} ||	}d}t fdd|D rqz$ j   |	||||||||	}W d   n1 sFw   Y  W n tyW   d}Y nw |rqt	| \}}t
t||j|j t|f} |	|||||||}|dur|durt|d |d rtt|d ts|s|S |S |dur|S |dur|S  |	|||||}
t|
dkr|
d }nttj}t|sd}ntj} jj||||d  j|||||||d}|r|s jt j!| |S )	z(Checks a call to an overloaded function.NFc                 3  r  r   )
real_unionr   r  r  r   r   r   j
  r  z8ExpressionChecker.check_overload_call.<locals>.<genexpr>Tr   r  rq  r<  )"r  r  plausible_overload_call_targetspossible_none_type_var_overlapr  r  r  union_overload_resultr   r  r   r  r4  r5  combine_function_signaturesr   infer_overload_return_typer~   r   r   r   overload_erased_call_targetsry  r   r0  is_operator_methodr  OPERATORno_variant_matches_argumentsr|  r  r  r   TOO_MANY_UNION_COMBINATIONS)r  ru  rc  rw  rx  rq  r<  r=  r  plausible_targetserased_targetsunioned_resultnone_type_var_overlapunion_interruptedunioned_returnreturnsinferred_typesinferred_resultrZ  r  r   r   r  r   r  J
  s   
	


z%ExpressionChecker.check_overload_callr   list[CallableType]c              
     s  ddd}g }g }d}d}	t | D ]\}
}|
tkr ||s d}|
tkr*||s*d}	q|jD ]V}t|||j|j fd	d
}| j 9 |	 durP|
| n%| | |||dru|re|jre|
| n|	rp|jrp|
| n|
| W d   n1 sw   Y  q.|| S )aD  Returns all overload call targets that having matching argument counts.

        If the given args contains a star-arg (*arg or **kwarg argument, including
        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.rQ  r   r   r   c                 S  s(   t | } t| ttfpt| to| jjS r   )r   r   r   r   r   r   is_named_tupler{  r   r   r   	has_shape
  s   zDExpressionChecker.plausible_overload_call_targets.<locals>.has_shapeFTc                       |  S r   r   rd  r0  r   r   rg  
      zCExpressionChecker.plausible_overload_call_targets.<locals>.<lambda>NrQ  r   r   r   )r  r4   r5   r   r   rw  rx  r  r  r  r  r  
is_var_arg	is_kw_arg)r  r  rw  rx  r   rl  matchesstar_matchesargs_have_var_argargs_have_kw_argr  rQ  rm  r   r0  r   rW  
  s<   




z1ExpressionChecker.plausible_overload_call_targetsra  c	                 C  s  g }	g }
g }t tt|}g }|D ]{}| j| jju sJ | j +}| j }| j|||||||d\}}W d   n1 s@w   Y  W d   n1 sOw   Y  |  }|r|si| j	| ||f  S t
|}t|trx|	| n|	| |
| || || q|	sdS t|	|
|||rt|
r| j	|d  |
d |d fS tdd |
D r| j	|d  t|
d t|d fS | jttj||||||dS | j	|d  |
d |d fS )a  Attempts to find the first matching callable from the given list.

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

        Assumes all of the given targets have argument counts compatible with the caller.
        )ru  rc  rw  rx  r=  rq  r<  Nr   c                 S  s   g | ]}t |qS r   )r   r   rQ  r   r   r   rj  K  r  z@ExpressionChecker.infer_overload_return_type.<locals>.<listcomp>)r  maphas_any_typer  r  r  r  r|  r}  store_typesr   r   r   r  any_causes_overload_ambiguityall_same_typesr   r   r   r)  )r  ra  rc  r  rw  rx  rq  r<  r=  rr  return_typesrh  args_contain_any	type_mapsrQ  wrK  r3  
infer_typeis_matchp_infer_typer   r   r   r[  	  sl   





z,ExpressionChecker.infer_overload_return_typec           	   	   C  s0   g }|D ]}|  ||||||r|| q|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  ra  r  rw  rx  rc  r=  rr  rQ  r   r   r   r\  ]  s   
z.ExpressionChecker.overload_erased_call_targetsc                   s   |r|sdS d}t |D ]}t|tsqt |jD ]}t|tr$d} nqq|s*dS tdd |D }t|D ] t fdd|D rRt fdd|D rR dS q7dS )a  Heuristic to determine whether we need to try forcing union math.

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

            x: int | None
            foo(x)
        we want this call to infer list[int] | None, not list[int | None].
        FTc                 s  s    | ]}t |jV  qd S r   )ry  r  r  r   r   r   r     r  zCExpressionChecker.possible_none_type_var_overlap.<locals>.<genexpr>c                 3  $    | ]}t t|j  tV  qd S r   )r   r   r  r   r  rd  r   r   r         
c                 3  r  r   )r   r   r  r   r  rd  r   r   r     r  )r   r   r   r   r   minr  r  )r  r  ra  has_optional_argrG  r  
min_prefixr   rd  r   rX  r  s4   

z0ExpressionChecker.possible_none_type_var_overlapr   rd  levellist[tuple[Type, Type]] | Nonec                 C  s  |
t krtt|D ]\}}| |r n,q
| || | ||||||||	}W d   n1 s3w   Y  |dur?|gS dS |sw| || | ||||||||	}W d   n1 s`w   Y  |durwtt|d tt	fsw|gS t|| }t|tsJ g }|
 D ]&}| }|||< | |||||||||	|
d 
}|dur|| q dS t }g }|D ]}||vr|| || q|S )a  Accepts a list of overload signatures and attempts to match calls by destructuring
        the first union.

        Return a list of (<return type>, <inferred variant type>) if call succeeds for every
        item of the desctructured union. Returns None if there is no match.
        Nr   r   )r   r   rQ  rT  type_overrides_setr[  r   r   r   r   r  copyrY  r3  r   r   r  )r  ra  rc  r  rw  rx  rq  r<  rd  r=  r  idxrQ  r  directfirst_union	res_itemsr  new_arg_types
sub_resultseenr   pairr   r   r   rY    s   



z'ExpressionChecker.union_overload_resultc                 C  s"   t |}t|tot| dkS r  )r   r   r   ry  r  r  rQ  r   r   r   rT    s   zExpressionChecker.real_unionexprsSequence[Expression]	overridesSequence[Type]Iterator[None]c              	   c  sh    t |t |ksJ t||D ]	\}}|| j|< qzdV  W |D ]}| j|= q!dS |D ]}| j|= q,w )z5Set _temporary_ type overrides for given expressions.N)ry  r  r  )r  r  r  r   rQ  r   r   r   r    s   

z$ExpressionChecker.type_overrides_setr   list[ProperType]AnyType | CallableTypec                 C  s  |sJ dt dd |D sttjS td|}t|dkr#|d S t|\}}dd tt|d jD }t	|d j
}g }d	}|D ]M}t|t|j
krSd
} n?tt||j
D ]\}	\}
}|
|krfq[|
 rs| rst||	< q[d
} |rz nt|jD ]\}	}||	 | q||j qDt|}|rttj}|d j||gttgddg||d
dS g }|D ]}t|}|| q|d j||||d
dS )aL  Accepts a list of function signatures and attempts to combine them together into a
        new CallableType consisting of the union of all of the given arguments and return types.

        If there is at least one non-callable type, return Any (this can happen if there is
        an ambiguity because of Any in arguments).
        zTrying to merge no callablesc                 s  r  r   r   r   r  r   r   r   r     r  z@ExpressionChecker.combine_function_signatures.<locals>.<genexpr>rj  r   r   c                 S  rL  r   r   rM  r   r   r   rj  +  rh  zAExpressionChecker.combine_function_signatures.<locals>.<listcomp>FTN)r  rw  rx  r3  r  r  )r  rw  r3  r  r  )r   r   r   r)  r   ry  #merge_typevars_in_callables_by_namer  r  r  rw  rQ  r  r  r3   r  r3  r   r  r4   r5   )r  r   	callablesr  r  	new_kindsnew_returnstoo_complexrZ  re  new_kindtarget_kindr  union_returnr  
final_args	args_listnew_typer   r   r   rZ    sb   



	z-ExpressionChecker.combine_function_signaturesc           	   	     s   t |||j|j fdd}| j  | | |||ds'	 W d   dS W d   n1 s1w   Y  ddd}z| j ||||||d W dS  tyT   Y dS w )z^Determine whether arguments could match the signature at runtime, after
        erasing types.c                   rm  r   r   rd  r0  r   r   rg  n  rn  z?ExpressionChecker.erased_signature_similarity.<locals>.<lambda>NFrH  r   original_ccaller_typerJ  r;   r  rP  r  rK  ru  r   r<  r  r=  rE   rL  r   r  c
           
      S  s   t | |std S r   )arg_approximate_similarityr   )
rH  r  rJ  r  rP  rK  ru  r<  r=  rL  r   r   r   r-  x  s   
z@ExpressionChecker.erased_signature_similarity.<locals>.check_arg)r=  r-  T)rH  r   r  r   rJ  r;   r  r   rP  r  rK  r  ru  r   r<  r  r=  rE   rL  rE   r   r  )r   rw  rx  r  r  r  r  r   )	r  r  rw  rx  rc  ru  r=  rm  r-  r   r0  r   r  b  s4   
	z-ExpressionChecker.erased_signature_similarityr  c                 C  s   t j||| jj||dS )z=Simple wrapper around mypy.applytype.apply_generic_arguments.r  )r   r  r  incompatible_typevar_value)r  r  r   r=  r  r   r   r   r    s   z)ExpressionChecker.apply_generic_argumentsc                 C  sL   |  | t|}t|trttj|dttj|dfS ttjttjfS )Nr  )r  r   r   r   r   r  r)  )r  rc  ru  r   r   r   r    s   

z%ExpressionChecker.check_any_type_callc                   s^   j    fdd| D }W d    n1 sw   Y  tdd |D |fS )Nc              	     s   g | ]} | qS r   )r|  )r   subtyperw  rx  rc  r=  r  r   r   rj    s    z6ExpressionChecker.check_union_call.<locals>.<listcomp>c                 S  r  r  r   )r   r  r   r   r   rj    r  )r  disable_type_namesr  r   )r  ru  rc  rw  rx  r=  resultsr   r  r   r    s   z"ExpressionChecker.check_union_callr  c                 C  s*   | j jt| | ||}| ||S )z'Visit member expression (of form e.id).)r  r  r   r   analyze_ordinary_member_accessr  )r  r  r  r   r   r   r   visit_member_expr  s   z#ExpressionChecker.visit_member_exprc                 C  s   |j dur
| |S | j|j| jd}|j}d}t|tr't|jtr'|jj	}t|tr;t|jt
r;|jjp9|jj}nd}t|j|||dd| j|| j|  ||d}|S )z+Analyse member expression or member lvalue.Nr\  F)	r  r  r  r  r  r  r  module_symbol_tabler,  )r  r  rW  r   r  r   r^   r   rU   rI  rp   r,  is_clsr   r/  r  r  rB  )r  r  r  r  rY  r  r,  member_typer   r   r   r    s2   

z0ExpressionChecker.analyze_ordinary_member_access	base_typec                 C  s$   t |||ddd| j|| j|  d
S )z}Analyse member access that is external, i.e. it cannot
        refer to private definitions. Return the result type.
        Fr  )r   r  r  rB  )r  r  r  r=  r   r   r   analyze_external_member_access  s   z0ExpressionChecker.analyze_external_member_accessc                 C  s   t | jd S )Nr$  )r   r  r  r   r   r   rB       z$ExpressionChecker.is_literal_contextr  r   fallback_namec                 C  s:   |  |}|  rt||dS |jt|||j|jdd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  rn  )r  rn  r4  r5  )rC  )r,  rB  r   r  r4  r5  )r  r  r  rQ  r   r   r   rD    s   
z)ExpressionChecker.infer_literal_expr_typeleftr   rightc                 C  s2   t |jrt |jrJ t|j|j | ddS )z$Concatenate two fixed length tuples.r  )r   rn  )r   r   r   r,  )r  r  r  r   r   r   concat_tuples  s   zExpressionChecker.concat_tuplesrP   c                 C     |  |jdS )z(Type check an integer literal (trivial).builtins.intrD  r  r  r  r   r   r   visit_int_expr&     z ExpressionChecker.visit_int_exprrd   c                 C  r  )z&Type check a string literal (trivial).r  r  r  r   r   r   visit_str_expr*  r  z ExpressionChecker.visit_str_exprr?   c                 C  r  )z%Type check a bytes literal (trivial).r   r  r  r   r   r   visit_bytes_expr.  r  z"ExpressionChecker.visit_bytes_exprrL   c                 C  
   |  dS )z%Type check a float literal (trivial).zbuiltins.floatr,  r  r   r   r   visit_float_expr2     
z"ExpressionChecker.visit_float_exprrC   c                 C  r  )zType check a complex literal.zbuiltins.complexr  r  r   r   r   visit_complex_expr6  r  z$ExpressionChecker.visit_complex_exprrI   c                 C  r  )zType check '...'.zbuiltins.ellipsisr  r  r   r   r   visit_ellipsis:  r  z ExpressionChecker.visit_ellipsisrY   c                 C  sZ  |j r	| |j S |jdks|jdkr| ||S |jdkr)t|jtr)| |S |jdkrLt|jtr=| j	
|j|jS t|jtrL| j	
|j|jS | |j}t|}t|tr|jdkr|jjd}|r|jdkrt| |j}t|tr|jjd}|d	u rt|jd	u st|jd	u r| ||S nEt| jjjv rt|tr| j|r|jd}|d	u r|jjjd
krt|jd	u r| j||}| jd
|g}|j|jt|g dS t }	|jdkrt!|drt| |j}t|t"rt#}	t|t"rt| |j}t!|drt$}	t| jjjv rW|jdkrWt|trW|jjd
krWt| |j}t|trW|jjjd
krWt|jd	u rW|jt|g|j dS |jt%j&v rt%j&|j }
|	t'j(u sp|	t'j)u r| j*|
||j||	t'j(u d\}}n|	t'j+u r| j*t%j,|
 | |j|j|dd\}}nt-|	 ||_.|S t/d|j )z(Type check a binary operator expression.andor*%+__add__zbuiltins.tuple.__add____radd__Nr  r  |r4  )r  r  r=  allow_reverseFzUnknown operator )0rT  rW  opcheck_boolean_opr   r  rS   check_list_multiplyr?   r
  check_str_interpolationr  rd   r   r   partial_fallbackr   r  r   r   r   r  rs   r  r  enable_incomplete_featurer   type_is_iterableiterable_item_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_methodrE  r  use_reversemethodr   r  r   r   r   visit_op_expr>  s   






	zExpressionChecker.visit_op_exprrB   c                 C  s  d}t |j|jdd |jD ]\}}}| |}|dks#|dkr0| |}|du r1| |}t|}|g}t|trCt|	 }| 
 }	g }
g }d}d}|D ]}| jjdd}| jd||gtg||d	\}}| j|}W d   n1 szw   Y  t|trd}qQ| r| |r| jjdd}| j||\}}W d   n1 sw   Y  | r| j|  d}qQt|gtjgdg| 
 | d
}|j| || qQ| s|r|
| |j| qQ| j|  d}qQ|s/|s/t|}t||s/|
s| jd||| nt|
}| j|||ddr/| j||d| n|tj v rtj | }t!| jj"}| j#||||dd\}	}|j| W d   n	1 s_w   Y  | s|dv r| |}| ||rt$|}t$|}| j||d| n9|dks|dkr| |}| 
 }	| ||rt$|}t$|}| j||d| |jd nt%d| |du r|	}qt&'||	}q|dusJ |S )zType check a comparison expression.

        Comparison expressions are type checked consecutive-pair-wise
        That is, 'a < b > c == d' is check as 'a < b and b > c and c == d'
        Nr   inznot inFTsave_filtered_errors__contains__)r  r  rc  rw  r=  r  r#  )original_containerprefer_literal	container)r  )z==z!=equalityiszis notidentityzUnknown comparison operator )(r  operandsr   rW  find_partial_type_ref_fast_pathr   r   r   r  r  	bool_typer  r  check_method_call_by_namer3   r  analyze_container_item_typer   r}  r4  -analyze_iterable_item_type_without_expression
add_errorsfiltered_errorsr   r   r,  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_typerE  container_errorsr  r  	cont_typeiterable_errorsitertypeiterable_typecontainer_typer  r  r   r   r   visit_comparison_expr  s   &
















z'ExpressionChecker.visit_comparison_exprc                 C  sV   t |tsdS t |jtr)| |j|}t |tr)|jdur)| j|t	| |S dS )zIf expression has a partial generic type, return it without additional checks.

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

        Otherwise, return None.
        N)
r   r^   r   rp   r*  r   r   r  r  r   )r  r   r   r   r   r   r  @  s   
z1ExpressionChecker.find_partial_type_ref_fast_pathT)r  
seen_typesr  r  r  set[tuple[Type, Type]] | Noner  c          
      C  sZ  | j jjsdS |du rt }||f|v rdS |||f t||f\}}t|ds/t|dr1dS |r;t|}t|}| j j	 rCdS t
|tsMt
|trOdS t
|trit
|trit|}t|}t||f\}}|rut|rut|rudS t
|tr	t
|tr	|jj}|jj}|tv r|tv r| j d}t||}t||}| j|jd |jd |dS |jdr|jdr| j d}	t||	}t||	}| j|jd |jd |dp| j|jd |jd |dS |d	v r||kr| j|jd |jd |dS |tv r	|tv r	dS t
|tr%t
|tr%t
|jtr%t
|jtr%dS t||dd
 S )a  Check for dangerous non-overlapping comparisons like 42 == 'no'.

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

        Rules:
            * X and None are overlapping even in strict-optional mode. This is to allow
            'assert x is not None' for x defined as 'x = None  # type: str' in class body
            (otherwise mypy itself would have couple dozen errors because of this).
            * Optional[X] and Optional[Y] are non-overlapping if X and Y are
            non-overlapping, although technically None is overlap, it is most
            likely an error.
            * Any overlaps with everything, i.e. always safe.
            * Special case: b'abc' in b'cde' is safe.
        FN__eq__ztyping.AbstractSetr   )r  r  r   )r1  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  rc  r  r   r   r  r   r-   )
r  r  r  r  r  r  	left_name
right_nameabstract_setabstract_mapr   r   r   r  P  sx   




z&ExpressionChecker.dangerous_comparisonr  c                 C  sh   |p|}t |}t|tr| ||||||S t|||ddd| j||| j|  d}| ||||||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  rB  check_method_call)r  r  r  rc  rw  r=  r  r  r   r   r   r    s(   
z+ExpressionChecker.check_method_call_by_namec              
   C  s|   g }g }|  D ]-}	| j  | ||	||||\}
}W d   n1 s&w   Y  ||
 || qt|t|fS )a  Type check a call to a named method on an object with union type.

        This essentially checks the call using check_method_call_by_name() for each
        union item and unions the result. We do this to allow plugins to act on
        individual union items.
        N)r  r  r  r  r  r   )r  r  r  rc  rw  r=  r  r  meth_resrQ  r  	meth_itemr   r   r   r    s   

z1ExpressionChecker.check_union_method_call_by_namer  c           	      C  sH   |  ||}|dur|nd}| j||||||d}| j||||||dS )zType check a call to a method with the given name and type on an object.

        Return tuple (result type, inferred method type).
        Nr  rV  )r  rv  r|  )	r  r  r  r  rc  rw  r=  rq  r<  r   r   r   r    s   z#ExpressionChecker.check_method_callop_namer  	left_exprr   
right_exprc              
     s  d fdd}ddd}t |}t |}t|tr%ttj|d}	|	|	fS t|tr5ttj|d}	|	|	fS tj| }
|||}||
|}|tjv rUt||rU|||fg}n<t	||rt|t
rt|t
r|jjd urr|jjj|ju s||||||
kr|||f|||fg}n
|||f|||fg}dd |D }g }g }|D ]<\}}}jjdd}||||gtg }W d    n1 sw   Y  | r||  || q|  S t|t
r|jjst|t
r|jjrttj}	|	|	fS |s0jjdd}|||gtg }W d    n	1 sw   Y  | r.||  || n|S j|d  t|dkrC|d S ttj}||f}|S )Nr  r  r  r   r   r  c                   sr    || sdS j "}t| |ddd| jj d
}| r&dn|W  d   S 1 s2w   Y  dS )zYLooks up the given operator and returns the corresponding type,
            if it exists.NFT)
r/  rQ  r  r  r  r  r=  r  r  r  )
has_memberr  r  r   r  rB  r}  )r  r  r  r  r  r   r   lookup_operator)  s"   $z>ExpressionChecker.check_op_reversible.<locals>.lookup_operatorrQ  r   r  r  c                 S  s(   | j jD ]}|j|r|j  S qdS )a  Returns the name of the class that contains the actual definition of attr_name.

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

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

            If the attr name is not present in the given class or its MRO, returns None.
            N)r   r  rI  r  r   )rQ  r  clsr   r   r   lookup_definerC  s
   
z=ExpressionChecker.check_op_reversible.<locals>.lookup_definerr  c                 S  s$   g | ]\}}}|d ur|||fqS r   r   )r   r  objr  r   r   r   rj    s   $ z9ExpressionChecker.check_op_reversible.<locals>.<listcomp>Tr  r   r   )r  r  r  r   r   r  )rQ  r   r  r  r   r  )r   r   r   r   r  r   r  op_methods_that_shortcutr}   r~   r   r   alt_promoter  r  r  r3   r}  r  r  r  r)  r  r  ry  r0  )r  r  r  r  r   r  r=  r   r"  any_typerev_op_nameleft_opright_opvariants_rawvariantsr  r  r  r#  r  local_errorsr   	error_anyr   r  r   check_op_reversible   sx   	










z%ExpressionChecker.check_op_reversibler  r  c                   sb  |r%|g}t |}t|trtt| }| |}g }g }	| j (}
|D ]}| j	||t
| d|| d\}}|| |	| q(W d   n1 sPw   Y  |
 set|}t|	}||fS ||fg}t |}t|tr fddt| D }g }g }	| jjdd/}
|D ]$}|D ]\}}| j	||t
| d|| d\}}|| |	| qqW d   n1 sw   Y  |
 r| j|
  |
 d }t
t }|j|_|j|_t|d	krt|d	kr| j| n!t|d	kr| jjd
||d nt|d	kr| jjd||d t|}| t|	}||fS | j|||gtg dS )zType check a binary operation which maps to a method call.

        Return tuple (result type, inferred operator method type).
        r
  )r  r  r  r   r  r=  Nc                   s   g | ]
}|t | d fqS )r
  )rg   r  r
  r   r   rj    r  z.ExpressionChecker.check_op.<locals>.<listcomp>Tr  r$  r   LeftRight)r  r  rc  rw  r=  )r   r   r   r  r   r  rW  r  r  r.  rg   r  r}  r   r  r  r   r4  r5  ry  "warn_both_operands_are_from_unionswarn_operand_was_from_unionrZ  r   r  r3   )r  r  r  r  r=  r  left_variantsr   all_resultsall_inferredr,  left_possible_typer   r  results_finalinferred_finalright_variantsright_possible_typer  r  recent_contextr   r
  r   r    s   













zExpressionChecker.check_opc                 C  s  | j d }| |j|}t| |j|d}|jdv sJ |jr%d}i }n&|jr.i d}}n|jdkr=| j|j\}}n|jdkrK| j|j\}}t	j
| jjjv rc|du rc|jsc| j|j|j | j rx|du rx|jsx| j|j|j | jj|du d | ||j|}W d   n1 sw   Y  |du r|du rt S |du r|dusJ |S |du r|dusJ |S |jdkrt|}	|j }
n|jdkrt|}	|j }
t|	tr|S |
r|S t|	|gS )z/Type check a boolean operation ('and' or 'or').r$  rA  )r  r  Nr  r  )r  )r  rW  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  r=  r&  r  expanded_left_typeleft_map	right_mapr   restricted_left_typeresult_is_leftr   r   r   r  C  s`   
	





z"ExpressionChecker.check_boolean_opc                 C  s`   |  |j}t|| dr| j |j| jd d}n|  |j}| d||j|\}}||_|S )zzType check an expression of form '[...] * e'.

        Type inference is special-cased for this common construct.
        r  r$  r  __mul__)rW  r  r~   r,  r  r  r  r  )r  r  r   r  r   r  r   r   r   r    s   z%ExpressionChecker.check_list_multiplyr=   c                 C  sR   |  |j}| j|j|j | j| t|s!| j|j| | |j |S r   )	rW  r  r  check_assignmentrZ  check_finalr  r  r  )r  r  r  r   r   r   visit_assignment_expr  s   z'ExpressionChecker.visit_assignment_exprro   c                 C  s`   |  |j}|j}|dkr|  }| j||j |S tj| }| ||g g |\}}||_	|S )z7Type check an unary operation ('not', '-', '+' or '~').not)
rW  r   r  r  r  check_for_truthy_typer   unary_op_methodsr  r  )r  r  operand_typer  r   r  r  r   r   r   visit_unary_expr  s   
z"ExpressionChecker.visit_unary_exprrO   c                 C  sD   |  |}| ||}t|}|  r t|tr |jdur |j}|S )zgType check an index expression (base[index]).

        It may also represent type application.
        N)visit_index_expr_helperr  r   rB  r   r   rC  )r  r  r   p_resultr   r   r   visit_index_expr  s   

z"ExpressionChecker.visit_index_exprc                 C  s*   |j r	| |j S | |j}| ||S r   )rT  rW  rY  visit_index_with_type)r  r  r  r   r   r   rU    s   z)ExpressionChecker.visit_index_expr_helperProperType | Nonec                   s2   j }t|}| t|tr tdd |jD r t|i }t|tr:p(|t	 fdd|
 D ddS t|trj rt|trO||S |}|durg }|D ]9}||}|durn|| q\jtj  tdd |jD r|}	jd	|	   ttj  S t	|S ||S t|tr| j d
 S t|tr| r| j rƈ!|  j  S jj"j#dkr| j$s| j%dkrވ&dS t|t'r(|j)ds*|j) S t|t+r|j,j%dkr&dS j-d| j gt.g d\}
}| _/|
S )zAnalyze type of an index expression for a given type of base expression.

        The 'original_type' is used for error messages (currently used for union types).
        c                 s  r  r   r  r   r   r   r   r     r  z:ExpressionChecker.visit_index_with_type.<locals>.<genexpr>c                   s   g | ]	} | qS r   )rX  rv  r  r  r  r   r   rj    s    z;ExpressionChecker.visit_index_with_type.<locals>.<listcomp>F)contract_literalsNc                 s  r  r   r  r  r   r   r   r     r  zVariadic tuple can have length r   )   	   r   ztypes.GenericAlias__getitem__r>  r  )0r8  r   rW  r   r   r  r   r$   r   r   r  r  r-  rb   visit_tuple_slice_helpertry_getting_int_literalsvisit_tuple_index_helperr  r  r   TUPLE_INDEX_OUT_OF_RANGEmin_tuple_lengthr+  r   r   r0  nonliteral_tuple_index_helperr   visit_typeddict_index_exprr   r  r  r  visit_enum_index_exprr  python_versionr  r   r,  r   r  r  rX  r   r   r  r3   r  )r  r  r  r  r8  nsoutrP  r  min_lenr   r  r   rZ  r   rX    sj   










z'ExpressionChecker.visit_index_with_typec                 C  s^   t |j}|d u r| S |j| }t|tsJ t|jtr)| d |jj S | d S r  )r   r   lengthr   r   r   r   rj  )r  r  unpack_indexunpackr   r   r   rc    s   

z"ExpressionChecker.min_tuple_lengthc           	   	   C  s  t |j}|d u r+|dk r|t|j7 }d|  kr!t|jk r)n d S |j| S d S |j| }t|ts7J t|j}t|tr[t|j}t|t	sMJ |jj
dksUJ |jd }nt|t	sbJ |jj
dksjJ |jd }| ||  d }|dkr|| |krd S ||k r|j| S t|g|j|d t|| d |d   |j|jS || |7 }|dk rd S ||| kr|j|| d  S t|jt||| |g |j|jS )Nr   r  r   r   )r   r   ry  r   r   r   r   r   r  r   r   rc  rc  rk  r   r  maxr4  r5  r  )	r  r  rP  rl  rm  unpackedboundmiddleextra_itemsr   r   r   ra  '  sP   







" z*ExpressionChecker.visit_tuple_index_helperslicrb   c                 C  s   d g}d g}d g}|j r| |j }|d u r| ||S |}|jr3| |j}|d u r1| ||S |}|jrH| |j}|d u rF| ||S |}g }	t|||D ])\}
}}|j|
||| dd}|d u ru| j	
tj| ttj  S |	| qQt|	S )Nr  rn  )begin_indexr`  rd  	end_indexstride	itertoolsproductslicer,  r  r  r   !AMBIGUOUS_SLICE_OF_VARIADIC_TUPLEr   r   r0  r  r   )r  r  rs  beginendrw  	begin_rawend_raw
stride_rawr   br  sr  r   r   r   r_  W  s4   z*ExpressionChecker.visit_tuple_slice_helperr8  list[int] | Nonec                 C  s   t |tr	|jgS t |tr2|jdkr!|j}t |tr!d|j gS |jdkr2|j}t |tr2|jgS t| |}t |trF|j	durF|j	}t |t
rUt |jtrU|jgS t |trzg }t|jD ]}t |t
rut |jtru||j qa dS |S dS )a  If the given expression or type corresponds to an int literal
        or a union of int literals, returns a list of the underlying ints.
        Otherwise, returns None.

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

        1. 'expr' is a IntExpr or a UnaryExpr backed by an IntExpr
        2. 'typ' is a LiteralType containing an int
        3. 'typ' is a UnionType containing only LiteralType of ints
        -r$  r  N)r   rP   r  ro   r  r   r   rW  r   rC  r   r  r   r   r   r  )r  r8  operandrQ  ri  r  r   r   r   r`  w  s0   






z*ExpressionChecker.try_getting_int_literalsc                 C  s@   | j d||gtg|d | |}t|tr| jd|gS |S )Nr^  r
  r  )r  r3   union_tuple_fallback_itemr   rb   r  r;  )r  r  r8  unionr   r   r   rd    s
   

z/ExpressionChecker.nonliteral_tuple_index_helperc                 C  sv   g }|j D ]1}t|tr1t|j}t|trt|j}t|tr/|jjdkr/|	|j
d  qt|	| qt|S )Nr  r   )r   r   r   r   r   r   r  r   r   r  rc  NotImplementedErrorr   )r  r  r   r  r@  r   r   r   r    s   




z+ExpressionChecker.union_tuple_fallback_itemtd_typesetitemtuple[Type, set[str]]c                 C  s  t |tr
|jg}nTt| |}t |trt|j}n|g}g }t|D ]8}t |t	r4|j
d ur4|j
}t |trMt |jtrM|jjjdkrM||j q%| j|| ttjt f  S g }|D ]$}	|j|	}
|
d u r| j||	|| ttjt f  S ||
 qbt|t|fS )Nr   )r   rd   r  r   rW  r   r  r   r   r   rC  r   r  rn  r   r   r  r  $typeddict_key_must_be_string_literalr   r   r0  r   r  typeddict_key_not_foundr   )r  r  r8  r  	key_namesrQ  	key_typesr  value_typeskey_namer  r   r   r   re    s4   



z,ExpressionChecker.visit_typeddict_index_expr	enum_typec                 C  s.   |  d}| j| |||dd t|g S )Nr  zEnum index should be a stringzactual index type)r,  r  check_subtyperW  r   )r  r  r8  r=  string_typer   r   r   rf    s   

z'ExpressionChecker.visit_enum_index_exprrA   c                 C  s   | j |jttjddd}|j}| jj}|jr)t	t
|ts)||kr)| j|| |jr8t|r8| jd|| t|| jj| jj| j|d |S )zType check a cast expression.Tr  rR  ro  zTarget type of castr
  )rW  r   r   r   r)  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  r   r   r   visit_cast_expr  s(   z!ExpressionChecker.visit_cast_exprr<   c                 C  s   | j |j| jd ddd}| jjr|S |j}t|}t|tj	j
r)|jd ur)|j}t||sC| j s;| jd|j | j||| |S )Nr$  Tr  zC"assert_type" expects everything to be "Any" in unchecked functions)rW  r   r  r  rF  r   r   r   rz  r   r   rC  r}   r-  r  r+  assert_type_fail)r  r   r  r  proper_source_typer   r   r   visit_assert_type_expr  s,   


z(ExpressionChecker.visit_assert_type_exprr_   c                 C  s   |j tkr8|jdusJ | j|j| jd dd}| jjs6| j||j | j	 s1| j
d|j | | |S | jjsW|jdurIdd |jD ni }| j|| | | t S )z$Type check a reveal_type expression.Nr$  Tr  rR  z9'reveal_type' always outputs 'Any' in unchecked functionsc                 S  s   i | ]}|j |jqS r   )r/  r   )r   var_noder   r   r   r  1  s    z7ExpressionChecker.visit_reveal_expr.<locals>.<dictcomp>)r  r:   r   rW  r  r  rF  r  reveal_typer-  r+  check_reveal_importedlocal_nodesreveal_localsr   )r  r   revealed_typenames_to_typesr   r   r   visit_reveal_expr  s*   




z#ExpressionChecker.visit_reveal_exprc                 C  s   t j| jjjvr
d S d}|jtkrd}n|jtkr|jsd}nd S | jj	d| d|t jd |dkrQ| jjj
dkr<dnd	}d
j||d}| jj||t jd d S d S )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}"))moduler/  )r  UNIMPORTED_REVEALr  r  r@  r  r9   r:   is_importedr  rg  rt  r+  )r  r   r/  r  hintr   r   r   r  :  s"   
z'ExpressionChecker.check_reveal_importedtapprj   c                 C  sN  t |jtrst |jjtrs|jjjr|  S t|jj|j| j	j
|jjj|| j	j}t|}t |trAt|j| j}| ||j|S t |tr\|jjjr\t|jj| j}| ||jj|S t |trf| |S | j	
tj| ttjS t| |j}t |tt fr|! s| j	
tj| | ||j|S t |trttj"|dS ttj#S )a{  Type check a type application (expr[type, ...]).

        There are two different options here, depending on whether expr refers
        to a type alias or directly to a generic class. In the first case we need
        to use a dedicated function typeanal.instantiate_type_alias(). This
        is due to slight differences in how type arguments are applied and checked.
        r  )$r   r   r^   r   r   python_3_12_type_aliastype_alias_type_typer   r   r  r  r  r  r   r   r   r   r,   apply_type_arguments_to_callablerc  r   r  rk  r   r	  r   ONLY_CLASS_APPLICATIONr   r   r0  rW  r   r   r  r  r)  )r  r  r  r  r   r   r   visit_type_applicationQ  s<   






z(ExpressionChecker.visit_type_applicationaliasri   c                 C  s   | j |j|d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%  )r:  r   )r  r  r   r   r   visit_type_alias_expr|  s   z'ExpressionChecker.visit_type_alias_expr)r'  r   r'  c             
   C  sN  |j r|  S t|jtr|jjrttjS | j	j
jo| j}tt|g |j|j| j	j
|| jjd}t|trJt|j| j}|jrB|S | ||j|S t|tr`t|jjdkr`tt|j| jS t|trj| |S t|trxt||j|jdS t|trttj |dS t|t!r|j"r| j	j
j#dkr| j	$d|j%S |rttj&S | dS )a  Get type of a type alias (could be generic) in a runtime expression.

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

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

            x = A()
            y = cast(A, ...)
        )disallow_anyr  r  r4  r5  r  )r\  
   ztypes.UnionTyper>  )'r  r  r   rZ  r   invalidr   r   r0  r  r  disallow_any_genericsr  r   r   r4  r5  r  r  r   r   r,  r  r  rc  r   r   r   r   r	  r   r   r  r   r  rg  r;  r   r)  )r  r  r&  r'  r  r  r  r   r   r   r:    sP   







z/ExpressionChecker.alias_type_in_runtime_contextr   c                 C  s  |  r| jj}nt|j}t|}t|j|D ]/\}}t|t	rItt
|tt	ttfsI| jdt|| jj | ttjgt|   S q|rUtdd |D sYt|S |  s_J | }t|||j|jd}t|| jjddst|| jj| jjd| jjd t|j}td	d t|D }	t||	 d
 }
||	 }t|tsJ t t!||	|
\}}}t|t"t||j#g t| 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                 s  r  r   r   r   r  r   r   r   r     r  z7ExpressionChecker.split_for_callable.<locals>.<genexpr>r  T)empty_tuple_indexF)r  r  c                 s  "    | ]\}}t |tr|V  qd S r   r  )r   re  r  r   r   r   r           r   )$r  r  r  r  r  r  r   r  r   r   r   r   r   r   r  r  r1   r  r   r0  ry  r  r   r4  r5  r   r   r+  rc  nextrQ  r   r   tupler   r   )r  r   rc  r&  varstvr  r  fakeprefixsuffixtvtstartrq  r}  r   r   r   split_for_callable  sB   


"z$ExpressionChecker.split_for_callabler  c              
     s  t |}t|tr| r| jj}nt|j}t	dd |D }t
dd |D }t |k s9t t|kr||s|| rj| jdkrjttt jdgtgdgtt jd|jd|j|jdS j|t|t  ttjS || S t|tr|jD ]H}| r| jj}nt|j}t	dd |D }t
d	d |D }t |k st t|kr|s؈j|t|t  ttj  S qt fd
d|jD S ttjS )a{  Apply type arguments to a generic callable type coming from a type object.

        This will first perform type arguments count checks, report the
        error as needed, and return the correct kind of Any. As a special
        case this returns Any for non-callable types, because if type object type
        is not callable, then an error should be already reported.
        c                 s      | ]}|   V  qd S r   has_defaultr  r   r   r   r   !  r  zEExpressionChecker.apply_type_arguments_to_callable.<locals>.<genexpr>c                 s  r  r   r  r  r   r   r   r   "  r  r  r  N)r/  
definition
bound_argsc                 s  r  r   r  r  r   r   r   r   B  r  c                 s  r  r   r  r  r   r   r   r   C  r  c              
     s$   g | ]} || qS r   )r  r  r   rc  r&  r  r   r   rj  L  s    zFExpressionChecker.apply_type_arguments_to_callable.<locals>.<listcomp>)r   r   r   r  r  r  r  r  r  sumr  ry  r   r   r  r,  r3   rn  r  r  r  incompatible_type_applicationr   r   r0  r  r  r   r   r)  )r  r  rc  r&  r  min_arg_counthas_type_var_tupler   r   r  r   r    s^   









z2ExpressionChecker.apply_type_arguments_to_callablerS   c                 C     |  |ddS )z#Type check a list expression [...].r1  z<list>check_lst_exprr  r   r   r   visit_list_exprS  r  z!ExpressionChecker.visit_list_exprra   c                 C  r  )Nr   z<set>r  r  r   r   r   visit_set_exprW  r  z ExpressionChecker.visit_set_exprListExpr | SetExpr | TupleExprcontainer_fullnamec           	      C  s   | j d }|r	dS | j|d}|durt|tr|S dS g }|jD ]}t|tr2t | j|<  dS || 	| q"t
|}t|sLt | j|< dS | j||g}|| j|< |S )aY  
        Fast path to determine the type of a list or set literal,
        based on the list of entries. This mostly impacts large
        module-level constant definitions.

        Limitations:
         - no active type context
         - no star expressions
         - the joined type of all entries must be an Instance or Tuple type
        r$  N)r  r	  r  r   r   r   rc   r   r  rW  r   rk  r   r  r;  )	r  r  r  r&  rtr  r  vtctr   r   r   fast_container_typeZ  s&   




z%ExpressionChecker.fast_container_typetagc              	   C  s   |  ||}|r
|S tddtdddg |  ttjd}t|gtj	gd g| j
||g| d||gd}| |dd	 |jD d
d	 |jD |d }t|S )NTr$  z<lst>	namespacer  r  r  defaultr#  r/  r  c                 S  s    g | ]}t |tr|jn|qS r   )r   rc   r   rl  r   r   r   rj    r  z4ExpressionChecker.check_lst_expr.<locals>.<listcomp>c                 S  s"   g | ]}t |trtjntjqS r   )r   rc   r   r4   r3   rl  r   r   r   rj    s   " r   )r  r   r   r<  r   r   from_omitted_genericsr   r   r4   r  r;  r,  r|  r   r    )r  r  r   r  r   r  constructorri  r   r   r   r  |  s:   
	z ExpressionChecker.check_lst_exprrh   c                 C  s   t |j}|d u rtdd |jD t|jkS tdd |jD dkr&dS tdd t|jD }t|jt|jko?||kS )Nc                 S  s   g | ]	}t |ts|qS r   r   rc   r   r  r   r   r   rj        z;ExpressionChecker.tuple_context_matches.<locals>.<listcomp>c                 S     g | ]	}t |tr|qS r   r  r  r   r   r   rj    r  r   Fc                 s  r  r   r  )r   re  lvr   r   r   r     r  z:ExpressionChecker.tuple_context_matches.<locals>.<genexpr>)r   r   ry  r  rQ  )r  r   r&  ctx_unpack_indexexpr_star_indexr   r   r   tuple_context_matches  s   
z'ExpressionChecker.tuple_context_matchesc                   s|  t jd }d}t|tr' fddt|jD }t|dkr&|d }n	 t|tr6 |r6|j}n|rRt	|t
rRt|tsDJ |jrR|jd gt j }d}|dur^t|du}d}|phtjjjv }g }d}	tt jD ]}
 j|
 }t|tr|r|sJ ||	 }t|tsJ |j}nd}|j|}t |}t|trt|jdur|r dd	  S d
}||j |r|	d7 }	qt|	t|j7 }	qt|r|st|trj|rj| }jd|g}|t| d
}qt dd	  S |r|	t|kr|}n|||	 }|	d7 }	|| qtttj }t|jd|g}|r<t!|i }|S )zType check a tuple expression.r$  Nc                   s0   g | ]}t |tr |st|tr|qS r   )r   r   r  r   r   r  rf  r   r   rj    s    
z6ExpressionChecker.visit_tuple_expr.<locals>.<listcomp>r   r   Fr  z<tuple>T)"r   r  r   r   r   r   ry  r   r  r   r   r   rc  r   rs   r  r  r  r  rc   r   r   rW  r   r  r3  r  r  r;  r  r   r   r)  r$   )r  r  r  type_context_itemstuples_in_contextunpack_in_contextseen_unpack_in_itemsallow_precise_tuplesr   ri  re  r  ctx_itemr&  ttrE  r  fallback_itemr   r   rf  r   visit_tuple_expr  s~   






z"ExpressionChecker.visit_tuple_exprrG   c                 C  sX  | j d }|r	dS | j|d}|durt|tr|S dS g }g }d}|jD ]E\}}|du r[t| |}	t|	trR|	jj	dkrRt
|	jdkrR|	jd |	jd f}q&t | j|<  dS || | || | q&t|}
t|}t|
r~t|st | j|< dS |r|d |
ks|d |krt | j|< dS | jd|
|g}|| j|< |S )a~  
        Fast path to determine the type of a dict literal,
        based on the list of entries. This mostly impacts large
        module-level constant definitions.

        Limitations:
         - no active type context
         - only supported star expressions are other dict instances
         - the joined types of all keys and values must be Instance or Tuple types
        r$  Nr4  r   r   r   )r  r	  r  r   r   r   r   rW  r   r   ry  rc  r   r  r   rk  r   r  r;  )r  r  r&  r  r  r  stargsr  r  stktr  dtr   r   r   fast_dict_type  s@   



z ExpressionChecker.fast_dict_typetypeddict_contextc                 C  s6   | j ||j|d d}t|}t|tr| S | S )N)ru  r  r=  r  )r  r   r   r   r   r  )r  r  r  r&  r3  r   r   r   "check_typeddict_literal_in_contextD  s   

z4ExpressionChecker.check_typeddict_literal_in_contextc              
   C  s8  |  | jd |}|rct|dkr| ||d S |D ]@}| j #}| j }| ||}W d   n1 s9w   Y  W d   n1 sHw   Y  | rRq| j	| |  S | j
|| | |}|rl|S tddtdddg |  ttjd}td	d	td
ddg |  ttjd}	g }
g }|jD ]P\}}|du r|
| || jd||	g qt||g}|jdkr|j|_|j|_n|j|_|j|_|j|_|j|_|
| |t||	g| d qt|tjgt| dgt| | jd||	g| dd||	gd}| ||
tjgt|
 |d S )zoType check a dict expression.

        Translate it into a call to dict(), with provisions for **expr.
        r$  r   r   NKT<dict>r  r  VTr2  r  r4  r#  r  ) find_typeddict_contextr  ry  r  r  r  r  r  r}  ry  typeddict_context_ambiguousr   r   r   r<  r   r   r  r   r  r;  rh   r4  r5  end_line
end_columnr   r,  r   r   r3   r|  )r  r  typeddict_contextsr  r  tmapr3  r  r  r  rc  r  r  r  tupr  r   r   r   visit_dict_exprO  s|   	 







 	z!ExpressionChecker.visit_dict_expr	dict_exprlist[TypedDictType]c                 C  sj   t |}t|tr|gS t|tr3g }|jD ]}| ||}|D ]}| ||j|r/|| q q|S g S r   )r   r   r   r   r   r  r  r  )r  r=  r  r   r  item_contextsitem_contextr   r   r   r    s    



z(ExpressionChecker.find_typeddict_contextrQ   c              	   C  s  | j j|dd | |\}}|sv| j jttj | j jj	ddd9 | j j
|" |jjdd D ]}|| j  q5| j| dd}W d   n1 sQw   Y  W d   n1 s`w   Y  | d	}| j j  t|||S | j j|j | j j| | j j||d
 W d   n1 sw   Y  | j | s| j jj	ddd | j| dd W d   n1 sw   Y  | j | }| j j  t||S )zType check lambda expression.F)body_is_trivialTr   can_skipfall_throughNr$  rS  r#  )type_override)r  check_default_argsinfer_lambda_type_using_contextr|  r  r   r   r)  r  frame_contextr-  push_functionbodyrW  r   r,  popr   r3  tscopefunction_scopecheck_func_itemr  r  replace_callable_return_type)r  r  r  r  stmtr3  rn  r   r   r   visit_lambda_expr  s:    

z#ExpressionChecker.visit_lambda_expr/tuple[CallableType | None, CallableType | None]c           	        s  t | jd }t|tr!dd t| D }t|dkr!|d }|r(t|ts*dS | jj	j
s^g  |jD ]}dd t|D }  fdd|D  q4|jt|jt t|j  d	}nt|t }t|trnt|tspJ |}|j| d
d}|jdus|jdurdS dd |jD }|js| dur|jdttjgt| ||j d}t |v st!|v r|dfS |j"|kr| j#t$j%| dS |j|jd|fS )zTry to infer lambda expression type using context.

        Return None if could not infer type.
        The second item in the return type is the type_override parameter for check_func_item.
        r$  c                 S  r  r   r  r  r   r   r   rj    s
    
zEExpressionChecker.infer_lambda_type_using_context.<locals>.<listcomp>r   r   NNc                 S  s   g | ]	}|j  r|qS r   )r  is_meta_varr   r  r   r   r   rj    r  c                   s   g | ]}| vr|qS r   r   r'  
extra_varsr   r   rj    r  )r3  r  r#  rt  Nc                 S  s   g | ]}|j qS r   )r  rU  r   r   r   rj    s    F)is_ellipsis_argsr  rw  rx  )rx  )&r   r  r   r   r   r  ry  r   r  r  r  r  r   r3  r  r!   r3  r   r  r  r   r,  r  r  	argumentsr*  r  r   r   r)  rx  r  r4   r5   rw  r  r   CANNOT_INFER_LAMBDA_TYPE)	r  r  r&  r  r  	meta_varscallable_ctxr  rw  r   r(  r   r    sL   	




z1ExpressionChecker.infer_lambda_type_using_contextre   c                 C  s  |  |}t|tr|\}}n|S t|}|du r&| jtj| tt	j
S t|}|du r;| jtj| tt	j
S |j}d}||v rJ||}n#| jj }	|	durmt||	jdrm|jrm||jjv rm|jj}||}|du r|jr~||kr~|js~d}n| jtj| tt	j
S t||d kr| jtj| tt	j
S ||d d D ]8}
|j|
jv s|
|d kr|jr|jjr|
|d krtt	j  S t|j|ddd||
|| j| j|  d  S qJ d)	z+Type check a super expression (non-lvalue).N)is_classmethodr$  r   FT)r/  rQ  r  r  r  r  override_infor=  r  r  r  r  )_super_arg_typesr   r  type_info_from_typer  r  r   UNSUPPORTED_ARG_1_FOR_SUPERr   r   r0  UNSUPPORTED_ARG_2_FOR_SUPERr  r8  r-  top_functionr   is_classr  r  !SUPER_ARG_2_NOT_INSTANCE_OF_ARG_1ry  TARGET_CLASS_HAS_NO_BASE_CLASSr/  rI  r  r)  r   r  rB  )r  r  r   	type_typeinstance_type	type_infoinstance_infor  r8  r  rY  r   r   r   visit_super_expr$  sl   









z"ExpressionChecker.visit_super_exprType | tuple[Type, Type]c                 C  s  | j  s
ttjS t|jjdkr\|jsttj	S | j j
 r-| j tj| ttj	S t|j}t|}| j j
 }|dusBJ |jrO|jd jjpM|}nu| j tj| ttj	S t|jjv ro| j tj| ttj	S t|jjthkr| j tj| ttj	S t|jjdkr| j tj| ttj	S t|jjdkrt| |jjd }| |jjd }n| j tj| ttj	S t |tr|jrtt|j}n&ttj!|dS t |tr|j"}t |tr|jrtt|j}nttj!|dS t |tst |t#r|$ s| j%&|| ttj	S t|}t |tr5|jr.t|j}||fS ttj!|dS t |trZ|j"}t |trZ|jrStt|j}||fS ttj!|dS ||fS )a*  
        Computes the types of the type and instance expressions in super(T, instance), or the
        implicit ones for zero-argument super() expressions.  Returns a single type for the whole
        super expression when possible (for errors, anys), otherwise the pair of computed types.
        r   Nr   r   r  )'r  r-  r   r   r  ry  callrc  r  r0  r-  active_classr  r   %SUPER_OUTSIDE_OF_METHOD_NOT_SUPPORTEDr   r   r5  r+  variabler   (SUPER_ENCLOSING_POSITIONAL_ARGS_REQUIREDr4   rw  SUPER_VARARGS_NOT_SUPPORTEDr   r3   SUPER_POSITIONAL_ARGS_REQUIRED#SUPER_WITH_SINGLE_ARG_NOT_SUPPORTEDr   rW  TOO_MANY_ARGS_FOR_SUPERr   r  r  r   r  r  %first_argument_for_super_must_be_type)r  r  current_typer9  r  r:  	type_iteminstance_itemr   r   r   r1  x  sz   














z"ExpressionChecker._super_arg_typesc                 C  sz   z| j d}W n ty   | j d}Y nw t|}|j|j|jfD ]}|r7| |}| j |||t	j
 q$| dS )Nztyping_extensions.SupportsIndexr  zbuiltins.slice)r  r,  rH  r   ru  rv  rw  rW  r  r   INVALID_SLICE_INDEX)r  r  supports_indexexpectedr8  r   r   r   r   visit_slice_expr  s   

z"ExpressionChecker.visit_slice_exprrR   c                 C     |  |jddS )Nr1  z<list-comprehension> check_generator_or_comprehension	generatorr  r   r   r   visit_list_comprehension     z*ExpressionChecker.visit_list_comprehensionr`   c                 C  rP  )Nr   z<set-comprehension>rQ  r  r   r   r   visit_set_comprehension  rU  z)ExpressionChecker.visit_set_comprehensionrN   c                 C  st   t |js"t|js"t dd |jdd  D s"t dd |jD r)d}t g}nd}t t g}| j||d|dS )	Nc                 s  r   r   r   )r   sequencer   r   r   r     r   z9ExpressionChecker.visit_generator_expr.<locals>.<genexpr>r   c                 s  s"    | ]}|D ]}t |V  qqd S r   r   )r   condlistcondr   r   r   r     r  ztyping.AsyncGeneratortyping.Generatorz<generator>)additional_args)r  is_asyncr   r  	sequences	condlistsr   rR  )r  r  rQ  r[  r   r   r   visit_generator_expr  s   
z&ExpressionChecker.visit_generator_exprgenr  id_for_messagesr[  list[Type] | Nonec              
   C  s   |pg }| j jjdddK | | tddtdddg |  ttj	d}|g}t
|tjgd	g| j ||| | j d
||gd}| ||jgtjg|d W  d	   S 1 s[w   Y  d	S )z:Type check a generator expression or a list comprehension.Tr   r  r  r$  z<genexp>r  r  Nr#  r  )r  r  r  check_for_compr   r   r<  r   r   r  r   r   r3   r;  r,  r|  r  )r  r`  r  ra  r[  r  tv_listr  r   r   r   rR    s.   


	$z2ExpressionChecker.check_generator_or_comprehensionrH   c              
   C  s   | j jjddde | | tddtdddg |  ttj	d}td	d	td
ddg |  ttj	d}t
||gtjtjgddg| j d||g| j dd||gd}| ||j|jgtjtjg|d W  d   S 1 sqw   Y  dS )z&Type check a dictionary comprehension.Tr   r  r  r$  r  r  r  r  r  Nr4  r#  z<dictionary-comprehension>r  )r  r  r  rc  r   r   r<  r   r   r  r   r   r3   r;  r,  r|  r  r  )r  r  ktdefvtdefr  r   r   r   visit_dictionary_comprehension  sB   




	$z0ExpressionChecker.visit_dictionary_comprehension'GeneratorExpr | DictionaryComprehensionc                 C  s   t |j|j|j|jD ][\}}}}|r| j|\}}n| j|\}}| j||d| |D ]6}| 	| | j
|\}	}
|	rF| j|	 tj| jjjv re|	du rZ| jd| q/|
du re| jd| q/qdS )zCheck the for_comp part of comprehensions. That is the part from 'for':
        ... for x in y if z

        Note: This adds the type information derived from the condlists to the current binder.
        TNF)r  indicesr]  r^  r\  r   analyze_async_iterable_item_typeanalyze_iterable_item_typeanalyze_index_variablesrW  r>  push_type_mapr  r?  r  r@  r  $redundant_condition_in_comprehension)r  r  r8  rW  
conditionsr\  r  sequence_type	conditiontrue_map	false_mapr   r   r   rc  :  s(   
z ExpressionChecker.check_for_comprD   c                 C  sf  |  |j | jd }| j|j\}}tj| jjjv r5|d u r)| j	
d|j n|d u r5| j	
d|j | j||j||d}tt|pF|}| j||j||d}tj|su|}	tt|	p`|	}
|d u sjt|
|st| j||j|
|d}n||kr||}	n
| j||j||d}	t||	g}t|rtt| jd tst||	}t|}t|tr|jjdkr|}|S )Nr$  FT)r=  rR  rG  )rW  rY  r  r  r>  r  r?  r  r@  r  redundant_condition_in_ifrD  if_exprr   r   	else_exprrz  r{  r:  r|   r   r  r   r   r   r  r   r   r   )r  r  rR  r&  if_mapelse_mapif_typeif_type_fallbackfull_context_else_type	else_typeelse_type_fallbackr  alternativep_altr   r   r   visit_conditional_exprW  sV   



z(ExpressionChecker.visit_conditional_exprrw  dict[Expression, Type] | Nonec                 C  s~   | j jjddd, |d u r | j|||d t W  d    S | j | | j|||dW  d    S 1 s8w   Y  d S )NTr   r  r  )r  r  r  rW  r   rm  )r  rw  r   r=  rR  r   r   r   rD    s   $z%ExpressionChecker.analyze_cond_branchro  r  c              
   C  s  || j v r
| j | S d}| jr| jst }d| _d}| j| | j}|| _zC|r7t|t	r7| j
|dd}	n2|rFt|trF| j|dd}	n#|rUt|trU| j|dd}	n|rdt|trd| j|dd}	n|| }	W n" ty }
 zt|
| jjj|j| jj| jj W Y d}
~
nd}
~
ww || _| j  |	dusJ | j||	 | jjjr|s| jjs| j rt|	r| jjs| j !|	| | j r| jjrt"t#j$}n|	}|r| j%|j  t | 7  < d| _|S )zType check a node in the given type context.  If allow_none_return
        is True and this expression is a call, allow it to return None.  This
        applies only to this expression and not any subexpressions.
        FTrS  N)&r  r  r  timeperf_counter_nsr  r  r  r   r@   rX  rr   visit_yield_from_exprrD   r  r>   visit_await_exprrW  	Exceptionr#   r  r  filer4  r  r  r  disallow_any_expris_stubr-  rx  rF  r  disallowed_any_typer   r   r  r  )r  r   r  rR  ro  r  record_timet0old_is_calleerQ  r  r   r   r   r   rW    sf   



zExpressionChecker.acceptr/  c                 C  s   | j |S )z}Return an instance type with type given by the name and no type
        arguments. Alias for TypeChecker.named_type.
        )r  r,  )r  r/  r   r   r   r,    s   zExpressionChecker.named_typec                 C  s"   | j jjdkr| dS | dS )zFReturns a `typing.TypeAliasType` or `typing_extensions.TypeAliasType`.)r\     ztyping.TypeAliasTypeztyping_extensions.TypeAliasType)r  r  rg  r,  r  r   r   r   r    s   

z&ExpressionChecker.type_alias_type_typec                 C  s6   t |}t|ttttfpt|| jdtt	j
gS )z$Is a type valid as a *args argument?r  )r   r   r   r   r   r   r~   r  r;  r   r)  r  r   r   r   r4    s   z"ExpressionChecker.is_valid_var_argc                 C  sJ   t || jd| dttjgp$t || jdt t gp$t|t	S )z'Is a type valid as a **kwargs argument?r2  r  )
r~   r  r;  r,  r   r   r)  r   r   r   r  r   r   r   r6    s    z*ExpressionChecker.is_valid_keyword_var_argc                   s  t |}t|trt |j}t|trt|}t|tr|j}t|tr*|j	
 S t|tr:| r:|jj	
 S t|trAdS t|trVt fdd| D }|S t|tr|j}t|trht |j}t|trqt|}t|tr|j	jdur|j	j S t|trdS dS dS )z*Does type have member with the given name?Tc                 3  s    | ]	} | V  qd S r   )r  )r   xr  r  r   r   r   0  r  z/ExpressionChecker.has_member.<locals>.<genexpr>NF)r   r   r   r  r   r   r   rn  r   r   has_readable_memberr   r  r   r   r   r  r   r  metaclass_typer  )r  rQ  r  r   r  r   r  r   r    s8   











zExpressionChecker.has_memberc                 C  s   | j || dS )zCalled when we can't infer the type of a variable because it's not ready yet.

        Either defer type checking of the enclosing function to the next
        pass or report an error.
        N)r  r.  )r  r/  r=  r   r   r   not_ready_callbackB  s   z$ExpressionChecker.not_ready_callbackrq   c                 C  s   | j jd }| j |d}|jd u r)tt|ttfs(| j  r(| j 	t
j| n| |j|}| j |||t
jdd | j |dS )Nr$  Factual typeexpected type)r  r|  get_generator_yield_typer   r   r   r   r   r-  r  r   YIELD_VALUE_EXPECTEDrW  r  INCOMPATIBLE_TYPES_IN_YIELDget_generator_receive_type)r  r  return_typeexpected_item_typeactual_item_typer   r   r   visit_yield_exprJ  s&   
z"ExpressionChecker.visit_yield_exprr>   c                 C  s   | j d }|d ur| jd|g}t| |j|}t|tr&ttj	|dS | 
||tj}|s?tt|tr?| jjd | |S )Nr$  typing.Awaitabler  )r  r  r;  r   rW  r   r   r   r   r  check_awaitable_exprr   INCOMPATIBLE_TYPES_IN_AWAITr   r  r  )r  r  rR  expected_typer(  r<  r   r   r   r  _  s   

z"ExpressionChecker.visit_await_exprstr | ErrorMessageignore_binderc                 C  sv   | j || d||ddsttjS | d|g g |d }| j |d}t|}|s9t	|t
r9|js9| 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  r,  r   r   r)  r  get_generator_return_typer   r   r   r  r  r  )r  r   r&  r  r  rS  r3  r   r   r   r  m  s   
z&ExpressionChecker.check_awaitable_exprrr   c                 C  sH  | j jd }t| |j}t|trttj|d}nP| j 	|rMt
|r1t|s1| j j|| ttj}| j d|||g}| jd|g g |d\}}nt
|rUt|sc| j j|| ttj}n| ||tj}| j |d}	| j |d}
| j |
|	|tjdd t|}| j j|dd	}|stt|tr| j jd | |S )
Nr$  r  rZ  __iter__r
  Fr  r  )is_coroutine)r  r|  r   rW  r   r   r   r   r  r  is_async_defhas_coroutine_decoratorr  yield_from_invalid_operand_typer)  r;  r  r0  r  r    INCOMPATIBLE_TYPES_IN_YIELD_FROMr  r  r  r   r  )r  r  rR  r  subexpr_type	iter_typer&  generic_generator_typer  r  r  	expr_typer   r   r   r    sF   




z'ExpressionChecker.visit_yield_from_exprrg   c                 C     |j S r   r   r  r   r   r   visit_temp_node     z!ExpressionChecker.visit_temp_noderm   c                   sp   t |j t tr jtjks3t |js| j	
d| |jr3t fdd|jD s3| j	
d| ttjS )Nz3TypeVar default must be a subtype of the bound typec                 3  s    | ]} |kV  qd S r   r   )r   r  	p_defaultr   r   r     r   z8ExpressionChecker.visit_type_var_expr.<locals>.<genexpr>z3TypeVar default must be one of the constraint types)r   r  r   r   type_of_anyr   r  r~   r  r  r  r  r  r)  r  r   r  r   visit_type_var_expr  s   

z%ExpressionChecker.visit_type_var_exprr[   c                 C  
   t tjS r   r   r   r)  r  r   r   r   visit_paramspec_expr  r  z&ExpressionChecker.visit_paramspec_exprrn   c                 C  r  r   r  r  r   r   r   visit_type_var_tuple_expr  r  z+ExpressionChecker.visit_type_var_tuple_exprrX   c                 C  r  r   r  r  r   r   r   visit_newtype_expr  r  z$ExpressionChecker.visit_newtype_exprrV   c                 C  sT   |j j}|r%| jjjrt|r| jd|| t|| jj| jj	| j|d t
tjS )NzNamedTuple typer
  )r  
tuple_typer  r  r  r   r  r  r   r  r   r   r)  )r  r  r  r   r   r   visit_namedtuple_expr  s   
z'ExpressionChecker.visit_namedtuple_exprrJ   c                 C  sf   t |j|jD ]&\}}|d ur-| |}tt|ts-|jj| j	}t|t
r-||_d|_qttjS NT)r  r   r  rW  r   r   r   r  rI  r   rp   r   r  r   r)  )r  r  r/  r  rQ  r9  r   r   r   visit_enum_call_expr  s   


z&ExpressionChecker.visit_enum_call_exprrk   c                 C  r  r   r  r  r   r   r   visit_typeddict_expr  r  z&ExpressionChecker.visit_typeddict_exprr]   c                 C  r  r   r  r  r   r   r   visit__promote_expr  r  z%ExpressionChecker.visit__promote_exprrc   c                 C  s   |  |jS r   )rW  r   r  r   r   r   visit_star_expr     z!ExpressionChecker.visit_star_exprc                 C  r  )zReturn instance type 'object'.rG  r  r  r   r   r   r<    r  zExpressionChecker.object_typec                 C  r  )zReturn instance type 'bool'.rA  r  r  r   r   r   r     r  zExpressionChecker.bool_type
known_typec                 C     d S r   r   )r  r   r  r   r   r   r       z)ExpressionChecker.narrow_type_from_binderr  c                 C  r  r   r   )r  r   r  r  r   r   r   r    s   c                 C  sX   t |tkr*| jj|}|r*tt|tr| jjs*|r%t	||dds%dS t
||S |S )zNarrow down a known type of expression using information in conditional type binder.

        If 'skip_non_overlapping' is True, return None if the type and restriction are
        non-overlapping.
        T)prohibit_none_typevar_overlapN)r+   r8   r  r  r  r   r   r   rF  r-   r.   )r  r   r  r  restrictionr   r   r   r    s   
c                   s@   t |trt |trt fddt|j|jD S  ||S )Nc                 3  s(    | ]\}}  t|t|V  qd S r   )has_abstract_typer   )r   callerru  r  r   r   r   '  s
    
z;ExpressionChecker.has_abstract_type_part.<locals>.<genexpr>)r   r   r  r  r   r  r  rH  r  r   r  r   rN  $  s
   z(ExpressionChecker.has_abstract_type_partc                 C  sZ   t |to,t |to,| o,| jp| jo,t |jto,|jj	jp'|jj	jo,| j
j S r   )r   r   r   r  r  r  r  r  r   r   r  allow_abstract_callr  r   r   r   r  -  s   

z#ExpressionChecker.has_abstract_type)
r  r  r  r0   r  rx   r  r  r   r  r   r  )r  rW   r   r   F)r  r^   r"  r   r   r   )r9  rp   r=  rE   r   r   )r   rU   r   r   )r  r@   rR  r   r   r   )rY  rK   r   r   )r  r@   r   r  )r<  r   r  r  r   r  r   rK   r   r   )r  r  r   r   )ru  r   rw  r  rx  r  rc  r  r=  rE   r  r  r   r   )r  r  ru  r   r   r  )
r  rK   ru  r   r   r  r  r   r   r   rQ  r   r   r   )ru  r   r  r  r=  rE   r   r   )
ru  r   r  r  r=  rE   r  r  r   r   )r  rl   r   r   )ru  r   r   r   )ru  r   r  r  r=  rE   r  r  r  r   r   r   )r   rT   r   r+  )r@  r^   r   rA  )r  r@   rC  r  r9  rp   r   rD  )ru  r   rw  r  r  rI  rx  rJ  rm  rK  rc  r  r   r  r<  r  r=  rE   r   r   )ru  r   rc  r  rw  r  rx  rJ  r_  r`  r   r   )ru  r   rc  r  rw  r  r=  rE   rx  rJ  rg  rh  r   r   )ru  r   rc  r  rw  r  r=  rE   rx  rJ  r<  r   rg  rm  r   r   r%  )rq  r  ru  r   rc  r  rw  r  r=  rE   rx  rJ  r<  r  r   r   )r  r   rc  r  r   rw  )r  r   ry  r   r&  rE   r   rz  r   )r  r   r  r@   rq  r  r<  r  r  r  r   r   )r  r@   r<  r   r  r  r   r   )NNNNN)ru  r   rc  r  rw  r  r=  rE   rx  rJ  r  r  rq  r  r<  r  r  r  r   r  )ru  r   rc  r  rw  r  r=  rE   rx  rJ  r  r  rq  r  r<  r  r   r  )r   rl   r  r  r   r   )r  r   r=  rE   r   r   )rc  r  r   rI  )r  r   r   r   )
ru  r   rc  r  rw  r  rm  rK  r   rI  )r  r   r  rE   r   r   )r  r   rc  r  rw  r  rx  rJ  rm  rK  r  r   r=  rE   r   r   )r  r   rc  r  rw  r  rx  rJ  rm  rK  r  r   r  r   r=  rE   r   r  )r   r(   )ru  r   rc  r  r  rI  rm  rK  r  r  r   r  )r  r   r~  r   r=  rE   r   r   )ru  r   r  rI  r  r  r  rJ  rm  rK  r=  r  r<  r  rq  r  r   r   )ru  r   r  rI  r  r  r  rJ  r  r  r=  rE   r   r!  )r<  r   rq  r  r=  rE   r   r  )r  rI  rw  r  rc  r  ru  r   rm  rK  r=  rE   r-  r.  r<  r  r   r  )rH  r   rI  r   rJ  r;   r  r   rP  r  rK  r  ru  r   r<  r  r=  rE   rL  rE   r   r  )ru  r   rc  r  rw  r  rx  rJ  rq  r  r<  r  r=  rE   r   r  )
r  rI  rw  r  rx  rJ  r   r   r   rj  )ra  rj  rc  r  r  rI  rw  r  rx  rJ  rq  r  r<  r  r=  rE   r   rz  )ra  rj  r  rI  rw  r  rx  rJ  rc  r  r=  rE   r   rj  )r  rI  ra  rj  r   r   r  )ra  rj  rc  r  r  rI  rw  r  rx  rJ  rq  r  r<  r  rd  r   r=  rE   r  r  r   r  ro  )r  r  r  r  r   r  )r   r  r   r  )r  rI  rw  r  rx  rJ  rc  r  ru  r   r=  rE   r   r   )
r  r   r   r   r=  rE   r  r   r   r   )rc  r  ru  r   r   r  )ru  r   rc  r  rw  r  rx  rJ  r=  rE   r   r  )r  rT   r  r   r   r   )r  r  r  r   r=  rE   r   r   )r   r   )r  r   r  r  r   r   )r  r   r  r   r   r   )r  rP   r   r   )r  rd   r   r   )r  r?   r   r   )r  rL   r   r   )r  rC   r   r   )r  rI   r   r   )r  rY   r   r   )r  rB   r   r   )r   rK   r   r  )r  r   r  r   r  r  r  r  r  r   r   r   )r  r  r  r   rc  r  rw  r  r=  rE   r  r  r   r  )r  r  r  r   rc  r  rw  r  r=  rE   r  r  r   r  )r  r  r  r   r  r   rc  r  rw  r  r=  rE   r   r  )r  r  r  r   r  rK   r   r   r  rK   r=  rE   r   r  )r  r  r  r   r  rK   r=  rE   r  r   r   r  )r  rY   r=  rE   r   r   )r  r=   r   r   )r  ro   r   r   )r  rO   r   r   )r  r   r  rO   r  rY  r   r   )r  r   r   r  )r  r   rP  r  r   r  )r  r   rs  rb   r   r   )r8  rK   r   r  )r  r   r8  rK   r   r   )r  r   r   r   )r  r   r8  rK   r  r   r   r  )r  rl   r8  rK   r=  rE   r   r   )r   rA   r   r   )r   r<   r   r   )r   r_   r   r   )r   r_   r   r  )r  rj   r   r   )r  ri   r   r   )r  r   r&  rE   r'  r   r   r   )r   r   rc  r  r&  rE   r   rI  )r  r   rc  r  r&  rE   r   r   )r  rS   r   r   )r  ra   r   r   )r  r  r  r  r   r  )r  r  r   r  r  r  r   r   )r   rh   r&  r   r   r   )r  rh   r   r   )r  rG   r   r  )r  rG   r  r   r   r   )r  rG   r   r   )r=  r  r  rG   r   r  )r  rQ   r   r   )r  rQ   r   r$  )r  re   r   r   )r  re   r   r>  )r  rb   r   r   )r  rR   r   r   )r  r`   r   r   )r  rN   r   r   )
r`  rN   r  r  ra  r  r[  rb  r   r   )r  rH   r   r   )r  rh  r   r  )r  rD   rR  r   r   r   )
rw  r  r   rK   r=  r  rR  r   r   r   )NFFF)r   rK   r  r  rR  r   ro  r   r  r   r   r   )r/  r  r   r   )r   r   )rQ  r   r  r  r   r   )r/  r  r=  rE   r   r  )r  rq   r   r   )r  r>   rR  r   r   r   )
r   r   r&  rE   r  r  r  r   r   r   )r  rr   rR  r   r   r   )r  rg   r   r   )r  rm   r   r   )r  r[   r   r   )r  rn   r   r   )r  rX   r   r   )r  rV   r   r   )r  rJ   r   r   )r  rk   r   r   )r  r]   r   r   )r  rc   r   r   )r   rK   r  r   r   r   )r   rK   r  r   r  r   r   r  )rH  r   r  r   r   r   )r   r   r   r   __annotations__r  r  r!  r  r*  r8  rX  r[  rV  r  r  r  r  r  r  rv  r  r  r  r  r  r2  r	  r  r/  r2  r5  r  r6  r7  r^  re  rl  rp  rv  rx  r  r  r  r|  r   r  r  r  r  r  r  r)   r  r  r  r  r  r  r  r  r-  r  rW  r[  r\  rX  rY  rT  r   r  rZ  r  r  r  r  r  r  r  rB  rD  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r.  r  r  r  rO  rT  rW  rU  rX  rc  ra  r_  r`  rd  r  re  rf  r  r  r  r  r  r  r:  r  r  r  r  r  r  r  r  r   r  r  r  r#  r  r=  r1  rO  rT  rV  r_  rR  rg  rc  r  rD  rW  r,  r  r4  r6  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r<  r  r   r  rN  r  r   r   r   r   r  &  s  
 "	E
 *28_
(+I )$2#w <.%P 8/C= ( 9T1fR:%m x, ;oOL
0 &%+E8L"#i/R#MTR"$P?';	r  Fignore_in_type_objc                 C  s   |  t|S )zWhether t contains an Any type)rW  
HasAnyType)r   r  r   r   r   rx  9  r  rx  c                      sT   e Zd Zd fddZdd	d
Zd fddZdddZdddZdddZ  Z	S )r  r  r   r   r  c                   s   t  tj || _d S r   )superr  r   ANY_STRATEGYr  )r  r  	__class__r   r   r  ?  s   
zHasAnyType.__init__r   r   c                 C  s   |j tjkS r   )r  r   r)  r  r   r   r   r   	visit_anyC  s   zHasAnyType.visit_anyr   c                   s   | j r	| r	dS t |S )NF)r  r  r  visit_callable_typer  r  r   r   r  F  s   zHasAnyType.visit_callable_typer   c                 C  s,   |  r|jgng }| |jg||j S r   )r  r  query_typesr  r  r  r   r  r   r   r   visit_type_varK  s   zHasAnyType.visit_type_varr   c                 C  &   |  r|jgng }| |jg|S r   r  r  r  r  r  r   r   r   visit_param_specO     zHasAnyType.visit_param_specr   c                 C  r  r   r  r  r   r   r   visit_type_var_tupleS  r  zHasAnyType.visit_type_var_tuple)r  r   r   r  )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
r   r   r   r  r  r  r  r  r  __classcell__r   r   r  r   r  >  s    


r  c                 C  s   t | } t| to| jjdkS )z;Whether t came from a function decorated with `@coroutine`.typing.AwaitableGenerator)r   r   r   r   r   r   r   r   r   r  X  s   r  c                 C  sP   t | } t| tr| jjdkrt| jdkrt | jd } t| to'| jjdkS )z9Whether t came from a function defined using `async def`.r     r\  ztyping.Coroutine)r   r   r   r   r   ry  rc  r   r   r   r   r  ^  s   r  c                 C  s   t | } t| tot| jS r   )r   r   r   r   r   r   r   r   r   r"  v  s   r"  mappingr  r  rI  r  r  c                   sX   t | dko+t | dko | d  tjko | d  tjk o+t fdd| D  S )Nr   r   r   c                 3  s2    | ]} | t jkott| t V  qd S r   )r   r5   r   r   r   )r   rK  r  r  r   r   r     s    
z'is_duplicate_mapping.<locals>.<genexpr>)ry  r   r4   r5   r   )r  r  r  r   r  r   r  {  s   r  r  r   r  c                 C  s   | j |dS )z>Return a copy of a callable type with a different return type.r  r  )r  r  r   r   r   r!    r  r!  c                      ,   e Zd ZdZd fddZdd	d
Z  ZS )r  zQuery whether an argument type should be inferred in the second pass.

    The result is True if the type has a type variable in a callable return
    type anywhere. For example, the result for Callable[[], T] is True if t is
    a type variable.
    r   r  c                      t  tj d S r   r  r  r   r  r  r  r   r   r       z ArgInferSecondPassQuery.__init__r   r   r   c                 C  s   |  |jp|t S r   )r  r  rW  HasTypeVarQueryr  r   r   r   r    s   z+ArgInferSecondPassQuery.visit_callable_typer  r  )r   r   r   r   r  r  r  r   r   r  r   r    s    r  c                      s@   e Zd ZdZd fddZdd	d
ZdddZdddZ  ZS )r  zBVisitor for querying whether a type has a type variable component.r   r  c                   r  r   r  r  r  r   r   r    r  zHasTypeVarQuery.__init__r   r   r   c                 C     dS r  r   r  r   r   r   r    r  zHasTypeVarQuery.visit_type_varr   c                 C  r  r  r   r  r   r   r   r    r  z HasTypeVarQuery.visit_param_specr   c                 C  r  r  r   r  r   r   r   r    r  z$HasTypeVarQuery.visit_type_var_tupler  r  r  r  )	r   r   r   r   r  r  r  r  r  r   r   r  r   r    s    

r  r  c                 C     | d uo	|  t S r   )rW  HasErasedComponentsQueryr   r   r   r   r       r  c                      r  )r  z<Visitor for querying whether a type has an erased component.r   r  c                   r  r   r  r  r  r   r   r    r  z!HasErasedComponentsQuery.__init__r   r   r   c                 C  r  r  r   r  r   r   r   visit_erased_type  r  z*HasErasedComponentsQuery.visit_erased_typer  )r   r   r   r   )r   r   r   r   r  r  r  r   r   r  r   r        r  c                 C  r  r   )rW  HasUninhabitedComponentsQueryr   r   r   r   r    r  r  c                      r  )r  zEVisitor for querying whether a type has an UninhabitedType component.r   r  c                   r  r   r  r  r  r   r   r    r  z&HasUninhabitedComponentsQuery.__init__r   r   r   c                 C  r  r  r   r  r   r   r   visit_uninhabited_type  r  z4HasUninhabitedComponentsQuery.visit_uninhabited_typer  )r   r   r   r   )r   r   r   r   r  r  r  r   r   r  r   r    r  r  r[  rY  c                   sP  t   t t trt  ttrtddd}ttr.t tttfr.dS | r8|r8dS t trJtfdd	 	 D S ttr\t fd
d		 D S t t
rntt
rhdS t jS ttrt tr{ j t tr jd j t trt  t trj jjv rdS tt t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.
    rQ  r   r   r   c                 S  s2   t | tpt | to|  pt | to| jjdkS )Nr   )r   r   r   r  r   r   r   r{  r   r   r   is_typetype_like  s
   
z4arg_approximate_similarity.<locals>.is_typetype_likeTc                 3  s    | ]}t | V  qd S r   r  r  )rY  r   r   r     r  z-arg_approximate_similarity.<locals>.<genexpr>c                 3  s    | ]}t  |V  qd S r   r  r  )r[  r   r   r     r  r   Nr  )r   r   r   r   r   r   r   r   r  r  r   r  rn  r   r   r   r   r   r  r~   r   r   )r[  rY  r  r   )r[  rY  r   r    s<   











r  r   rj  r|  r  rw  rx  rJ  c                   s   t |rdS fdd| D }tD ]B\ }t|ddrW fddt|D }g }g }	|D ]\}
}| |
 }||j |D ]
}|	|j|  q@q0t |	sWt |sW dS qdS )a  May an argument containing 'Any' cause ambiguous result type on call to overloaded function?

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

    Args:
        items: Overload items matching the actual arguments
        arg_types: Actual argument types
        arg_kinds: Actual argument kinds
        arg_names: Actual argument names
    Fc              
     s(   g | ]}t  |j|jfd dqS )c                   rm  r   r   rd  r0  r   r   rg  ,  rn  z:any_causes_overload_ambiguity.<locals>.<listcomp>.<lambda>)r   rw  rx  r  )rw  rx  r  r   r   rj  *  s    z1any_causes_overload_ambiguity.<locals>.<listcomp>T)r  c                   s$   g | ]\}}|  r||  fqS r   r   )r   item_idxlookup)arg_idxr   r   rj  6  s    
)r{  rQ  rx  r  r3  r  )r   r|  r  rw  rx  actual_to_formalrG  matching_formals_unfilteredmatching_returnsmatching_formalsr  formalsmatched_callablerY  r   )r  rw  rx  r  r   rz    s,   
rz  r   c                   s&    sdS t  fdd dd  D S )NTc                 3  s    | ]
}t | d  V  qdS )r   N)r}   r  r   r   r   r   Q  s    z!all_same_types.<locals>.<genexpr>r   )r   r  r   r  r   r{  N  s   r{  r  Sequence[CallableType],tuple[list[CallableType], list[TypeVarType]]c                 C  s   g }i }g }| D ]B}|  rEt|}i }|jD ](}|j}||vr8t|ttfr(qt|ts/J |||< || || ||j	< qt
||}|| q||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  rZ  renamer  r/  r   r   r   r  T  s&   


r  rQ  r   c                 C  s&   t | } t| tr| jdur| jS | S )z>If possible, get a more precise literal type for a given type.N)r   r   r   rC  r{  r   r   r   r    s   r  r   rK   c                 C  sR   t | tr| j}t |to|jtv S t | tr'| j}t |to&t t	|j
tS dS )z-Returns 'true' if the given node is a LiteralF)r   rO   rY  r^   r   r   rW   r   r   r   rZ  r   )r   rY  
underlyingr   r   r   r~    s   


r~  c                 C  sL   t | } ddh}t| trtdd | jD S t| tr$| jj|v r$dS dS )z?Is this one of builtin byte types, or a union that contains it?r   r   c                 s  r   r   )r  r  r   r   r   r     r   z&has_bytes_component.<locals>.<genexpr>TF)r   r   r   r  r   r   r   r   )rQ  
byte_typesr   r   r   r    s   
r  TypeInfo | Nonec                 C  sl   t | } t| tr|  r|  S t| tr| j} t| tr#t | j} t| t	r,t
| } t| tr4| jS dS )zXGets the TypeInfo for a type, indirecting through things like type variables and tuples.N)r   r   r   r  r  r   r  r   r  r   r   r   r   r{  r   r   r   r2    s   




r2  r   r  c                 C  s@   | sdS |  dd }|tj v p|tj v p|tj v S )NFr   r$  )splitr   r  r  r  rR  )r   
short_namer   r   r   r]    s   r]  PartialType | Nonec                 C  s$   | d u st | tr| jd u rd S | S r   )r   r   r   r   r   r   r   r9    s   r9  r=  c                 C  s8   t | } t| trdS t| trtdd | jD S dS )NTc                 s  r   r   )r6  r  r   r   r   r     r   z'is_type_type_context.<locals>.<genexpr>F)r   r   r   r   r  r   r
  r   r   r   r6    s   

r6  )r   r   r   r   )r   r^   r   r   r  )r   r   r  r   r   r   )r  r  r  rI  r  r  r   r   )r  r   r  r   r   r   )r   r  r   r   )r[  r   rY  r   r   r   )r   rj  r|  rI  r  rI  rw  r  rx  rJ  r   r   )r   rI  r   r   )r  r  r   r  )rQ  r   r   r   r  ro  )rQ  r   r   r  )r   r  r   r   )r   r  r   r  )r=  r  r   r   (  r   
__future__r   enumrx  r  collectionsr   
contextlibr   r  r   r   r   r   r	   r
   r   r   r   r  r   r   r   r   mypy.checkerrz  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_registryr/   mypy.messagesr0   r1   
mypy.nodesr2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   mypy.optionsrs   mypy.pluginrt   ru   rv   rw   rx   mypy.semanal_enumry   
mypy.staterz   mypy.subtypesr{   r|   r}   r~   r   mypy.traverserr   mypy.typeanalr   r   r   r   r   r   r   mypy.typeopsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
mypy.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mypy.types_utilsr   r   r   r   mypy.typestater   mypy.typevarsr   	mypy.utilr   mypy.visitorr   r  r   r  r   r   r   r  r   r   r   r   uniqueEnumr   r   r  r   r  r   r  r  rx  BoolTypeQueryr  r  r  r"  r  r!  r  r  r  r  r  r  r  rz  r{  r  r  r~  r  r2  r]  r9  r6  r   r   r   r   <module>   s    ,$ D$D	)


	                                               A

?:-