
    hik\                   
   U d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZmZ ddlZ dd	l 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/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m@Z@mAZAmBZBmCZC ddlDmEZEmFZFmGZGmHZHmIZImJZJ ddlKmLZL ddlMmNZNmOZOmPZPmQZQ ddlRmSZS ddlTmUZUmVZVmWZW ddlXmYZY ddlZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZc ddldmeZemfZf ddlgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZ ddlmZmZ ddlmZmZ ddlmZ ddlmZ dd lmZ dd!lmZmZmZ dd"lmZmZ dd#lmZ dd$lmZ dd%lmZmZmZmZmZmZmZmZmZmZ dd&lmZmZmZ dd'lmZ dd(lmZmZmZ dd)lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dd*l mZmZmZmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ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)m*Z* dd,l+m,Z, dd-l-m.Z.m/Z/m0Z0 dd.l1m2Z2m3Z3 dd/l4m5Z5  ed0          Z6d1Z7d2e8d3<   d4Z9d2e8d5<   eeeef         Z:d6e8d7<   eeeef         Z;d6e8d8<    G d9 d:e          Z< G d; d<e          Z=ee>eef                  Z?d6e8d=<    G d> d?e          Z@ G d@ dA          ZA G dB dCe5d         e-          ZB G dD dEe,          ZCe	 ddFdGddR            ZDedFdGddT            ZD	 ddFdGddVZDdd\ZEddaZFddcZGdddZHddeZIddfZJddiZKddkZLdddpZMdddrZN	 ddduZOddwZPddzZQdd|ZRddZS G d de          ZTddZUddZV	 dddZWddZXddZYddZZddZ[ddZ\ddZ]	 dddZ^ G d de          Z_ G d de          Z`ddZaddZb ed          Zc ed          Zd G d deecedf                   ZeddZfddZgddZhddZiddZjddZkddZlddZmddĄZnddńZoddǄZpd dȄZqddɄZrdd˄ZsddЄZt G dф de          ZuddԄZvddՄZwddׄZxdd؄ZydS (  zMypy type checker.    )annotationsN)defaultdict)IterableIteratorMappingSequenceSet)	ExitStackcontextmanager)
CallableFinalGenericLiteral
NamedTupleOptionalTypeVarUnioncastoverload)	TypeAlias	TypeGuard)
errorcodesjoinmessage_registrynodes	operators)ConditionalTypeBinderFrameget_declaration)CheckerScopeTypeCheckerSharedApi	TypeRange)checker_state)MemberContextanalyze_class_attribute_accessanalyze_instance_member_accessanalyze_member_accessis_instance_var)PatternChecker)SUPERTYPE_OF)
erase_typeerase_typevars!remove_instance_last_known_values)TYPE_VARUNUSED_AWAITABLEUNUSED_COROUTINE	ErrorCode)	ErrorInfoErrorsErrorWatcherIterationDependentErrorsIterationErrorWatcherreport_internal_error)expand_type)Keyextract_var_from_literal_hashliteralliteral_hash)map_instance_to_supertype)is_overlapping_erased_typesis_overlapping_types
meet_types)ErrorMessage)	SUGGESTED_TEST_FIXTURESMessageBuilderappend_invariance_notesappend_union_noteformat_typeformat_type_bareformat_type_distinctlymake_inferred_type_note
pretty_seq)MroErrorcalculate_mro)S	ARG_NAMEDARG_POSARG_STARCONTRAVARIANT	COVARIANTFUNC_NO_INFOGDEFIMPLICITLY_ABSTRACT	INVARIANTIS_ABSTRACTLDEFLITERAL_TYPEMDEFNOT_ABSTRACTSYMBOL_FUNCBASE_TYPES
AssertStmtAssignmentExprAssignmentStmtBlock	BreakStmt	BytesExprCallExprClassDefComparisonExprContextContinueStmt	DecoratorDelStmtDictExprEllipsisExpr
ExpressionExpressionStmt	FloatExprForStmtFuncBaseFuncDefFuncItem
GlobalDeclIfStmtImport	ImportAll
ImportBase
ImportFrom	IndexExprIntExpr
LambdaExprListExprLvalue	MatchStmt
MemberExprMypyFileNameExprNodeNonlocalDeclOperatorAssignmentStmtOpExprOverloadedFuncDefOverloadPartPassStmtPromoteExpr	RaiseStmtRefExpr
ReturnStmtSetExprStarExpr	StatementStrExpr
SymbolNodeSymbolTableSymbolTableNodeTempNodeTryStmt	TupleExprr   TypeAliasStmtTypeInfo	UnaryExprVar	WhileStmtWithStmt	YieldExprget_func_defis_final_node)flip_opsint_op_to_methodneg_ops)PRECISE_TUPLE_TYPESOptions)	AsPatternStarredPattern)Plugin)dataclasses)Scope)is_trivial_bodyrefers_to_fullnameset_callable_name)
ENUM_BASESENUM_SPECIAL_PROPS)BINARY_MAGIC_METHODS)state)
find_memberinfer_class_variancesis_callable_compatibleis_equivalentis_more_preciseis_proper_subtypeis_same_type
is_subtyperestrict_subtype_awayunify_generic_callable)TraverserVisitorall_return_statementshas_return_statement)TransformVisitor)check_for_explicit_anyhas_any_from_unimported_typemake_optional_type)	bind_selfcan_have_shared_disjoint_basecoerce_to_literalcustom_special_methoderase_def_to_union_or_bounderase_to_bounderase_to_union_or_bound
false_onlyfixup_partial_typefunction_typeis_literal_type_likeis_singleton_typemake_simplified_union	true_onlytry_expanding_sum_type_to_union"try_getting_int_literals_from_typetry_getting_str_literals"try_getting_str_literals_from_typetuple_fallbacktype_object_type)%ANY_STRATEGYMYPYC_NATIVE_INT_NAMESOVERLOAD_NAMESAnyTypeBoolTypeQueryCallableTypeDeletedType
ErasedTypeFunctionLikeInstanceLiteralTypeNoneType
OverloadedPartialType
ProperType	TupleTypeTypeTypeAliasTypeTypedDictTypeTypeGuardedType	TypeOfAnyTypeTranslatorTypeType	TypeVarIdTypeVarLikeTypeTypeVarTupleTypeTypeVarTypeUnboundTypeUninhabitedType	UnionType
UnpackTypefind_unpack_in_listflatten_nested_unionsget_proper_typeget_proper_typesis_literal_typeis_named_instance)is_overlapping_noneremove_optionalstore_argument_type
strip_type)TypeTraverserVisitor)fill_typevarsfill_typevars_with_anyhas_no_typevars)	is_dunder	is_sunder)NodeVisitorT   r   DEFAULT_LAST_PASS   MAX_PRECISE_TUPLE_SIZE
_TypeAliasDeferredNodeTypeFineGrainedDeferredNodeTypec                  $    e Zd ZU ded<   ded<   dS )DeferredNoder  nodeTypeInfo | Noneactive_typeinfoN__name__
__module____qualname____annotations__     \/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/mypy/checker.pyr  r     s*         $$$$$$r  r  c                  $    e Zd ZU ded<   ded<   dS )FineGrainedDeferredNoder  r  r  r  Nr  r  r  r  r  r    s*         %%%%$$$$$$r  r  TypeMapc                  .    e Zd ZU ded<   ded<   ded<   dS )PartialTypeScopedict[Var, Context]mapboolis_functionis_localNr  r  r  r  r  r     s1         NNNNNr  r  c                  *    e Zd ZdZddZddZddZdS )LocalTypeMapzStore inferred types into a temporary type map (returned).

    This can be used to perform type checking "experiments" without
    affecting exported types (which are used by mypyc).
    chkTypeCheckerreturnNonec                    || _         d S N)r&  )selfr&  s     r  __init__zLocalTypeMap.__init__-  s    r  dict[Expression, Type]c                H    i }| j         j                            |           |S r+  )r&  
_type_mapsappend)r,  temp_type_maps     r  	__enter__zLocalTypeMap.__enter__0  s&    02""=111r  exc_typeobjectexc_valexc_tbLiteral[False]c                B    | j         j                                         dS NF)r&  r0  pop)r,  r4  r6  r7  s       r  __exit__zLocalTypeMap.__exit__5  s    !!!ur  N)r&  r'  r(  r)  )r(  r.  )r4  r5  r6  r5  r7  r5  r(  r8  )r  r  r  __doc__r-  r3  r<  r  r  r  r%  r%  &  sZ               
     r  r%  c                  V   e Zd ZU dZdZded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded <   d!ed"<   d#ZeZdZ	dZ
d$ed%<   d&Zd'ed(<   dZd)ed*<   d+ed,<   d-ed.<   d/ed0<   d1ed2<   d>d;Zed?d<            Zed@d>            ZdAd?ZdAd@Z	 dBdAdBdCdFZdDdIZdEdJZdFdNZdGdRZdHdUZ	 dBd&d&dVdId^ZdJdaZdJdbZedKdf            ZdLdkZdJdlZdMdpZ dNdqZ!dOdsZ"dOdtZ#dPduZ$dOdvZ%dQdxZ&dQdyZ'	 	 	 dRdSd~Z(dTdZ)edUd            Z*	 dVdWdZ+dXdZ,dYdZ-dZdZ.d[dZ/d\dZ0d\dZ1d]dZ2d^dZ3d_dZ4d`dZ5dadZ6dbdZ7dcdZ8dddZ9dddZ:dedZ;dfdZ<	 dBdgdZ=dhdZ>didZ?djdZ@dkdZAdldZBdmdZCdndZDdodZEdpdZFdodÄZGdqdƄZHdodǄZIdrdȄZJdsd˄ZKdod̄ZLdod̈́ZMdod΄ZNdpdτZOdtd҄ZPdpdӄZQdudՄZRdvdׄZSdwdلZTdxdۄZUdydބZVdzd߄ZWd{dZXd|dZYd|dZZ	 	 d}d~dZ[ddhZ\ded<   ddZ]ddZ^ddZ_ddZ`ddd&dddZaddZbddZcddZddzdZeedd            Zfdd
ZgddZhddZiddZj	 dddZk	 dBddZl	 	 	 dddZmddZnddZo	 dddZpdd Zqdd&Zrdd(Zs	 ddd)Zt	 dBdd+Zudd,Zvdd.Zwdd/Zxdd2Zydd3Zzdd4Z{dd5Z|dd6Z}e~j        d7d8fd&d&d&d9ddBZddDZddIZddKZddMZddNZddPZddRZddTZddXZddYZdd[Zdd]Zdd_ZddaZddcZdVddfZddhZddjZddmZddnZddqZddrZddtZddvZddwZddxZddyZddzZdd}ZddZddZ	 dddZddZddZddZddZddZddZdÐdZdĐdZdŐdZdƐdZdǐdZdȐdZdɐdZdʐdZdːdZd̐dZd͐dZdΐdZdϐdZdАdZdѐdZddZdҐdZdӐdZdAddԐdĄZdAddԐdńZdՐdƄZd֐d̄Zdאd΄ZdؐdфZdِd҄ZdڐdلZdېdڄZdܐdۄZdNd܄ZÐdݐd݄ZĐdސd߄ZŐdߐdZƐddZǐddZe	 	 dd&d&d&ddd            Ze	 	 dd&d&ddd            Z	 	 dd&d&d&dddZʐddZedUd            Z̐ddZ͐ddZΐddZϐddZАddZѐddZҐddZӐddZԐddZՐddZ֐dd ZאddZؐdzdZِddZڐddZeddddd            ZܐddZݐddZސddZߐddZdBddZd&dddZ	 dd&dddZddZddZdAdddZdd Ze	 dBdAd!dd&            ZedAd!d d'            Z	 dBdAd!dd(Zdd)Zdd*Zdd+Zdd,Zdd.Zdd/Zdd0ZdBd	d2Zd
d3Zdd4Zdd5Zdd7Zdd9Zdd;Zdd=Zd&S (  r'  zMypy type checker.

    Type check mypy source files that have been semantically analyzed.

    You must create a separate instance for each source file.
    Fr3   errorsrC   msgzlist[dict[Expression, Type]]r0  r   binder mypy.checkexpr.ExpressionChecker_expr_checkerr)   pattern_checkerr   tscoper    scope
list[Type]return_typesz
list[bool]dynamic_funcszlist[PartialTypeScope]partial_typeszset[Var]partial_reportedz	list[str]widened_varsr   globalsdict[str, MypyFile]moduleszlist[DeferredNode]deferred_nodesr   r   optionsNzdict[Var, Type] | Noneinferred_attribute_typesr!  no_partial_typesset[str]module_refszdict[Var, set[int]]var_decl_framesr   pluginint
_unique_idtreer   pathstrper_line_checking_time_nsdict[int, int]r(  r)  c                   || _         || _        || _        || _        || _        t          ||          | _        || _        t                      | _	        t          |          | _        t          |          | _        |j        | _        g | _        g | _        g | _        t'                      | _        i | _        g | _        g | _        i g| _        t'                      | _        d| _        d| _        |j        | _        |                    |          | _        d| _        d| _         tC          |           | _"        d| _#        d| _$        g | _%        d| _&        d| _'        tP          j)        *                    | | j        | j        |          | _+        d| _,        d| _-        d| _.        d| _/        d| _0        tc          | | j        | j        |          | _2        d| _3        dS )zSConstruct a type checker.

        Use errors to report type check errors.
        r   FNT)4r?  rO  rQ  rZ  r[  rC   r@  rW  r   rE  r    rF  r   rA  namesrM  rH  rI  rJ  setrK  rV  rP  rL  r0  rU  pass_numcurrent_node_deferredis_stubis_typeshed_fileis_typeshed_stubrR  allow_constructor_cacher%  local_type_maprecurse_into_functions_is_final_defoverload_impl_stackchecking_missing_awaitallow_abstract_callmypy	checkexprExpressionCheckerrC  	_str_type_function_type	_int_type
_bool_type_object_typer)   rD  rY  )r,  r?  rO  rQ  rZ  r[  rW  r]  s           r  r-  zTypeChecker.__init__  s    		!&'22gg!$''
+G44z #! $55%*"| $ 5 5g > >(,%'+$*400 '+# #
 8:  ',#
 $)  "^==$(DK)B
 
 +//3*.+/-1-dDHdk7SSr  c                    | j         S r+  )rC  r,  s    r  expr_checkerzTypeChecker.expr_checker      !!r  list[Type | None]c                    | j         j        S r+  )rC  type_contextrw  s    r  r|  zTypeChecker.type_context  s    !..r  c                   | j                                          | j                                         t          | j                  | _        g | j        dd<   | j        d                                          | j                                         g | _	        g | _
        d| _        t          | j                  | _        dS )zCleanup stale state that might be left over from a typechecking run.

        This allows us to reuse TypeChecker objects in fine-grained
        incremental mode.
           Nr   )rK  clearrU  r   rQ  rA  r0  rx  resetrP  rJ  rR  r    rZ  rF  rw  s    r  r  zTypeChecker.reset  s     	##%%%   +DL99   """!!! (,%!$),,


r  c           
        d| _         t          j        | j        j                  5  t          j        |           5  | j                            | j	        | j
        j        | j        | j                   | j                            | j
        j                  5  |                                 5  | j                                        5  | j
        j        D ]x}| j                                        rH|                                 s nH|                     |          s| j                            |            nc|                     |           yddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   | j        rJ | j                            d          }||j        |j        }|J |                     d|                     d          g          }t?          |j        |          sStA          ||j        | j                  \  }}| !                    tD          j#        $                    ||          |           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )a  Type check the entire file, but defer functions with unresolved references.

        Unresolved references are forward references to variables
        whose types haven't been inferred yet.  They may occur later
        in the same file or in a different file that's being processed
        later (usually due to an import cycle).

        Deferred functions will be processed by check_second_pass().
        TrF  rQ  N__all__typing.Sequencebuiltins.strrQ  )%ri  r   strict_optional_setrQ  strict_optionalr#   ra  r?  set_filer[  rZ  fullnamerE  module_scopeenter_partial_typesrA  top_frame_contextdefsis_unreachable should_report_unreachable_issuesis_noop_for_reachabilityr@  unreachable_statementacceptrc  rM  gettyper  named_generic_type
named_typer   rH   failr   ALL_MUST_BE_SEQ_STRformat)r,  dall_all_nodeseq_str	str_seq_sall_ss          r  check_first_passzTypeChecker.check_first_pass  s    '+#&t|'CDD 	 	mFWX\F]F] 	 	K  	49-T[$, !    ))$)*<==  --// 	+ 	+1N1N1P1P 	+ 	+!Y^ + +;5577 +#'#H#H#J#J & %#'#@#@#C#C & $ > >q A A A %& !KKNNNN	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+  5555|''	22#	(=#yH#///"55)DOON,K,K+L G &di99 +A#TY, , ,(	5 		,@GG	SXYY[c  3              		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   I>AI&I,E/	BEE/	EE/	E E/	#I/E33I6E37CII&II&II&I>&I*	*I>-I*	.I>>JJT)rg  todo7Sequence[DeferredNode | FineGrainedDeferredNode] | Nonerg  c          
        || _         d| _        t          j        | j        j                  5  t          j        |           5  |s | j        s	 ddd           ddd           dS | j	        
                    | j        | j        j        | j        | j                   | j                            | j        j                  5  | xj        dz  c_        |s| j        }n	| j        rJ g | _        t                      }|D ]\  }}||v r
|                    |           t%                      5 }|rZ|                    | j                            |                     |                    | j                            |                     |                     |           ddd           n# 1 swxY w Y   	 ddd           n# 1 swxY w Y   	 ddd           ddd           dS # 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )zRun second or following pass of type checking.

        This goes through deferred nodes, returning True if there were any.
        TNFr  r~  )rg  ri  r   r  rQ  r  r#   ra  rP  r?  r  r[  rZ  r  rE  r  rb  addr
   enter_contextclass_scoperF  
push_classcheck_partial)r,  r  rg  doner  r  stacks          r  check_second_passzTypeChecker.check_second_pass%  sX    (?$&*#&t|'CDD 	 	mFWX\F]F] 	 	  3 	 	 	 	 	 	 	 	 	 	 	 	 	 	 K  	49-T[$, !    ))$)*<== 1 1" 3.DD#2222&(#LOEE-1 1 1)D/t||  HHTNNN" 1* X!//0G0G0X0XYYY!//
0E0Eo0V0VWWW**4000	1 1 1 1 1 1 1 1 1 1 1 1 1 1 111 1 1 1 1 1 1 1 1 1 1 1 1 1 1( 5	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   G;G#G;%AG# A(F?(A2F&F?&F**F?-F*.F?3G#?GG#GG#G;#G'	'G;*G'	+G;;G?G?r  .DeferredNodeType | FineGrainedDeferredNodeTypec                   g | _         t          |t                    r|                     |           d S d| _        | j                                        5  |                     |           d d d            d S # 1 swxY w Y   d S NT)rL  
isinstancer   check_top_levelri  rA  r  r  r,  r  s     r  r  zTypeChecker.check_partialM  s    dH%% 	"  &&&&&*.D'..00 " "D!!!" " " " " " " " " " " " " " " " " "s   A77A;>A;c                    d| _         |                                 5  | j                                        5  |j        D ]}|                    |            	 ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   | j        rJ dS )zDCheck only the top-level of a module, skipping function definitions.FN)ri  r  rA  r  r  r  rc  )r,  r  r  s      r  r  zTypeChecker.check_top_levelV  s   &+#%%'' 	# 	#..00 # # # #AHHTNNNN## # # # # # # # # # # # # # #	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#
 ------s4   A: A#A:#A'	'A:*A'	+A::A>A>r  enclosing_classr  c                V    | j                             t          ||                     dS )a  Defer a node for processing during next type-checking pass.

        Args:
            node: function/method being deferred
            enclosing_class: for methods, the class where the method is defined
        NOTE: this can't handle nested functions/methods.
        N)rP  r1  r  )r,  r  r  s      r  
defer_nodezTypeChecker.defer_nodea  s+     	""<o#F#FGGGGGr  namecontextre   c                *   | j                                         }| j        | j        k     rNt	          |t
                    r9| j                             |          }|                     ||           d| _        d S | j	        
                    ||           d S r  )rF  top_level_functionrb  	last_passr  rp   r  r  rc  r@  cannot_determine_type)r,  r  r  r  r  s        r  handle_cannot_determine_typez(TypeChecker.handle_cannot_determine_typen  s    z,,..=4>))jw.G.G)
 #j88>>OOOD/222 *.D&&&H**499999r  stmtr   c                    	 |                     |            dS # t          $ r7}t          || j        j        |j        | j        | j                   Y d}~dS d}~ww xY w)z,Type check a node in the given type context.N)r  	Exceptionr7   r?  filelinerQ  )r,  r  errs      r  r  zTypeChecker.accept~  sx    	_KK 	_ 	_ 	_!#t{'7DKQUQ]^^^^^^^^^	_s    
A,AA)exit_conditionon_enter_bodybody	else_bodyStatement | Noner  Expression | Noner  Callable[[], None] | Nonec                  | j                             dd          5  t          d | j        D                       }t	          | j                  }t                      }d}	 | j                             ddd          5  |
 |             t          | j        j	        |          5  | 
                    |           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          d	 | j        D                       }	t	          | j                  }
|	|k    r| j         j        r|d
k    r|
|k    s|dk    rn|	}|
}|dz  }|dk    rt          d          | j                            |           |r-|                     |          \  }}|                     |           |r| 
                    |           ddd           dS # 1 swxY w Y   dS )zARepeatedly type check a loop body until the frame doesn't change.FT)can_skipconditional_framec              3  >   K   | ]}t          |j                  V  d S r+  lenr   .0ptss     r  	<genexpr>z*TypeChecker.accept_loop.<locals>.<genexpr>  s*      JJs37||JJJJJJr  r~  r  )r  break_framecontinue_frameNc              3  >   K   | ]}t          |j                  V  d S r+  r  r  s     r  r  z*TypeChecker.accept_loop.<locals>.<genexpr>  s*      "N"NC3sw<<"N"N"N"N"N"Nr        z(Too many iterations when checking a loop)rA  frame_contextsumrJ  r  rL  r5   r6   r@  r?  r  last_pop_changedRuntimeErroriteration_dependent_errorsfind_isinstance_checkpush_type_map)r,  r  r  r  r  partials_oldwidened_olditer_errorsiterpartials_newwidened_new_else_maps                r  accept_loopzTypeChecker.accept_loop  s    [&&&NN 0	' 0	' JJt7IJJJJJL d/00K244KDS[..!\].^^ * *$0%.txLL * *D)))* * * * * * * * * * * * * * *	* * * * * * * * * * * * * * *  #"N"N4;M"N"N"NNN!$"344 "\11![9 2=AAXX$33taxx+)	2::&'QRRR5S8 H//<<<  -"88HH8""8,,,  'I&&&a0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	' 0	's[   A!G>'C%C;CCCCCGC"	"G%C"	&CGGGdefnr   c                    | j         sd S | j                            |          5  |                     |           d d d            d S # 1 swxY w Y   d S r+  )ri  rE  function_scope_visit_overloaded_func_defr,  r  s     r  visit_overloaded_func_defz%TypeChecker.visit_overloaded_func_def  s    * 	F[''-- 	2 	2++D111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2   AAAc           	     
   d}|j         sd S t          |j                   dk    r |                     t          j        |           |j        rt          |j         d         t                    sJ |                     |j         d                    |j         d         j	        j
        rs|                     |j        d           |j        j	        j        }t          t          j                  }t#          ||gt$          t$          gd d g||                     d                    }|r0t)          ||          s |                     d|j        j                   |                     ||          }t          |t"                    rt          |j                  dk    r|}||j         d         j	        _        t          |j        t2                    rN|                     |j         d         j	        j        |          }|!|j         d         |_        ||j        j         d<   t7          |j                   D ]\  }}t          |t                    sJ |j        rqt          |j         d         t                    sJ |j         d         j	        j
        }	|	r|dk    s|	s-|dk    r'|                     |j        |j        j        d	           n|                     |d
           |j        j        t>          t@          fv r|dz  }|dt          |j                   fvr |                     t          j!        |           |j"        rL| #                    |j"                  5  |j"        $                    |            d d d            n# 1 swxY w Y   |j        s| %                    |           |j        wg }
|j         D ]W}t          |t                    sJ |                     |j	        j        |          }|||_        |
&                    |           X|
rt3          |
          |_        n|j        t          |j         d         t                    sJ |                     |j         d         j	        j        |          }t          |t"                    sHt          t          j                  }t#          |gt$          gd g||                     d                    }t3          |g          |_        |j'        r| (                    |          }|j)        r0|s.|,|j'        j*        s | j+        ,                    |j        |           | -                    |||j"                   | .                    |           d S d S )Nr   r~  T)skip_first_itembuiltins.function)	arg_types	arg_kinds	arg_namesret_typefallbackz!Invalid property setter signaturer  r  allow_empty)r  )/itemsr  r  r   MULTIPLE_OVERLOADS_REQUIREDis_propertyr  rg   visit_decoratorvaris_settable_propertyvisit_decorator_innersetterr  r   r   special_formr   rN   r  r   funcextract_callable_typer  setter_typer   
definition	enumeratecheck_func_itemr  abstract_statusrV   rT   INCONSISTENT_ABSTRACT_OVERLOADimplenter_overload_implr  check_overlapping_overloadsr1  infocheck_method_overrideis_explicit_overridefallback_to_anyr@  no_overridable_method!check_explicit_override_decoratorcheck_inplace_operator_method)r,  r  num_abstractr  any_typefallback_setter_typegetter_typeifdefsettable
item_typesitem	item_typevar_typefound_method_base_classess                  r  r  z&TypeChecker._visit_overloaded_func_def  s   z 	 Ftz??aII&BDIII 	9djmY77777  A///z!} 5 9**4;*MMM"ko2"9#9::'3'2&0#Tl%!__-@AA( ( ($  Uz+?S'T'T UIIA4;CSTTT"88dKK!+|<< 7KDY@Z@Z^_@_@_"6K0;
1!-di44 9"&"<"<TZ]=N=SUY"Z"ZK".15A.-8	* ,, 	" 	"GAtdI..... 	C!$*Q-;;;;;:a=,A [QQUU((UY(ZZZ **4T*BBBy([:M,NNN!3tz??333II&EtLLL9 	'))$)44 ' '	  &&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 	/,,T222y 
 J 5 5D%dI66666 $ : :48=$ O OI ,/3	,")))444 7 *: 6 6DIY djmY7777711$*Q-2C2H$OOHh55 	"9#9::''j&i#f%!__-@AA   #H:..DI9 	5(,(B(B4(H(H%)@1@ .9 	1 :
 ..ty$???2249RTXT]^^^..t44444	5 	5s   M88M<?M<r  r   Iterator[None]c              #     K   | j                             |           	 d V  | j                                         |k    sJ d S # | j                                         |k    sJ w xY wr+  )rk  r1  r;  )r,  r  s     r  r  zTypeChecker.enter_overload_impl1  s}       ''---	:EEE+//11T9999994+//11T99999999s   A !A$
inner_typeType | NonectxCallableType | Nonec                .   t          |          }d}|t          |t                    rdS t          |t                    rt          |j                  }t          |t
                    r-t          | j                            |j        |                    }t          |t                    r|}nt          |t                    r<t          t          d||ddd||                     }t          |t                    r|}nt          |t                    rt          |j                  }t          |t                    rtg }|j        D ]1}|                     ||          }| nN|                    |           2t          t#          j        |                    }	t          |	t                    r|	}n|                     ||          S || j                            ||           dS t          |t*                    rdS t          |t,                    sJ |S )z,Get type as seen by an overload item caller.N__call__FT)r  typr  	is_lvalueis_superis_operatororiginal_typer&  )r   r  r   r   upper_boundr   rx  analyze_type_type_calleer  r   r   r'   r   r   r  r  r1  r   join_type_listr@  not_callabler   r   )
r,  r$  r&  
outer_type
inner_call
union_typer  r  callable_itemjoined_types
             r  r  z!TypeChecker.extract_callable_type9  s*   $Z00
*.
J!@!@4j/22 	A()?@@Jj(++ 	(!:::?CPP J j,// 	C#JJ
H-- 	C(%#"#" $",	 	 	 J *l33 ('

I.. 	C.z/?@@J*i00 C&, 1 1D$($>$>tS$I$IM$,LL////"1$2Ee2L2L"M"MK!+|<< 1%0
11*cBBBH!!*c2224j*-- 	4*l33333r  c           	         | j         j        s5| j        j        j        | j        j        j        v s| j        r| j         j        rd S d }|j        rxt          |j        t                    r|j        j        }n6t          |j        t                    r|j        j        j        }n
J d            |                     ||j                  }|j        o
|j        dk    }t#          |j                  D ]\  }}t          |t                    sJ |                     |j        j        |          }|@t#          |j        |dz   d                    D ]H\  }}	t          |	t                    sJ |                     |	j        j        |	          }
|
@t'          ||
          sQt)          ||
          r+| j                            |dz   ||z   dz   |	j                   |s| j                                        }|r|j        j        ng }t7          j        d          5  t;          ||
|          rT|dk    o"t;          |
||           ot)          |
|           }| j                            |dz   ||z   dz   ||j                   d d d            n# 1 swxY w Y   J|e|j        J t?          ||t@          dd 	          r|j!        rdtE          |#                                |#                                dtH          
          }|%| j        %                    |dz   |j                   ;n|}|j&        r9|j        r2|'                    |j&        d         g|j&        dd          z             }t?          ||t@          dd          s#| j        (                    |dz   |j                   tA          |j)        |j)                  s=tA          |j)        |j)                  s#| j        *                    |dz   |j                   d S )NFzImpl isn't the right type__get__r~  r  Tr   c                "    t          ||           S r+  r   lrs     r  <lambda>z9TypeChecker.check_overlapping_overloads.<locals>.<lambda>  s    *Q2B2B r  )	is_compatr   is_compat_return)ignore_returnreturn_constraint_direction)r  r@  r   rB  )+rQ  ignore_errorsr@  r?  r  ignored_filesrf  test_envr  r  rp   r  rg   r  r  r  r  r  r  are_argument_counts_overlappingoverload_can_never_match%overloaded_signature_will_never_matchr  rF  active_classr  	type_varsr   r  )is_unsafe_overlapping_overload_signaturesoverloaded_signatures_overlapr   r   	variablesr   with_unpacked_kwargsr*   &overloaded_signatures_typevar_specificr  copy_modified"overloaded_signatures_arg_specificr  "overloaded_signatures_ret_specific)r,  r  	impl_typer$  is_descriptor_getr  r  sig1jitem2sig2current_classrL  	flip_noter  s                  r  r  z'TypeChecker.check_overlapping_overloadsp  s   
 L&		x#tx'DDD% E*.,*? E F *.	9 
	J$)W-- :*.).

DIy11 :!Y]/

99999 22:tyIII I@$)y*@ ,, c	R c	RGAtdI.....--dhmTBBD|%djQ&9:: & &5!%3333311%).%HH<6tTBB +D$77 HBB1q5!a%RS)UZU_````*  %)J$;$;$=$=M@M U 2 < <SUI2488  DT4QZ[[ 
 !Q !M(Q$($	)" )" %"!M )At(L(L$L & !HBB !Aq1uqy)TY                 $y,,, *(&+%B%B     & %0F!66881133&+4@1 1 1D |GGAtyYYY  $ %D > bdi b--9J8Kdn]^]_]_N`8`-aaD .$*]a   R H??AtyQQQ t}dm<<R!$-??R H??AtyQQQGc	R c	Rs   A&JJJr*  r   is_coroutinec                x   t          |          }|rA|                     dt          t          j                  g          }t          ||          rdS nDt          t          j                  }|                     d|||g          }t          ||          rdS t          |t                    o|j        j	        dk    S )zIs `typ` a valid type for a generator/coroutine?

        True if `typ` is a *supertype* of Generator or Awaitable.
        Also true it it's *exactly* AwaitableGenerator (modulo type parameters).
        typing.AwaitableTtyping.Generatortyping.AwaitableGenerator)
r   r  r   r   r  r   r  r   r  r  )r,  r*  r]  atr  gts         r  is_generator_return_typez$TypeChecker.is_generator_return_type  s     c"" 		(();giF\>]>]=^__B"c"" t y566H(();hRZ=[\\B"c"" t#x((]SX->B]-]]r  c                    	 t          t          j                  }|                     d||g          }n# t          $ r Y dS w xY wt          ||          S )zoIs `typ` a valid type for an async generator?

        True if `typ` is a supertype of AsyncGenerator.
        typing.AsyncGeneratorF)r   r   r  r  KeyErrorr   )r,  r*  r  agts       r  is_async_generator_return_typez*TypeChecker.is_async_generator_return_type1  sh    
	y566H))*AHhCWXXCC 	 	 	55	 #s###s   14 
AAreturn_typec                    t          |          }t          |t                    rt          t          j        |          S t          |t
                    r!t           fd|j        D                       S                      |          s. 	                    |          st          t          j
                  S t          |t                    st          t          j
                  S |j        j        dk    rt          t          j                  S |j        r|j        d         }|S t          t          j                  S )zRGiven the declared return type of a generator (t), return the type it yields (ty).
source_anyc                <    g | ]}                     |          S r  )get_generator_yield_typer  r  r]  r,  s     r  
<listcomp>z8TypeChecker.get_generator_yield_type.<locals>.<listcomp>F  s)    aaat..t\BBaaar  r_  r   )r   r  r   r   from_another_anyr   r   r  rd  ri  
from_errorr   r  r  r  args)r,  rj  r]  r  s   ` ` r  ro  z$TypeChecker.get_generator_yield_type>  s8   %k22k7++ 	395+NNNNY// 	3(aaaaa{O`aaa   ..
 
 	355kBB	3
 9/000K22 	39/000&*<<<91222 
	3"'*HO 91222r  c                    t          |          }t          |t                    rt          t          j        |          S t          |t
                    r!t           fd|j        D                       S                      |          s. 	                    |          st          t          j
                  S t          |t                    st          t          j
                  S |j        j        dk    rt          t          j                  S |j        j        dv r%t          |j                  dk    r|j        d         S |j        j        dk    r%t          |j                  dk    r|j        d         S t#                      S )	zTGiven a declared generator return type (t), return the type its yield receives (tc).rl  c                <    g | ]}                     |          S r  )get_generator_receive_typerp  s     r  rq  z:TypeChecker.get_generator_receive_type.<locals>.<listcomp>h  s)    ccc00|DDcccr  r_  r`  ra  r  r~  rf  r  )r   r  r   r   rr  r   r   r  rd  ri  rs  r   r  r  r  r  rt  r   r,  rj  r]  s   ` `r  rw  z&TypeChecker.get_generator_receive_type`  s   %k22k7++ 	95+NNNNY// 	(cccccQ\Qbccc   ..
 
 	55kBB	
 9/000K22 	9/000&*<<<91222%)ZZZK$%%** #A&&&*AAAc+JZF[F[_`F`F`#A&& ::r  c                    t          |          }t          |t                    rt          t          j        |          S t          |t
                    s
J d            |j        d         S )Nrl  z-Should only be called on coroutine functions.r  )r   r  r   r   rr  r   rt  )r,  rj  s     r  get_coroutine_return_typez%TypeChecker.get_coroutine_return_type  se    %k22k7++ 	O95+NNNN+x00aa2aaaa""r  c                    t          |          }t          |t                    rt          t          j        |          S t          |t
                    r!t           fd|j        D                       S                      |          st          t          j	                  S t          |t                    st          t          j	                  S |j        j        dk    r%t          |j                  dk    r|j        d         S |j        j        dv r%t          |j                  dk    r|j        d         S t                      S )	zSGiven the declared return type of a generator (t), return the type it returns (tr).rl  c                <    g | ]}                     |          S r  )get_generator_return_typerp  s     r  rq  z9TypeChecker.get_generator_return_type.<locals>.<listcomp>  s)    bbb//lCCbbbr  r_  r~  r   rx  r  r  )r   r  r   r   rr  r   r   r  rd  rs  r   r  r  r  rt  r   ry  s   ` `r  r~  z%TypeChecker.get_generator_return_type  sE   %k22k7++ 	95+NNNNY// 	(bbbbbP[Pabbb   ..{LII 	 9/000K22 	9/000&*<<<[EUAVAVZ[A[A[#A&&%)ZZZK$%%** #A&& ::r  rp   c                    | j         sd S | j                            |          5  |                     |           d d d            d S # 1 swxY w Y   d S r+  )ri  rE  r  _visit_func_defr  s     r  visit_func_defzTypeChecker.visit_func_def  s    * 	F[''-- 	' 	'  &&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'r  c                P   |                      ||j                   |j        rN|j        s2|j        s+|                     |          }|                     ||           |                     |           |j        r-| 	                    |          }| 
                    ||           dS dS )!Type check a function definition.r  N)r	  r  r  is_overloadis_decoratedr  r  r  original_defr   check_func_def_override)r,  r  r!  new_types       r  r  zTypeChecker._visit_func_def  s    T	2229 	5# XD,= X
 -1,F,Ft,L,L)66t=VWWW..t444 	9))$//H((x88888	9 	9r  rq   type_override
str | Noner  c                   | j                             |                                o|            | j        }|                     d          5  |                     |          }|r!|                    |j        |j                  }t          |t                    rE|                                 5  |                     ||||           ddd           n# 1 swxY w Y   nt          d          ddd           n# 1 swxY w Y   | j                                          || _        |dk    r|                     |           |dk    r6t!          j        |j                  rt!          j        | ||j                   dS dS dS )zcType check a function.

        If type_override is provided, use it as the function type.
        T)r"  )r  columnNzNot supportedr<  __post_init__)rI  r1  
is_dynamicrc  r  r   rR  r  r  r  r   !enter_attribute_inference_contextcheck_func_defr  r;  check__exit__return_typedataclasses_pluginis_processed_dataclassr  check_post_init)r,  r  r  r  r  enclosing_node_deferredr*  s          r  r	  zTypeChecker.check_func_item  s!    	!!$//"3"3"IM8IJJJ"&"<%%$%77 	4 	4$$T**C T#11sx
1SS#|,, 4;;== F F''c4EEEF F F F F F F F F F F F F F F #?333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	   %<":))$/// ?""!8CC J"24tyIIIII #"J Js7   A"C;/CC;C	C;C	C;;C?C?r  r   c                   |j         J t          |j         t                    rJ|                     |j                   }t	          ||          s| j                            |||           d S d S |j         j        }|d S t          |t                    rt|j        K|j         }t          |t                    r|j
        }n|}|                     |          }|||_        ||= d S d S |                     t          j        |           d S t          |j                  }|j         |_        | j                            |||           |                     |||t          j        dd           d S )Nzredefinition with typezoriginal type)r  r  rp   r   r   r@  %incompatible_conditional_function_defr  r   rg   r  find_partial_typesr  r   INCOMPATIBLE_REDEFINITIONr   r  r  rA  assign_typecheck_subtype)	r,  r  r  old_type	orig_typeorig_defr  rJ  	name_exprs	            r  r  z#TypeChecker.check_func_def_override  s    ,,,d'11 '	))$*;<<H(33 Y>>tXxXXXXXY Y
 ).I  )[11 >)#0H!(I66 '&l&$($;$;C$@$@M$0#+)#... 10
 II.H$OOOOO$TY//	!%!2	''	8YGGG""$>,#    r  c              #  <   K   | j         }i | _         d V  || _         d S r+  )rR  )r,  	old_typess     r  r  z-TypeChecker.enter_attribute_inference_context  s-      1	(*%


(1%%%r  r   c                <   |                      |j                   |                     ||          }|}|D ]\  }}| j        }t	          | j                  | _        | j                                        5  |j                            |           t          |t                    r|}	|	j        r||	j        dv rst          t          |j                  t          t           f          sE| j        d         s8|                     t&          j                            |	j                  |           |	j        r!|	j        dk    r|                     |	|           |                     |	           | j        j        r|	j        rt          |	j        t4                    r|	j        j        }
t7          |
          r| j                            d|
|	           t=          |	j        j                  D ]A\  }}t7          |          r-d|dz    d|	j         d}| j                            |||	           BtA          |	j        | j        | j!        | j        |		           |rv|j        r7| "                    |          r"|| j#        vr| $                    ||||           n8|d
v r| %                    |||           n|dk    r| &                    ||           t          |j        tN                    rP|j        j(        tR          k    r%|                     t&          j*        |j                   | +                    |           n;t          |j        tN                    r!|j        j,        r| +                    |           |j-        r|j.        r;| /                    |j                  s |                     t&          j0        |           n@| 1                    |j        |j2                  s |                     t&          j3        |           |j4        r|j        }|j2        }| 5                    ||          }| 6                    ||          }|r| 7                    |          }n| 8                    ||          }| 9                    d||||g          }
|:                    |
          }||_        | j;                            |j                   | j<        =                    |          5  | j<        >                                }ddd           n# 1 swxY w Y   |j?        rd}|	|j@        rd}|t          |j                  k     rt          |j?        |j        |                   sj|                     t&          jC                            t          |j?        | j                  t          |j        |         | j                            |           d}t          |t                    r|jE        s| F                    ||          }t          t          |j                            D ]}|j        |         }t          |tN                    rd|j(        t          k    rT|j        dvrKt          |j                  s7|dk    s|s/|}|jJ        dk     r|}|                     t&          jK        |           t          |||| j9                   t          |jN                  }| O                    ||           ddd           n# 1 swxY w Y   | j                                        5  d}|jP        D ]}|jQ        R                                D ]p\  }}t          |          }|Z| T                    ||jJ                  s?|| j        U                                }||jQ        |<   |jV        |         | j        jV        |<   q| j        jW        r`| jX        sY|jY        D ]Q}|jZ        }|j        At          |j                  } || _\        | j        ]                    | |j        |j                   R| j<        =                    |          5  t          |          st          |          dk    r| j        _                                 | j        j`        s"| j        ja        jb        | j        ja        jc        v r(| j        jd        st          |t                    r|je        r| f                    |jN                   ddd           n# 1 swxY w Y   | j        g                                }!|| j        h                    dd           ddd           n# 1 swxY w Y   |!s|j-        st          | j;        d         d          r'| 8                    | j;        d         |j2                  }"n5|j2        r!| 7                    | j;        d                   }"n| j;        d         }"t          |"          }"|p| j        jj        }| p0| o-t          |t                    o|jk        t          k     o| jX         }#|j        t          ur1|j        |j        jn        vs|j        jn        |j                 jo        rd}#t          |t                    r	|jp        rd}#|rt          t                      |"          rd}#|o?|j        t          uo1|j        jq        duo#|j        jq        j        r                    d          }$| j        js        r| jt        st          |"t          t          f          s|#rt          |"t                     rt&          jv        }%nt&          jw        }%|r |%x                    t          jz                  }%|                     |%|           |$r | {                    t&          j|        |           ny|#rwt&          j}        }%|r |%x                    t          jz                  }%| ~                    dt                      d|"||%          s"|$r | {                    t&          j|        |           | j;                                         || _        dS )r  )r-  __init_subclass____new__zReturn typez	Argument r~  z to ""r  )__getattr____getattribute____setattr__ra  )r  Nr   F)r-  r  r  r  Tabc.ABCMetacodezimplicitly returnsexpected)subtype_labelsubtypesupertype_label	supertyper  r@  )check_typevar_defaultsrO  expand_typevarsrA  r   rQ  r  expandedr1  r  rp   r  r  r   r  r   r   rI  r  r   MUST_HAVE_NONE_RETURN_TYPEr  check___new___signaturecheck_for_missing_annotationsdisallow_any_unimportedr  r   r   r@  unimported_type_becomes_anyr  r  r   rf  is_reverse_op_methodrk  check_reverse_op_methodcheck_getattr_methodcheck_setattr_methodr   variancerP   #RETURN_TYPE_CANNOT_BE_CONTRAVARIANTcheck_unbound_return_typevarvaluesis_generatoris_async_generatorri  'INVALID_RETURN_TYPE_FOR_ASYNC_GENERATORrd  r]  !INVALID_RETURN_TYPE_FOR_GENERATORis_awaitable_coroutinero  rw  r{  r~  r  rR  rH  rF  push_functionactive_self_typetype_ishas_self_or_cls_argumentr  r   NARROWED_TYPE_NOT_SUBTYPErF   r  require_correct_self_argumentrangerQ   
is_privater  &FUNCTION_PARAMETER_CANNOT_BE_COVARIANTr   r   r  check_default_argsframestypesr  r:   !is_var_redefined_in_outer_context
push_framedeclarationsallow_redefinition_newrd  	argumentsvariabler   r  r  _is_empty_generator_functionsuppress_unreachable_warningsrE  r?  r  rF  preserve_astshas_self_attr_defr  r  	pop_framer   allow_empty_bodiesr
  rZ   rR   r`  plugin_generatedis_mypy_onlymetaclass_typehas_basewarn_no_returnrc  r   INVALID_IMPLICIT_RETURNMISSING_RETURN_STATEMENT_replacecodes
EMPTY_BODYnoteEMPTY_BODY_ABSTRACTINCOMPATIBLE_RETURN_VALUE_TYPEr  r;  )&r,  r  r*  r  r  r  original_typr  
old_binderr  r  idxarg_typeprefixtctytctrref_type	arg_index
found_selfr  r&  body_is_trivial	new_frameframekeynarrowed_typekey_varargvnunreachablerj  
show_errormay_be_abstractr@  s&                                         r  r  zTypeChecker.check_func_def  s   
 	##CM222''c22! f	% f	%ID#J/==DK..00 N? N?$$T***
 dG,, D 	
 I)JJJ *+CL99Ho;V! ! K !% 22 6	 K 		,GNNtyYY[_  
 y @TY)%;%;44T3???66t<<<|; a9 aDI|)L)L a'+y'9H;HEE d $ D D]T\^b c c c1:49;N1O1O a aX#?#I#I !a-Sq-S-Sty-S-S-SF$(H$H$HQY[_$`$`$`*	4<1FZ^     
=		= 55d;;	= !(@@@44T3dKKKK!DDD11#tTBBBB..11#t<<< clK88 D|,==		,PRUR^   55c::::|4kBBDGSG\GcD
 55lCCC $ _. _#BB3<PP  II 0 XZ]    $<<S\4K\]] _ II&6&XZ]^^^ . $ A)A66q!<<B88A>>B B!;;A>>!;;AqAA#663b"b!_   H ++X+>>C #DI !((666Z--d33 J J -1J,G,G,I,IHJ J J J J J J J J J J J J J J
 ;  !I+0M+$%	 3s}#5#555jS]9%=? ?5 		,FMM +CK F F +CM),Ddl S S  !   #
dG,, OT5F O!%!C!CC!N!NJs3=1122 O OA"}Q/H!(K88 d %-:: $	1Y Y Y$.ty$9$9 !Z!"az+3C"x!||&) II&6&]_bccc'ad6MNNNN #2$)"<"<''o>>>]N? N? N? N? N? N? N? N? N? N? N? N? N? N? N?b ..00 73 73 +/	'. 
Y 
YE.3k.?.?.A.A 	Y 	Y*]"?"D"D".t7]7]#TY8 8.  )0,0K,B,B,D,D	3@IOC0<F<STW<XDK4S9	Y <6 Gt| G#~ G GL6- ( 0 0A%&AF K33AqvqvFFFZ--d33 / / 4D99 DS]]a=O=OAACCC !L6	/  $x3tx7TTT<5  U  *$88  U  1	  U DI...3/ / / / / / / / / / / / / / /4 #k88::(K))$222o73 73 73 73 73 73 73 73 73 73 73 73 73 73 73r  UN$ 	8(9%b)+F) ) 	8 #'"@"@)"-t/@# #KK & 8"&"@"@ARSUAV"W"WKK"&"3B"7K-k::)LT\-L (' 	 ( -&tW55^$:NR^:^- !%,  9L00ITY_44		8R8c4!&J dG,, '1B '!&J # 'z(**k'J'J '!&J $ N	5N	0<N 	05>>}MM	   <. "N 6R *;78K L LR 'R &k?CC L"2"JCC"2"KC* F"%,,E4D,"E"EC		#t,,,* R II&6&JDQQQ N*IC& B!ll0@lAA !..*>$,JJ,6&1$( # /  N ,N 		"2"FMMM!!###$DKKM	f	% f	%sp   4Q[%S9-[%9S==[% S=G[%%[)	,[)		Dd+&B,cd+c""d+%c"&9d++d/	2d/	r  c                T   t          |          }t          |t                    sdS | j        j        sMt          | j                  dk     s5| j        d         r(|                                rt          |j	                  S | j
                            |          5  | j
                                        }|	 d d d            dS 	 d d d            n# 1 swxY w Y   |j        r,|j        r'|j        d         t          j        t          j        fv rdS |j	        s|                     d|           dS |j	        d         }|j        s|j        dk    r$t*          j        j                            |          }t3          ||          rdS t          t5          t7          |                              }t9          ||d          st          |t:                    r|j        j        s@t          |t.                    r.t          |j         t:                    r|j         j        j        rd }nl|j!        d         d	v rQtD          j#        $                    |%                    | j                  |%                    | j                            }ntD          j&        }|r|                     ||           dS )
NFr  r   zKMethod must have at least one argument. Did you forget the "self" argument?r  T)ignore_type_params>   clsr,  )'r   r  r   rQ  check_untyped_defsr  rI  r  r!  r  rF  r  r  r  r  r   rO   	ARG_STAR2r  is_classr  rn  r  r   make_normalizedr   r,   r   r   r   r  is_protocolr  r  r   ERASED_SELF_TYPE_NOT_SUPERTYPEr  str_with_optionsMISSING_OR_INVALID_SELF_TYPE)r,  r  r  r  r  erasedr@  s          r  r  z)TypeChecker.require_correct_self_argumentF  s   t$$$-- 	5 L+	(4%&&**%b) +??$$ + '''Z%%d++ 	 	 %)J$?$?$A$AH	 	 	 	 	 	 	 	  		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 , 	N	#~a0U^U_4UUU5~ 	II]_c   5>!$= 	EDI22z*::8DDH(++ 	4 !x0H0H!I!IJJ(FtDDD 	%68,,DK+D fh//D v{H55	D
 K$0D "o55&ELL++DL998;T;TUYUa;b;b  'C %		#t$$$ts   CCCr  r   
after_linec                    |j         rdS | j                                        }|sdS |D ]3}t          |t                    rt          |j        |          |k    r dS 4dS )zCan the variable be assigned to at module top level or outer function?

        Note that this doesn't do a full CFG analysis but uses a line number based
        heuristic that isn't correct in some (rare) cases.
        FT)is_finalrE  outer_functionsr  rp   find_last_var_assignment_liner  )r,  r  r  outersouters        r  r  z-TypeChecker.is_var_redefined_in_outer_context  sz     : 	5,,.. 	 4 	  	 E%))  0Q??:MM44ur  c                *   t          |j        t                    r|j        |j        v rt	                      }|j        D ]}|                    |           |j        |j        vr|                     t          j	        |j        t                     t          |j        j                  }t          |t                    r|j        j        dk    sE|                     dt#          |j        j        | j                   d|j                   dS dS dS dS dS )z:Fails when the return typevar is not defined in arguments.r  builtins.objectzConsider using the upper bound z insteadr  N)r  r  r   rO  CollectArgTypeVarTypesr  r  r  r   UNBOUND_TYPEVARr.   r   r/  r   r  r  r  rF   rQ  )r,  r*  arg_type_visitorargtyper/  s        r  r  z(TypeChecker.check_unbound_return_typevar  s3   clK00 	S\S]5R5R577= 1 1/0000|#3#===		*:CLx	XXX-cl.FGG{H55#(15FFFIIY&s|'?NNY Y Y #      	 	5R5R
 >=
 GFr  r  r  c           
        |j         D ]}|j        
|rt          |j        t                    r'|j        j        }d}|                    d          r|d|dd           z  }n	|d| dz  }| j        j        s/t          |j        t                    r|j        j
        dk    rdd	g}nd }|                     |j        j        |j        |j        t          |t          j        
          dd|           d S )NzIncompatible default for __tuple_arg_ztuple argument    z
argument "r  builtins.NonezkPEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=Truez_Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebaser  argumentdefault)r  r@  lvalue_namervalue_namenotes)r  initializerr  rj   r  r  
startswithrQ  implicit_optionalr   r  check_simple_assignmentr  rA   r  
ASSIGNMENT)r,  r  r  r  r  r@  r)  s          r  r  zTypeChecker.check_default_args  s:   >  	  	C& :co|#L#L <$D-C~.. ,4bcc444+D++++L2s99 O,??], ((! 5+;<<<&% )    1 	  	r  method_namec                    |t           j        v S r+  )r   reverse_op_methodsr,  r/  s     r  is_forward_op_methodz TypeChecker.is_forward_op_method  s    i:::r  c                    |t           j        v S r+  )r   reverse_op_method_setr2  s     r  r  z TypeChecker.is_reverse_op_method  s    i===r  r  c                `   ddt          |j        t                    o2t          fd|j        j        |j        j        gz   D                       }| j         p| j        j        }| j        j	        o|}|r0| j        j
        s|r#|j        | j        j
        r|j        r:t          |j                  dk    r|j        d         d	k    s|j        d         d
k    r^|                     t          j        |           t#          |          s+|j        s&|                     d|t(          j                   d S d S d S |                     t          j        |           d S t          |j        t                    r6t/          |j        j                  } |          r!|                     t          j        |           n|j        rE |                     ||j                            r |                     t          j        |           nZ|j        rSt          |t4                    r> |                     |                    r |                     t          j        |           t          fd|j        j        D                       r(|                     t          j        |           d S d S d S d S d S )Nr  r   r(  r!  c                    t          | t                    sdS t          | t                    o| j        t          j        k    S r:  )r  r   r   type_of_anyr   unannotatedr  s    r  is_unannotated_anyzETypeChecker.check_for_missing_annotations.<locals>.is_unannotated_any  s8    a,, ua))Tamy?T.TTr  c              3  0   K   | ]} |           V  d S r+  r  r  r  r;  s     r  r  z<TypeChecker.check_for_missing_annotations.<locals>.<genexpr>  sK       N
 N
*+""1%%%N
 N
 N
 N
 N
 N
r  r~  r   r,  r
  z1Use "-> None" if function does not return a valuer  c              3  .   K   | ]} |          V  d S r+  r  r=  s     r  r  z<TypeChecker.check_for_missing_annotations.<locals>.<genexpr>  s/      JJ))!,,JJJJJJr  r  r   r(  r!  )r  r  r   anyr  r  rf  rQ  warn_incomplete_stubdisallow_incomplete_defsdisallow_untyped_defsr  r  r  r  r   RETURN_TYPE_EXPECTEDr   r  r  r  NO_UNTYPED_DEFFUNCTION_TYPE_EXPECTEDr   r~  r]  r   r{  ARGUMENT_TYPE_EXPECTED)r,  r  has_explicit_annotationshow_untypedcheck_incomplete_defsr  r;  s         @r  r  z)TypeChecker.check_for_missing_annotations  s.   	U 	U 	U 	U
 #-TY"E"E #
# N
 N
 N
 N
/3y/BdiFXEY/YN
 N
 N
 K
 K
  00UDL4U $ E aJa 	MT\? 	MCX 	My T\%G ~ M''1,,*f44q8IU8R8RII.CTJJJ/55 d>O 		O !&!5 "         II.EtLLLLLDI|44 M*49+=>>%%h// 	OII.CTJJJJ& O))66xARSS  O 		"2"GNNN& O:h+I+I O))$*H*H*R*RSS O		"2"GNNNJJJJdi6IJJJJJ MII.EtLLLLL9	M 	M 	M 	MM MM Mr  c                ^   t          |j                  }t          ||d          }|j                                        r=|                     |j        |                                 |t          j        dd           d S t          t          |j                  t          t          t          t          f          sM|                     t          j                            t%          |j        | j                            |           d S |                     |j        ||t          j        dd           d S )NT)is_classmethodreturnszbut must return a subtype of)r   r  r   is_metaclassr  r  	type_typer   INVALID_NEW_TYPEr  r   r   r   r   r   r  NON_INSTANCE_NEW_TYPEr  rF   rQ  )r,  r  r*  	self_type
bound_types        r  r  z#TypeChecker.check___new___signature  s:   *4955	sIdCCC
 9!!## 	#   1.     J/007HiQ`2a
 
 	 II 6==
 3T\BB  	     # 1.    r  reverse_typereverse_namec           	        |j         sJ t          t          t          j                  t          t          j                  gt
          j        t
          j        gddgt          t          j                  |                     d                    }t          ||          s| j	        
                    ||           dS |dv rdS t          |j                  }t          |t                    rdS t          |t                    r|j        j        dk    rdS |j        d         t$          k    r=|                    |j        d         gdz  t          gdz  |j        d         dg          }t-          |j                  dk    sJ t.          j        |         }t          |j        d	                   }t          |t2                    rt          |j                  }nNt          |t6                    rt9          |          }n)t          |t:          t<          t>          f          r|j         }t          |tB                    r,|j"        }	t          |	t                    r|	j        j#        }
|
|
}dfdt          |t          tH          f          r ||          sdS |j        d	         }| j%        &                    |||          }| '                    |||j         ||||           dS )z1Check a reverse operator method such as __radd__.Nr  )__eq____ne__r  r   r  r  r  r  r  r~  r*  UnionType | Instancer  r\  r(  r!  c                    t          | t                    r| j                                      S t	          fdt          |                                           D                       S )Nc              3     K   | ]T}t          |t                    r |          p.t          |t                    o|j                                      V  Ud S r+  )r  r   r   r  has_readable_member)r  xr]  r  s     r  r  zSTypeChecker.check_reverse_op_method.<locals>.has_readable_member.<locals>.<genexpr>d  s~          Ay))J.A.A!T.J.J Rq(++P0J0J40P0P     r  )r  r   r  r]  allr   relevant_items)r*  r  r]  s    `r  r]  z@TypeChecker.check_reverse_op_method.<locals>.has_readable_member`  s    #x(( :x33D999      *#*<*<*>*>??     r  r  )r*  rZ  r  r\  r(  r!  )(r  r   r   r   r  r   rN   r  r   r@  invalid_signaturer   r  r  r   r  r  r  rO   rR  r  r  r  r   normal_from_reverse_opr   r/  r   r   r   r   r   r  r   r  r  r   rx  analyze_external_member_accesscheck_overlapping_op_methods)r,  r  rT  rU  r  method_typer  forward_nameforward_instr  opt_metaforward_baseforward_typer]  s                @r  r  z#TypeChecker.check_reverse_op_method%  s    y #Y+,,gi6L.M.MN]EM*4LI*++OO/00
 
 ,44 	H&&|W===F///F #<#899h(( 	Fh)) 	}%):::!!$00'55'1!459")a-'1!4c: 6  L
 <)**a//// 7E&|'=a'@AAlK00 	1*<+CDDLLi00 	1),77LL|]K&PQQ 	1'0LlH-- 	,$D$)) ,93'#+L	 	 	 	 	 	 |h	%:;;	##L,??	 F#-a0(GG, H 
 
 	))I 	* 	
 	
 	
 	
 	
r  reverse_classr   rj  rf  ri  c           	        t          |g          D ]}t          |          }t          |t                    r6|                     |||          r| j                            |||||           \t          |t                    r@|j        D ]7}	|                     |	||          r| j                            |||||           8t          |t                    s| j        
                    ||           dS )a  Check for overlapping method and reverse method signatures.

        This function assumes that:

        -   The reverse method has valid argument count and kinds.
        -   If the reverse operator method accepts some argument of type
            X, the forward operator method also belong to class X.

            For example, if we have the reverse operator `A.__radd__(B)`, then the
            corresponding forward operator must have the type `B.__add__(...)`.
        N)r   r   r  r   is_unsafe_overlapping_opr@  "operator_method_signatures_overlapr   r  r   forward_operator_not_callable)
r,  rT  rU  rk  rj  rf  ri  r  forward_itemr  s
             r  rd  z(TypeChecker.check_overlapping_op_methods}  s(   ` 2<.AA 	N 	NL*<88L,55 N00|\ZZ H??%|\<QX   L*55 N(.  D44T<VV CC)<|U\  
  g66 N66|WMMM	N 	Nr  rp  c                   t          |j                  dk     rdS |}t          |t                    rt	          |          }|                    ||j        d         gt          j        gdz  d gdz            }|                    |j        d         |j        d         gt          j        gdz  d gdz            }|j        d         }t          |t                    rt	          |          }t          ||          rdS t          ||          r|}|}	n|}|}	| j
                                        }
|
r|
j        j        ng }t          ||	|d          S )Nr~  Fr   r  rY  )partial_only)r  r  r  r   r   rR  r   rN   r   r   rF  rK  r  rL  rM  )r,  rp  ri  rT  forward_base_erasedforward_tweakedreverse_tweakedreverse_base_erasedfirstsecondr[  rL  s               r  rm  z$TypeChecker.is_unsafe_overlapping_op  s    |%&&**5
 +lK00 	?"0">"> '44*L,B1,EF}o)fqj 5 
 

 '44#-a0,2H2KL}o)fqj 5 
 
 +4Q7);77 	F"01D"E"E+-@AA 	%5+-@AA 	%#E$FF#E$F
//114AIM&00r	8695
 
 
 	
r  ro   c                   |j         }|t          j        vrdS t          |                     |                    }|j        }d|dd         z   }|                    |          rt          |          }t          | j	        
                    |||                    }d}t          |t                    rt          ||          sd}nd}|r | j                            |||           dS dS dS )zrCheck an inplace operator method such as __iadd__.

        They cannot arbitrarily overlap with __add__.
        N__r  FT)r  r   inplace_operator_methodsr   r   r  r]  r   r   rx  rc  r  r   is_more_general_arg_prefixr@  signatures_incompatible)	r,  r  methodr*  r
  other_methodinstancetyp2r  s	            r  r  z)TypeChecker.check_inplace_operator_method  s   
 ;;;F**40011ifQRRj(""<00 	M$S))H"!@@xY]^^ D D$-- 1#t<<  D  M00tLLLLL	M 	MM Mr  c           	        t          | j        j                  dk    r|dk    r"|                     t          j        |           d S t          |                     d          gt          j	        gd gt          t          j                  |                     d                    }n| j                                        rt          t          t          j                  |                     d          gt          j	        t          j	        gd d gt          t          j                  |                     d                    }nd S t          ||          s| j                            |||           d S d S )Nr~  r  r  r  )r  rF  r  r  r   MODULE_LEVEL_GETATTRIBUTEr   r  r   rN   r   r   r  rK  r   r@  $invalid_signature_for_special_method)r,  r*  r  r  re  s        r  r  z TypeChecker.check_getattr_method  sQ   tz  A%%)))		*DgNNN '001	.// 344 KK Z$$&& 		&/00$//.2Q2QR.t	.// 344 KK F#{++ 	NH99#wMMMMM	N 	Nr  c           	        | j                                         sd S t          t          t          j                  |                     d          t          t          j                  gt          j        t          j        t          j        gg dt                      |                     d                    }t          ||          s| j                            ||d           d S d S )Nr  )NNNr  r  )rF  rK  r   r   r   r  r  r   rN   r   r   r@  r  )r,  r*  r  re  s       r  r  z TypeChecker.check_setattr_method(  s    z&&(( 	F"	.////	.//
 ]EM5=9JJOO/00

 

 #{++ 	WH99#wVVVVV	W 	Wr  c           	         |                      d          }t          ||                     d|g          g          }|                     |||t          j        ddt          j                   dS )zCheck the type of __slots__.r  typing.Iterablezactual typezexpected typer  N)r  r   r  r  r   INVALID_TYPE_FOR_SLOTSr  r.  )r,  r*  r  str_typeexpected_types        r  check_slots_definitionz"TypeChecker.check_slots_definition9  s    ??>22!t../@8*MMN
 
 	3! 	 	
 	
 	
 	
 	
r  r  c                   | j                                         sdS t          |          }t          |t                    rt          d |j        D                       s)| j                            d|t          j
                   dS dS )z2Check that __match_args__ contains literal stringsNc              3  4   K   | ]}t          |          V  d S r+  )is_string_literalr  r  s     r  r  z/TypeChecker.check_match_args.<locals>.<genexpr>N  s<       5
 5
(,d##5
 5
 5
 5
 5
 5
r  zb__match_args__ must be a tuple containing string literals for checking of match statements to workr  )rF  rK  r   r  r   r_  r  r@  r  r  LITERAL_REQ)r,  r  r*  r  s       r  check_match_argszTypeChecker.check_match_argsI  s    z&&(( 	Fc""#y)) 	 5
 5
03	5
 5
 5
 2
 2
 	 HMM.&	      	 	r  #list[tuple[FuncItem, CallableType]]c                   g }t          |j                  pg }|j        r||j        j        j        pg z  }|D ]Dt          t                    r-j        r&|                    fdj        D                        E|ro| j	        j
        sc| j	        j        sWg }t          j        | D ]D}t          |          }|                    t          ||          t!          ||          f           E|S ||fgS )Nc                "    g | ]}j         |fS r  id)r  valuetvars     r  rq  z/TypeChecker.expand_typevars.<locals>.<listcomp>c  s     HHH5tw.HHHr  )listrO  r  r  rL  r  r   r  r1  rQ  mypycinspections	itertoolsproductdictexpand_funcr8   )	r,  r  r*  substtvarsresultsubstitutionsmappingr  s	           @r  r  zTypeChecker.expand_typevarsX  s"    57S]##)r9 	4TY^-33E 	J 	JD$,, J JHHHHDKHHHIII  	!$,, 	!0H 	!:<F!*!2E!: W W}--{499;sG;T;TUVVVVM3K= r  FuncDef | OverloadedFuncDefr!  list[TypeInfo] | NoneContext | Nonec                ,   d}|j         r*|j                             |j                  x}r	|j        rd}|sV|rV|j        sQ|j        dvrJt          |j                  s8| j                            |j        |d         j        |p|           d S d S d S d S d S d S )NFTr-  r  r   )	r  r  r  r  r  r  r@  #explicit_override_decorator_missingr  )r,  r  r!  r  r  r  s         r  r  z-TypeChecker.check_explicit_override_decoratorp  s     !9 	$$)--	":"::$ 	$@U 	$  $ !		)		 -		 	!888ty)) 9 H88	4Q7@'/T    		 		 		 		 		 		 9888r  'FuncDef | OverloadedFuncDef | Decoratorc                   | j         j        s"| j        j        j        | j        j        j        v rdS |j        dvoL| j         j        p|                                 o+|j        dk    p |j	        j
                            d          du }g }|j	        j        dd         D ]5}|                     |||          }| dS |r|                    |           6|S )a&  Check if function definition is compatible with base classes.

        This may defer the method if a signature is not available in at least one base class.
        Return ``None`` if that happens.

        Return a list of base classes which contain an attribute with the method name.
        N)r-  r  r  r  __replace__dataclass_tagr~  )rQ  rE  r@  r?  r  rF  r  r  r  r  metadatar  mro*check_method_or_accessor_override_for_baser1  )r,  r  check_override_compatibilityr!  baser  s         r  r  z!TypeChecker.check_method_override  s    <% 	)=A^)^)^4 IZZ 0I8I8I4I 	]* C9%))/::dB 	% 57!IM!""% 	7 	7DDDd8 F ~tt 7)00666((r  r  r  bool | Nonec                   d}|r|j         }|j                            |          }|rit          |j                  r0t          |          s!| j                            ||j         |           |j        r| 	                    ||j        |           d}|rM| 
                    |||          rdS |t          j        v r&d|dd         z   }| 
                    |||          rdS |S )a  Check if method definition is compatible with a base class.

        Return ``None`` if the node was deferred because one of the corresponding
        superclass nodes is not ready.

        Return ``True`` if an attribute with the method name was found in the base class.
        FTNrz  r  )r  r`  r  r   r  r  r@  cant_override_finalr  $check_if_final_var_override_writable(check_method_override_for_base_with_namer   r{  )r,  r  r  r  found_base_methodr  	base_attrr~  s           r  r  z6TypeChecker.check_method_or_accessor_override_for_base  s    " 	$9D
t,,I ) 00 HD9I9I HH00ty$GGG= Z==dINTXYYY$(!+ $ @@tTRR  49===!DH_F
 DDT6SWXX $#t  r  c                   |                      |j        |j        |d          \  }}|                      |j        ||d          \  }}||J t          ||          s$| j                            |j        |||           dS dS )a&  Check override of a setter type of a mutable attribute.

        Currently, this should be only called when either base node or the current node
        is a custom settable property (i.e. where setter type is different from getter type).
        Note that this check is contravariant.
        Tr  N)node_type_from_baser  r  r   r@  incompatible_setter_overrider  )r,  r  r  r*  r  r.  s         r  check_setter_type_overridez&TypeChecker.check_setter_type_override  s     ))$)TYRV)WWQ33DItTW[3\\q=#<#<#<--- 	YH11$+sMSWXXXXX	Y 	Yr  c           
        |j                             |          }|sdS t          |t                    s|}n|j        }t          |t
          t          f          r|j        p|j        }n|j        j        p|j        j        }| 	                    |j
        |j        |          \  }|j
         d|j        j         v sJ dS |j        }d}	| 	                    |||          \  }
}|
<d}	| j        | j        k     rz| j                                        }t          |t
                    r/|                     || j                            |                     n|                     ||j                   dS t          |t
          t          f          r|                     |          }
n~t          |t                    r|                     |j                  }
nNt          |t(                    r+|j        t-          |j                  }
nt/                      }
nt/                      }
d}t1          |          r\t1          |          st          |t(                    r8t3          |          st3          |          r|	rd}|                     ||           t          |t
          t          f          r|j        p|j        }n-t          |t                    r|j        }|j        p|j        }nd}t-                    t-          |
          }
t7          |          rt          |t(                    rk|j        sd|j        r|j        rVt          |t                    rAt          |
t:                    s,| j                            d|j        t@          j!                   t          |
t:                    st          t:                    rn;t          |
tD                    rt          tD                    r| #                    |
|j
        ||j$        | j%        j&        k    r|j
        n|j&        |||          }|r|rt@          j'        | j(        j)        v r| *                    |          rr|sptW          |
d          s^tY          |
| j(                  \  }}tZ          j.        /                    d	|j
         d
| d| d          }|                     ||           n*t          |
t`                    rtc          fd|
j2        D                       r|rt@          j'        | j(        j)        v ru| *                    |          r`|s^tY          |
| j(                  \  }}tZ          j.        /                    d	|j
         d
| d| d          }|                     ||           netg          |
          rnT|r(| *                    |          r|rtW          |
          rn*| j        4                    |j
        ||j
        ||
           dS )zCheck if overriding an attribute `name` of `base` with `defn` is valid.

        Return True if the supertype node was not analysed yet, and `defn` was deferred.
        FNz-redefinitionTz;Cannot override writeable attribute with read-only propertyr  ignore_pos_arg_namesr  z (base class "z" defined the type as z, override has type )c              3  <   K   | ]}t          |d           V  dS )Tr  Nr;  )r  orig_typr*  s     r  r  zGTypeChecker.check_method_override_for_base_with_name.<locals>.<genexpr>o	  sF       :
 :
 sH4@@@:
 :
 :
 :
 :
 :
r  originaloverride)5r`  r  r  rg   r  rp   r   r  	is_staticr  r  r  r  rb  r  rF  r  r  r  r   r   r  r   r   r   is_custom_settable_propertyr  r  r  r   r@  r  r  OVERRIDEr   check_overridemodule_namerZ  r  MUTABLE_OVERRIDErQ  enabled_error_codesis_writable_attributer   rH   r   'COVARIANT_OVERRIDE_OF_MUTABLE_ATTRIBUTEwith_additional_msgr   r@  r  r   %signature_incompatible_with_supertype)r,  r  r  r  r  r  override_class_or_staticr  original_nodesupertype_readyr.  	top_levelalways_allow_covariantoriginal_class_or_staticr  okbase_stroverride_strr@  r*  s                      @r  r  z4TypeChecker.check_method_override_for_base_with_name  s    JNN4((	 	5
 $	** 	 GGiG dW&7899 	Q'+}'F$$'+y'9'PTY=P$))$)TYEEQ; i...$)/AAAA5! 33D$EEq #O}t~-- !J99;;	i11 5OOItz/I/I)/T/TUUUU OOD$)444tMG5F+GHH + $ 2 2= A AM955 + $ 2 2=3E F FM3// + !%1$3M4F$G$GMM$,JJMM !)

!&%% 		@ //		@3=mS3Q3Q		@ +400 @5PQ^5_5_ @ # @-1*33D$???mg/@%ABB 	-'4'='XAX$$y11 	- %D'+}'F$$',$c""'66 	=#..	 "*	 #.		 3@2T		
 4++	 mW55 QI	     mW-- B	C1I1I B	|44 @	C9V9V @	$$	!-1CCC		((	 	B (!( *dl.NNN..}== O. O #=#DQQQ O
 *@!3* * *&, 'Nbb:TY : :h : :*6: : :  		#w'''y11 #	c :
 :
 :
 :
)/:
 :
 :
 7
 7
 #	 (*dl.NNN..}== O. O
 *@!3* * *&, 'Nbb:TY : :h : :*6: : :  		#w'''=#.. 	 
	//>>
	BX
	 3..
	 H::	4GmVY ;    ur  tpc                b    t          |t                    rI|j        r@|j        d         t          k    r*t	          |j        d         d |j        D                       S d S t          |t                    r2 fd|j        D             }d |D             }|rt          |          S d S J d            )Nr   c                    h | ]	}|j         
S r  r  r  r  s     r  	<setcomp>z2TypeChecker.get_op_other_domain.<locals>.<setcomp>	  s    7S7S7S7S7S7Sr  c                :    g | ]}                     |          S r  )get_op_other_domainr  itr,  s     r  rq  z3TypeChecker.get_op_other_domain.<locals>.<listcomp>	  s'    III"11"55IIIr  c                    g | ]}||S r  r  r  r  s     r  rq  z3TypeChecker.get_op_other_domain.<locals>.<listcomp>	  s    222Br2R222r  Fz,Need to check all FunctionLike subtypes here)
r  r   r  rN   r,   r  rO  r   r  r   )r,  r  	raw_itemsr  s   `   r  r  zTypeChecker.get_op_other_domain	  s    b,'' 	I| UQ7 : : &bl1o7S7Sbl7S7S7STTT4J'' 	IIIIIIIII22)222E 4,U3334HHHHHr  r  r  name_in_superr  r  r  c	                $
   d}	d}
t          ||d          sd}	nlt          |t                    rW|                     |          rB|                     |          }|                     |          }|r|rt          ||          sd}	d}
t          |t
                    rQ|r|sd}	nJt          |t                    r5t          |t                    r |j        	|j        d}	|j        	|j        d}	t          |          rd}	|	rd}t          |t                    o|j
        }t          |t          t          f          r|                                }t          |t          t          f          r|                                }t          |t                    rft          |t                    rPt          |j                  t          |j                  k    r%|j        |j        k    r|                                d}t!          |          }t          |t"                    r|j        j        }dfd}t)          t+          |j        |j                            D ]P\  }\  }}|                                r/|                                r|j        |         }|j        |         }nw|                                rb|                                rN|sL|j        |         }||j        v r5|j        |         }|j                            |          }|j        |         }nt          | ||                    st|}t          |t"                    r6|j        s/|j        ||                                z            }|j        d	k    r|}| j                             |d
z   |||||||           d}Rt           ||j!                  |j!                  s+| j        "                    ||||j!        |j!        |           d}nt          |t                    rt          |t                    rg }|j#        D ]C}t)          |j#                  D ],\  }}t          ||          r|$                    |            n-Dt          |          t          |j#                  k    r2|tK          |          k    r| j        &                    ||||           d}|s | j        '                    ||||||           |
r"| (                    d|tR          j*                   |	 S )a  Check a method override with given signatures.

        Arguments:
          override:                 The signature of the overriding method.
          original:                 The signature of the original supertype method.
          name:                     The name of the overriding method.
                                    Used primarily for generating error messages.
          name_in_super:            The name of the overridden in the superclass.
                                    Used for generating error messages only.
          supertype:                The name of the supertype.
          original_class_or_static: Indicates whether the original method (from the superclass)
                                    is either a class method or a static method.
          override_class_or_static: Indicates whether the overriding method (from the subclass)
                                    is either a class method or a static method.
          node:                     Context node.
        FTr  Nr  r   r(  c                &    t          |           S )N)ids_to_erase)r,   )r  override_idss    r  erase_overridez2TypeChecker.check_override.<locals>.erase_override	  s    )!,GGGGr  r  r~  )secondary_contextr  zHOverloaded operator methods can't have wider argument types in overridesr  )r  r   r(  r   )+r   r  r   r3  r  r   r   
type_guardr  r  unpack_kwargsrP  r  r  min_argstype_var_idsr   rp   r  r  r  zipr  is_positionalis_namedr  indexr  r  boundr  r@  $argument_incompatible_with_supertyper  'return_type_incompatible_with_supertyper  r1  sorted.overload_signature_incompatible_with_supertyper  r  r  r  )r,  r  r  r  r  r  r  r  r  r  op_method_wider_noteoriginal_domainoverride_domainemitted_msgoffset_arguments	type_namer  r  r  sub_kind
super_kindoverride_arg_typeoriginal_arg_typearg_name
original_ir  arg_nodeorderchild_variantparent_variantr  s                                 @r  r  zTypeChecker.check_override	  s   8 $(H4HHH 	,DD*-- 	,$2K2KD2Q2Q 	, #66x@@O"66x@@O,#, #?ODD,
 '+$h-- 	 '  0H  Hl33  
8\8Z8Z  &2x7J7RD#/H4D4LDd 	D i	K)(LAA\hF\(\:$>?? ;#88::(\:$>?? ;#88:: 8\22S'x66S' *++s83E/F/FFF%):::  (4466 	)(33
j'22 5 * 4IH H H H H H 2;*H,>??2 2  +  +-A-*  --// !J4L4L4N4N !,4,>q,A),4,>q,A))!**,, 	!1D1D1F1F 	!O_ 	!#+#5a#8#x'999080B10E-)1);)A)A()K)KJ080B:0N--$ %&7HY9Z9Z[[ ++/%dG44 3T=M 3'+~a(..:J:J6J'KH'}22*2EEE %)-%#.2 F 	 	 	 '+!..1B"C"CXEVWW 'HDDmY8I8K\^b   #'KHj11 'j:6V6V ' %-^ " "M-6x~-F-F " ")>%m^DD "!LLOOO!E" u::X^!4!444&--9O9OHKKmY   #'K >>-D8V^ ?    $ 		^    
 xr  c                0   |j         rt          |j         t                    sdS t          |j         j                  }t          |          sdS t          |          }|sdS t          d |D                       r| j        	                    |           dS dS )a;  Generate error if the return type of __exit__ is problematic.

        If __exit__ always returns False but the return type is declared
        as bool, mypy thinks that a with statement may "swallow"
        exceptions even though this is not the case, resulting in
        invalid reachability inference.
        Nc              3  j   K   | ].}t          |j        t                    o|j        j        d k    V  /dS )builtins.FalseN)r  exprr   r  )r  rets     r  r  z7TypeChecker.check__exit__return_type.<locals>.<genexpr>\
  sR       
 
 sx**Tsx/@DT/T
 
 
 
 
 
r  )
r  r  r   r   r  has_bool_itemr   r_  r@  incorrect__exit__return)r,  r  r  rM  s       r  r  z$TypeChecker.check__exit__return_typeI
  s     y 	
49l C C 	F"49#566X&& 	F'-- 	F 
 

 
 
 
 
 	3 H,,T22222		3 	3r  rc   c           
      	   |j         }|j        dd         D ]A}|j        r8|                     t          j                            |j                  |           Bt          |j	                  s8|                     t          j
                            |j                  |           | j                            |j                   5  |                     d          5  | j        }t          | j                  | _        | j                                        5  | j                            |j                   5  |                     |j                   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   || _        |j         j        s-|j         j        s!|j         j        s|                     |           |j        s|                     |           |                     |           |                     |           |j        rt?          |j         | j                   }tC          |j                  D ]}tE          |tF                    rtE          |j$        tJ                    r2| j&                            |          }| '                    ||          }d}	tE          |tP                    r	|j)        pd}	| j*        }
d| _*        | j&        +                    ||gtX          j-        g||	          \  }}|
| _*        ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |j.        j/        r|j.        j0        |j	        D ]}tc          |j2        |j3        j.        j/                  D ]z\  }}tE          |th                    r`|j5        tl          k    rPtE          |th                    r;|j5        |j5        k    r+|                     d|j         d|tn          j8        	           {|j.        j/        r| 9                    |j.        j/                   |j:        r!|j.        j/        r| ;                    |           |j        s!|j         j        r| <                    |           t{          |j                    dS )
zType check a class definition.r~  NTr  r  )callable_namezVariance of TypeVar "z+" incompatible with variance in parent type)r  r  )>r  r  r  r  r   CANNOT_INHERIT_FROM_FINALr  r  r   basesINCOMPATIBLE_DISJOINT_BASESrE  r  r  rA  r   rQ  r  rF  r  r  r  typeddict_type
tuple_typeis_enumcheck_init_subclasshas_incompatible_baseclasscheck_multiple_inheritancecheck_metaclass_compatibilitycheck_final_deletable
decoratorsr   r  reversedr  rb   analyzedr   rx  	temp_noder   r  rm  
check_callr   rN   r  rL  	type_argsr  rt  r  r   r  rU   r  r.   r  r  check_protocol_variance
check_enumr   )r,  r  r*  r  r  sig	decoratordectempr  old_allow_abstract_callr  	base_inst	base_tvarbase_decl_tvars                  r  visit_class_defzTypeChecker.visit_class_defb
  s   iGABBK 	^ 	^D} ^		*DKKDIVVX\]]],SY77 	[II&BII#(SSUYZZZ[$$TY// '	G '	G1I1ISW1I1X1X '	G '	GJ/==DK..00 + +Z**4955 + +KK	***+ + + + + + + + + + + + + + ++ + + + + + + + + + + + + + + %DKI, /	0D /	HY /((...2 5//444..s333&&s+++ G,TYHH!)$/!:!: G GI!)X66 !:!*K< < ! !+229==C>>#y>AAD#H!)W55 >#,#5#= /3.F+/3D,!.99dVem_d( :  FC 0GD,,O'	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	G '	GT 8 	#("4"< Y  	14NIN$7$A2 2  -I~ #9k::%.);;&~{CC <*3y7III		;IN ; ; ;$(!&	 "    8 	<''(:;;;? 	/sx1 	/((.... 	"493D 	"OOD!!!di(((((s   L#:L E35E	E3E  E3#E $E3'L3E77L:E7;FL L#L	L#L	L##L'*L'c                    |j         D ]i}|j                            |          }|rKt          |j        t
                    r1|j        j        r%|                     t          j	        |j                   jd S r+  )
deletable_attributesr`  r  r  r  r   r  r  r   CANNOT_MAKE_DELETABLE_FINAL)r,  r*  attrr  s       r  r!  z!TypeChecker.check_final_deletable
  s|     , 	S 	SD9==&&D S
49c22 Sty7I S		*F	RRR	S 	Sr  c                   |j         j        r|j         j        j        j        dvrdS |j         j        dd         D ]3}d|j        vrt          |j                  }||_        t          |d          }t          |j                                                  }t          |j                                                  }d|v r?|                    d          }|                    |           |                    |           t           gt#          |          z  }t%          ||||          }	|j        |	_        |j        |	_        |j        |	_        | j                            |	dd            dS dS )a  Check that keywords in a class definition are valid arguments for __init_subclass__().

        In this example:
            1   class Base:
            2       def __init_subclass__(cls, thing: int):
            3           pass
            4   class Child(Base, thing=5):
            5       def __init_subclass__(cls):
            6           pass
            7   Child()

        Base.__init_subclass__(thing=5) is called at line 4. This is what we simulate here.
        Child.__init_subclass__ is never called.
        )builtins.typer  Nr~  r  	metaclassTallow_none_returnalways_allow_any)r  r  r  r  r  r`  r   r  r  r~   r  keywordsr  keysr  r;  rM   r  rb   r  r  end_linerx  r  )
r,  r  r  r  calleert  r  r  r  	call_exprs
             r  r  zTypeChecker.check_init_subclass
  sr    9# 		(@(E(N W
 )
 )
 F IM!""% 	 	D"$*44 ++I!IN	+>??F,,..//D*.t}/A/A/C/C*D*DI i''ook22c""""c$ii/I y)DDI!YIN#{I!%I$$Y$Y]$^^^ EE-	 	r  r  Sequence[TypeVarLikeType]c                @   |D ]t          t                    r                                s,t          j        j                  s|                     d           j        r6t          fdj        D                       s|                     d           d S )Nz3TypeVar default must be a subtype of the bound typec              3  B   K   | ]}t          j        |          V  d S r+  )r   r&  )r  r  tvs     r  r  z5TypeChecker.check_typevar_defaults.<locals>.<genexpr>
  s/      $\$\\"*e%D%D$\$\$\$\$\$\r  z3TypeVar default must be one of the constraint types)	r  r   has_defaultr   r&  r/  r  r  r@  )r,  r  rE  s     @r  r  z"TypeChecker.check_typevar_defaults
  s     	U 	UBr;// BNN4D4D bj".99 U		OQSTTTy U$\$\$\$\RTR[$\$\$\!\!\ U		OQSTTT	U 	Ur  c                   |j         j        sJ |j         j        t          vrkd|j         j        v r]|j         j        d         }t          |j        t                    r1|j        j        r%| 	                    t          j        |j                   |j         j        dd         D ]-}|j        r$|j        t          vr|                     ||           .| j        rT| j        j        dvrF|j         j        s:| 	                    d|j         j         d|           |                     d|           |                     |           |                     |           d S )N__members__r~  r  >   enum	_typeshedzDetected enum "z" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use `member = value` to mark an enum member, instead of `member: type`zLSee https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members)r  r  r  r   r`  r  r  r   has_explicit_valuer  r   $ENUM_MEMBERS_ATTR_WILL_BE_OVERRIDDENr  check_final_enumrd  rZ  enum_membersr  check_enum_basescheck_enum_new)r,  r  symr  s       r  r)  zTypeChecker.check_enum
  ss   y    9Z//MTY_4T4T)/-0C#(C(( [SX-H [ 		*OQTQYZZZIM!B$' 	2 	2D| 2Z ? ?%%dD111< 	DI.6KKK9) 		0di&8 0 0 0    		b  
 	d###D!!!!!r  c                V    |j         r!|                     d|j         d|           d S d S )Nz+Cannot extend enum with existing members: "r  )rN  r  r  )r,  r  r  s      r  rM  zTypeChecker.check_final_enum  sC     	XIIPDIPPPRVWWWWW	X 	Xr  rQ  r   c                   t          |j        t          t          f          rdS t          |j        t                    sdS t          |j        j                  s^t          |j        j                  sEt          |j        j                  s,t          t          |j        j
                  t                    rdS | j        p|j        j        S )NFT)r  r  ro   rg   r   r  r  r  r  r   r  r   rd  rK  )r,  rQ  s     r  is_final_enum_valuezTypeChecker.is_final_enum_value  s    ch9 566 	5#(C(( 	4 sx}%%		''		 ''		 /#(-88,GG		 5|:sx::r  c                    d}|j         j        D ]V}||j        j        r|}|A|j        j        s5|                     d|                    | j                   d|            dS WdS )a  
        Non-enum mixins cannot appear after enum bases; this is disallowed at runtime:

            class Foo: ...
            class Bar(enum.Enum, Foo): ...

        But any number of enum mixins can appear in a class definition
        (even if multiple enum bases define __new__). So this is fine:

            class Foo(enum.Enum):
                def __new__(cls, val): ...
            class Bar(enum.Enum):
                def __new__(cls, val): ...
            class Baz(int, Foo, Bar, enum.Flag): ...
        Nz-No non-enum mixin classes are allowed after "r  )r  r  r  r  r  r  rQ  )r,  r  	enum_baser  s       r  rO  zTypeChecker.check_enum_bases(  s      &*	IO 		 		D TY%6  	&ty/@&		oID^D^_c_kDlDlooo   		 		r  c                ^   ddd}|j         j        D ]}d}|j        j        r.t	          fd|j        j        dd	         D                       }n |j                  }|rD|rB|                     d
                    |                    | j	                            |           |rd}d S )Nr  r   r(  r!  c                x    |                      d          }t          |o|j        o|j        j        dk              S )Nr  zbuiltins.object.__new__)r  r!  r  r  )r  
new_methods     r  has_new_methodz2TypeChecker.check_enum_new.<locals>.has_new_methodE  sG    ),,J JOJO,0II  r  Fc              3  >   K   | ]}|j          o
 |          V  d S r+  )r  )r  brZ  s     r  r  z-TypeChecker.check_enum_new.<locals>.<genexpr>S  s6      aaAI C..2C2Caaaaaar  r~  r  zLOnly a single data type mixin is allowed for Enum subtypes, found extra "{}"T)r  r   r(  r!  )
r  r  r  r  r@  r  r  r  r  rQ  )r,  r  has_newr  	candidaterZ  s        @r  rP  zTypeChecker.check_enum_newD  s    	 	 	 	 IO 	 	DIy  6aaaaTY][\]_[_M`aaaaa		*N4955	 W 		''-vd.C.CDL.Q.Q'R'R   
  !	 	r  c                V  
 |j         dS |j        }t          |j        d         g           |j        j        }t          |          D ]\  
}t          |t                    s
fdt          |          D             }
fdt          |          D             }t          ||          t          ||          }}t          ||d          rt          }	n!t          ||d          rt          }	nt          }	|	|j        k    r'| j                            |j        |j        |	|           dS )a/  Check that protocol definition is compatible with declared
        variances of type variables.

        Note that we also prohibit declaring protocol classes as invariant
        if they are actually covariant/contravariant, since this may break
        transitivity of subtyping, see PEP 544.
        Nr  c                X    g | ]&\  }}|k    rnt          t          j                  'S r  )r   r   r  )r  rX  r  r  object_types      r  rq  z7TypeChecker.check_protocol_variance.<locals>.<listcomp>r  sD     # # #Aq  !Avv793I+J+J# # #r  c                p    g | ]2\  }}|k    rt                      nt          t          j                  3S r  )r   r   r   r  )r  rX  r  r  s      r  rq  z7TypeChecker.check_protocol_variance.<locals>.<listcomp>v  sK     % % %Aq &'!VV!!!9O1P1P% % %r  T)ignore_declared_variance)r'  r  r   r  r  rL  r  r  r   r   rQ   rP   rU   r  r@  bad_proto_variancer  )r,  r  r  r  r  up_args	down_argsupdownr  r  ra  s             @@r  r(  z#TypeChecker.check_protocol_variance`  sk    >%Fytx|R00	# '' 	V 	VGAtdK00 # # # # #%e,,# # #G% % % %%e,,% % %I  g..y0I0IB$TBBB %$BtDDD %($4=((++DM49hPTUUU+	V 	Vr  c                   t          |j                  dk    rdS |j        dd         }d |D             }t          ||j                                        z
            D ]wt                    rt          fdt          |          D                       \  }}||dz   d         D ],}|j        v r!||j        vr| 	                    |||           -xdS )z.Check for multiple inheritance related errors.r~  Nc                &    h | ]}|j         D ]}|S r  r`  )r  r  r  s      r  r  z9TypeChecker.check_multiple_inheritance.<locals>.<setcomp>  s'    AAAddjAAdTAAAAr  c              3  8   K   | ]\  }}|j         v ||fV  d S r+  rk  )r  r  r  r  s      r  r  z9TypeChecker.check_multiple_inheritance.<locals>.<genexpr>  s7      YYDddjFXFXAt9FXFXFXFXYYr  )
r  r  r  r  r`  r>  r  nextr  check_compatibility)r,  r*  r  	all_namesr  r  base2r  s          @r  r  z&TypeChecker.check_multiple_inheritance  s   sy>>QFgabbkAAcAAA	9sy~~'7'7788 	E 	ED $  YYYYIcNNYYYYYGAtQUWW E E5;&&5+@+@,,T4DDDE	E 	Er  base1rp  c           	     T   |dv rdS |j         |         }|j         |         }|                     ||||          \  }}|                     ||||          \  }	}t          |          }
t          |	          }t          |
t                    rt          |t                    r|
                                re|                                rQt          t          |
                                          t          |                                                    }nQ|r|	sJ t          ||	d          }n7|r|	r|j	        +| 
                    |j	                  st          ||	          }nt          ||	          }|r|j	        r|j	        r| 
                    |j	                  r~t          |j	                  rjt          |j	        t                    rPt          |t                    s;| j                            d| d|j         d	|j         d
|t$          j                   nH|!| j                            ||j        |           |	!| j                            ||j        |           d}t+          |j	                  r0t-          |          s!| j                            ||j        |           t+          |j	                  r|                     ||j	        |           t          |j	        t2                    r|j	        j        rd}|s| j                            ||||           dS dS )ay  Check if attribute name in base1 is compatible with base2 in multiple inheritance.

        Assume base1 comes before base2 in the MRO, and that base1 and base2 don't have
        a direct subclass relationship (i.e., the compatibility requirement only derives from
        multiple inheritance).

        This check verifies that a definition taken from base1 (and mapped to the current
        class ctx), is type compatible with the definition taken from base2 (also mapped), so
        that unsafe subclassing like this can be detected:
            class A(Generic[T]):
                def foo(self, x: T) -> None: ...

            class B:
                def foo(self, x: str) -> None: ...

            class C(B, A[int]): ...  # this is unsafe because...

            x: A[int] = C()
            x.foo  # ...runtime type is (str) -> None, while static type is (int) -> None
        )r-  r  r  N)r[  leftrightTr  z%Cannot override writeable attribute "z" in base "z#" with read-only property in base "r  r  )r`  r  r   r  r   is_type_objr   r   type_objectr  r  r   r  rg   r   r@  r  r  r  r  cannot_determine_type_in_baser   r  r  r  r   allow_incompatible_override#base_class_definitions_incompatible)r,  r  rq  rp  r&  rw  rx  
first_typer  second_typep_first_typep_second_typer  s                r  rn  zTypeChecker.check_compatibility  s   . ???FD!T"00ucQT0UU
A11$sRU1VVQ 'z22'44lL11 $	jP\6]6] $	'')) 	Tm.G.G.I.I 	T  /0H0H0J0JKK01J1J1L1LMM  
 "1k111
KdSSS 	K 	{&t/I/I&+/V/V&
K88":{;; J 226;?? $EJ//	
 #5:y99 '}g>> HMMK K KQVQ[ K K=BZK K K"^	 "    !66tUZMMM"66tUZMMMB %% 	@j.>.> 	@H((uz3???$$ 	N55dFKMMM fk3'' 	FK,S 	B 	RH88ueSQQQQQ	R 	Rr  c                t   |                                 s|j        s|j        s|j        s|j        dS |j        zt          d |j        D                       r^|                     d|t          j
                   |                                }|r(|                     ||t          j
                   dS dS dS dS )z<Ensures that metaclasses of all parent types are compatible.Nc              3  2   K   | ]}|j         j        d uV  d S r+  )r  r  r  r  s     r  r  z<TypeChecker.check_metaclass_compatibility.<locals>.<genexpr>  s=       .
 .
59DI$D0.
 .
 .
 .
 .
 .
r  zxMetaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its basesr  )rN  r  is_named_tupler  r  r  r@  r  r  r  	METACLASSexplain_metaclass_conflictr  )r,  r*  explanations      r  r   z)TypeChecker.check_metaclass_compatibility  s    		 !	 {		
 !-F%# .
 .
=@Y.
 .
 .
 +
 +
% IIN_	     88::K B		+s	AAAAA &%%%B Br  rw   c                    |j         D ]<\  }}| j                            |          x}|                     |j        |           =|                     |           d S r+  )r`  rM  r  warn_deprecatedr  check_import)r,  r  r  r  rQ  s        r  visit_import_fromzTypeChecker.visit_import_from  se    z 	5 	5GD!|''---:$$SXt444$r  ru   c                0    |                      |           d S r+  r  r  s     r  visit_import_allzTypeChecker.visit_import_all      $r  rt   c                0    |                      |           d S r+  r  r  s     r  visit_importzTypeChecker.visit_import  r  r  rv   c           	     f   |j         D ]}|j        d         }|                     |          \  }}}|t          t          j                  }t          |j        t                    sJ t          j
                            |j        j                  }|                     ||j        ||dd           d S )Nr   z
local namezimported name)r@  r'  r(  )assignmentslvaluescheck_lvaluer   r   r  r  rvaluer   r   INCOMPATIBLE_IMPORT_OFr  r  r-  )r,  r  assignlvaluelvalue_typer  rz  messages           r  r  zTypeChecker.check_import  s    & 	 	F^A&F!%!2!26!:!:KB"%i&<==fmX66666&=DDV]EWXXG(((+ )    	 	r  r\  r_   c                   |j         r| j                                         d S |j        D ]}| j                                         rJ|                                 s d S |                     |          s| j                            |            d S e|                     |           | j	        j
                                         d S r+  )r  rA  r  r  r  r  r@  r  r  rx  
expr_cacher  )r,  r\  ss      r  visit_blockzTypeChecker.visit_block-  s     	 K##%%%F 
	5 
	5A{))++ 	5<<>> EE44Q77 H221555EE A!,224444
	5 
	5r  c                    |                                  o-| j        j        o!| j         o| j                                         S r+  )in_checked_functionrQ  warn_unreachablerc  rA  !is_unreachable_warning_suppressedrw  s    r  r  z,TypeChecker.should_report_unreachable_issues@  sO    $$&& D-D..D KAACCC		
r  r  c                *   t          |t                    rt          |j                  rdS t          |t          t
          f          rdS t          |t                    rt          |j        t                    rdS t          |j        t                    r~| j	        j
                            d          5  t          | j	                            |j        dd                    }ddd           n# 1 swxY w Y   t          |t                    rdS dS )a  Returns 'true' if the given statement either throws an error of some kind
        or is a no-op.

        We use this function while handling the '--warn-unreachable' flag. When
        that flag is present, we normally report an error on any unreachable statement.
        But if that statement is just something like a 'pass' or a just-in-case 'assert False',
        reporting an error would be annoying.
        T)filter_revealed_typer:  NF)r  r\   is_false_literalr  r   r   rl   rj   rb   rx  r@  filter_errorsr   r  r   )r,  r  r*  s      r  r  z$TypeChecker.is_noop_for_reachabilityH  sK    a$$ 	 )9!&)A)A 	 4Ix011 	 4>** 	 !&,//  tAFH-- 	 &*88d8SS  ))00FdT 1   C               c?33  4us   50C11C58C5r^   c                   |j         r| j        sf|                     |j                  5  |                     |j        d         |j        |j        du |j                   ddd           n# 1 swxY w Y   |j         r| 	                    |           |j        | j
        j        rt          |j                  rut          |j        d         t                    r4| j                            dt#          t$          j                  |           n!| j                            d|j        |           t)          |j        | j
        | j        | j        |           t-          |j                  dk    r|                     |j                  s| j                            |j                   |                     |                     |j                  |          }|j        dd         D ]R}|                     |j                  5  |                     |||j        du            ddd           n# 1 swxY w Y   S|                     |           |j        rT|j        rMt;          |j                  s9| j                                         |                      tB          j"        |           |j#        r1| $                                s| j        %                    |           dS dS dS )z|Type check an assignment statement.

        Handle all kinds of assignment statements (simple, indexed, multiple).
        r  NzA type on this linezType of variabler  r~  )&is_alias_defrd  enter_final_contextis_final_defcheck_assignmentr  r  r  
new_syntaxcheck_type_alias_rvaluerQ  r  r   r  r   r@  r  r   r   r  r   rf  r  has_typerx  r  r%  lookup_typecheck_finalr  rF  rK  r  r   DEPENDENT_FINAL_IN_CLASS_BODYunanalyzed_typer   annotation_in_unchecked_function)r,  r  r  lvs       r  visit_assignment_stmtz!TypeChecker.visit_assignment_stmtd  s|     	]4< 	]))!.99 ] ]%%aimQXqv~q|\\\] ] ] ] ] ] ] ] ] ] ] ] ] ] ] > 	,((+++ F4 ,QV44  !)B-33 T 44)793I+J+JA    445GQRSSSqvt|T5JDH^_````qy>>A ==** 3!((222^^D$4$4QX$>$>BBFin F F--an== F F))"fafnEEEF F F F F F F F F F F F F F F 	N	I	I $AF++	I 
''))5II&DaHHH 	AT%=%=%?%? 	AH55a5@@@@@	A 	A 	A 	As#   5A**A.1A.?H**H.	1H.	c                    | j                                         5  | j                            |j                  }d d d            n# 1 swxY w Y   |                     |j        d         |           d S Nr  )r@  r  rx  r  r  
store_typer  )r,  r  
alias_types      r  r  z#TypeChecker.check_type_alias_rvalue  s    X##%% 	< 	<*11!(;;J	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<	"z22222s    AA
A
r  r|   r  rk   infer_lvalue_typer  c                ~   t          |t          t          f          r|                     |j        |||           dS |                     ||d           |                     ||          \  }}}t          |t                    rL|j        rD|j        j	        }|dv rU|r|}	n| j
                            |          }	|	r4|dk    r|                     |	|           n|                     |	||           |dk    rK| j                                        2|p| j
                            |          }
|                     |
|           |dk    r3|1| j
                            |          }
|                     ||
|           |dk    rO| j                                        }|r4t%          j        |          r |                     t*          j        |           t          |t.                    r+|j	        dk    r |                     t*          j        |           |rt          |t2                    r|j        | j
                            |          }t          t7          |          t8                    rdS |j        }t=          || j        |j                   ru| !                    |          }|\| j"        sDtG          |          }tI          |t9                      g          }| %                    |||           nd|_        ||= |j        }n| &                    |j        ||           ntO          |          rAt          |t                    r,t          |j        tP                    r|j        j)        r|s|}nt          |t.                    rF|j*        ?| j
                            |j+                  }| ,                    |||||	          \  }}}n$| j        j-        stO          |          rt          |t                    r|j*        t\          k    rt          |j        tP                    r|j        j        r|j        | j/        v rt          t7          |          t`                    so| j/        |j                 }d
}tc          | j2        j3                  D ]}|j4        |v r	|j5        } n|r+tm          |          }| %                    |j        ||           | 7                    |||||          \  }}d}t7          |          }t7          |          }t          |tp                    r|9                                r|:                                j;        s|:                                j<        rnt          |tz                    rYt          |j>        t~                    r?|j>        j        j;        s|j>        j        j<        r| j@        A                    ||           dS |r|rt          |t2                    st          |t                    r|jB        s~| j2        C                    |||           t          |t                    rMt          |j        tP                    r3|j        jD        r'|j        jE        r|tG          |          |j        _        nD| j        j-        r|| j2        C                    |||           n|r| F                    |||           |r| G                    ||          }| j
                            ||          }|j         s6|jE        s/t          |t                    r|j	        dk    stG          |          }| H                    ||||           | I                    |           t          |t                    r8t          |t                    r|j	        dk    s| K                    ||           dS dS dS )z0Type check a single assignment: lvalue = rvalue.=)r  r  r  r  	__slots__N__match_args__r  )is_lvalue_finalr  F)r  inferredr  r|  )Lr  r   r{   $check_assignment_to_multiple_lvaluesr  .try_infer_partial_generic_type_from_assignmentr  r   r  r  rx  r  r  r  rF  rK  r  r  r  r  r  r   &DATACLASS_POST_INIT_MUST_BE_A_FUNCTIONr~   CANNOT_MODIFY_MATCH_ARGSr   r  r   r   r  is_valid_inferred_typerQ  r  r  rc  r-   r   set_inferred_typeinfer_partial_typeis_literal_noner   is_initialized_in_classkindr  check_member_assignmentr  rW   rV  r   r#  rA  r  r  r  r   r-  r   rv  rw  is_abstractr  r   r  r   r@  concrete_only_assignis_special_formr  is_inferredis_index_varcheck_indexed_assignmentget_variable_type_contextinfer_variable_typecheck_assignment_to_slotsr   check_compatibility_all_supers)r,  r  r  r  r  r  index_lvaluer  r  	signaturer*  rK  rvalue_typer  rJ  inferred_typeinstance_typedecl_frame_maphas_if_ancestorr  p_rvalue_typep_lvalue_typer|  s                          r  r  zTypeChecker.check_assignment  sx    fy(344 l	D55ff.?     ??PSTTT262C2CFF2S2S/Kx &(++ c c{'MMM" E$/		$($5$<$<V$D$D	  O=00 55iHHHH 55iNNN;&&4:+B+B+D+D+P%I):)A)A&)I)IC//V<<<+++0D+226::C))(C@@@?**#':#:#:#<#<L# c(:(QR^(_(_ c		"2"Y[abbb&*-- M&+AQ2Q2Q		*CVLLL tLk;77 M$K<L<T"&"3":":6"B"BK!/+">">II  %/C-#T\3<   V )-(?(?(D(D(4#'#= 0.OP[.\.\0E{T\T^T^F_0`0` $ 6 6sFM R R R R+/ -c 2*-(K //UUUU#F++2$"68442$ #6;442$ ;	2$
 '2$ #.KKvz22)$7={7J$($5$<$<V[$I$IMBFB^B^{FF C_ C C?K.?.? !L?U+F33U 'vx88U #K4//&v{C88 0"K, 0 #K4+??? *?;+G+G Q Q @ *.)=fk)J +0%-dk.@%A%A & &E$x>99272I %  : + U*<[*I*IK 226;TTT/3/K/K#VVhW] 0L 0 0,K
  $H !0 < < / < <}l;;%1133 &1133?	
 )4466B #=(;; #=#5x@@ &*/; @M?Q?V?b H11-HHHF N#4 NZU`=a=a N&vx88 	^V=S 	^//[QQQ&vx88^ *6; < <^ !' 7^ !' 8	^
 !, 7/PQ\/]/]FK,\8 N[=TK++FKMMM L--lFFKKK 	P#==hOO"/66vL6YY%Q,Q #6844Q :@HX9X9X"CK"P"PK((6;OOO**6222&'** D68,,D17@P1P1P
 33FFCCCCCD D1P1Pr  )builtins.list+)builtins.set|r   partial_type_augmented_opsr  c           
     v   g }|j         r|j         j        dd          D ]}|j        |j        vr|j        |j                 j        }|                     |j        ||t          |          p$t          |t                    ot          |                     \  }}|rFt          |t                    r|j
        s*t          |t                    s|                    |           |s|j        dk    rE| j                                        ,|                     d          }|                     d|g          S |j        dk    rE| j                                        r,|                     d          }|                     d|g          S d S |d         }	|D ](}
t%          |
|	          r|
}	t'          |	|
          s d S )|	S )	Nr~  r  r  r  r  r  r  r   )r  r  r  r`  r  r  	is_methodr  r   r(   invalid_partial_typer   r1  rF  rK  r  r  is_top_levelr   r   )r,  r  r  type_contextsr  	base_node	base_typer  r  r^  others              r  r  z%TypeChecker.get_variable_type_contextW  s   = 	4 )!""- 4 4=
22 !Jx}5:	#77M&y11 7!)S11 7+I666  8    	1 4'	3774<E<Z4 'y+>>4
 "((333 	}++
0G0G0I0I0U??>::../@8*MMM}	))dj.E.E.G.G)??>::../@8*MMM4!!$	" 	 	E 	22 !			511 tt r  opc                $   d}t          |t                    rAt          |j        t                    r't          |j        j        t
                    r|j        }n/t          |t                    r| j                            |          }||j        }t          |t
                    sJ |j        dS |dk    r|j        j	        |f| j
        vrdS |                     |          }|dS | j                            |          }t          |          }t          |t                    r5|j        |j        k    r!t          || j                  r||_        ||= dS dS dS t          |t"                    r t%          |j                  |_        ||= dS dS dS )aE  Try to infer a precise type for partial generic type from assignment.

        'op' is '=' for normal assignment and a binary operator ('+', ...) for
        augmented assignment.

        Example where this happens:

            x = []
            if foo():
                x = [1]  # Infer List[int] as type of 'x'
        Nr  )r  r   r  r   r  r   r~   rx  get_partial_self_varr  r  r  r  r   r   r  rQ  r   r   )r,  r  r  r  r  r*  rJ  r  s           r  r  z:TypeChecker.try_infer_partial_generic_type_from_assignment  s    vx((	A6;,,	A 6;+[99	A
 +CC
++ 	A#88@@C?(Cc;/////xSyych/4D<[[[ !33C88M$+226::K)+66K+x00 '#sx//4J5 5/  +CH%c***	 0///
 K11 '1#(;;!#&&&/ ?*' 'r  r   c           	        |j         }t          |t                    r|j        |j        k    s|j        r|j        s||j        t          d fv rgt          |j	        j
                  dk    rO|j	        j        dd          D ]_}|j                            |j                  }|<|                     |||j                   s n|                     |||j                   s n`|j	                                        }|r|d         nd }d }|j        rS|j        sLt          |j        t&                    s|j        nd }	| j                            ||	          }
|j        }|
|_        |                     |j        |j	        |          \  }}|j        r|j        s||_        |sd S |j	        j        dd          D ]	}|j        r|j        dk    r|j        dk    s!t3          |j                  r6|                     |j        ||          \  }}t5          |          }t          |t&                    rd }|r|J |                     ||||||          s d S |rW|rU|                     |j        ||d          \  }}|J t9          ||          s | j                            ||||            d S ||u r d S d S d S d S d S d S d S )	Nr   r~  r  r  r  )r  Tr  )r  r  r   r  r  explicit_self_typer  rY   r  r  r  r  r`  r  r  "check_compatibility_classvar_supercheck_compatibility_final_superdirect_base_classesr  r   rx  r  r  ry  r  r  r  check_compatibility_superr   r@  r  )r,  r  r  lvalue_noder  tnodedirect_baseslast_immediate_baseactual_lvalue_typer&  r  r  r  r  r  custom_setters                   r  r  z*TypeChecker.check_compatibility_all_supers  s   k {C((Z	  FK//* 0#6 0 d|++K$*++a//#(,QRR0 	 	
{'788$BB;PTV[V`aa ??TSXS]^^ &+??AAL6B"L,r"2"2
 "&& /{/M /.89I;.W.Wak&&]a"/66vsCC%0%5"#. !55k6FHXZ`aaNK& 6{/M 6#5  #(,QRR0 . . : $33IZ8Z8Zk.// '+'?'?@PRVX^'_'_$	9 ;I F Fi55 % $I $00099#!!/< :   
 " #} #'+'?'?',dF (@ ( (	1
  )444))[AA # HAA &Y   #FF222 uZ	 Z	 ,+	 0///
 0/B. .r  compare_typer  r  r   r  c           
        |                      |||t          j        dd|j         d          }|r\t          j        | j        j        v rD|                     |          r/|s-|                      |||t          j	        d|j         dd          }|S )Nzexpression has typezbase class "z" defined the type as)
r  r    INCOMPATIBLE_TYPES_IN_ASSIGNMENTr  r  r  rQ  r  r  r  )r,  r  r  r  r  r  r  r  s           r  r  z%TypeChecker.check_compatibility_super  s     =!;49;;;
 
 	&$,*JJJ**955 K* K ## H?ty???% B 	r  )r  r  r[  r  r  r[  %tuple[Type | None, SymbolNode | None]c          	        |j                             |          }|rNt          |j        t          t
          f          r|j        r&t          |j        t                    r|j        j        dS || j        	                                }nt          |          }|
J d            t          |t                    rt          |          }	n|}	t          |dt          j                            |          ||| d          }
| j                            d          5  |r6|	j        j        p|
                    d          }t+          |	||
||	          }nt-          ||	|
|          }ddd           n# 1 swxY w Y   ||j        fS )
a  Find a type for a name in base class.

        Return the type found and the corresponding node defining the name or None
        for both if the name is not defined in base or the node type is not known (yet).
        The type returned is already properly mapped/bound to the subclass.
        If setter_type is True, return setter types for settable properties (otherwise the
        getter type is returned).
        NNNz)Internal error: base lookup outside classFT)r+  r,  r-  r.  r  r&  suppress_errorsfilter_deprecatedr8  )mcs_fallbackoverride_info)r`  r  r  r  r   rg   r  r   rF  current_self_typer   r   r   r$   rn  ro  is_operator_methodr@  r  r  r  r%   r&   )r,  r  r  r  r  r  r[  r  rR  r  mxr  r  s                r  r  zTypeChecker.node_type_from_base2  s   $ JNN4((	 	).3	*:;;	 N	 ).+66		
 #/: 
4466II%m44I$$&Q$$$i++ 	!%i00HH H!99$??# 
 
 
 X##d#;; 	U 	U U#=7Y2==;Y;Y:dBXT  		 ;42tTT		U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U ).((s   AE00E47E4Node | Nonec                T   t          |t                    sdS |j        rA|j        s:|                     t          j                            |j                  |           dS |j        sA|j        r:|                     t          j                            |j                  |           dS dS NTF)	r  r   is_classvarr  r   CANNOT_OVERRIDE_INSTANCE_VARr  r  CANNOT_OVERRIDE_CLASS_VARr,  r  r  r  s       r  r  z.TypeChecker.check_compatibility_classvar_supern  s     )S)) 	4 	I$9 	II&CJJ49UUW[\\\5! 	i&; 	II&@GG	RRTXYYY5tr  c                   t          |t          t          t          f          sdS t	          |j                  rdS |j        rD|j        st          |t                    s(| j                            |j        |j        |           dS |j        r:|j	        t          v s|j        t          v rdS |                     |j        ||           dS )a  Check if an assignment overrides a final attribute in a base class.

        This only checks situations where either a node in base class is not a variable
        but a final method, or where override is explicitly declared as final.
        In these cases we give a more detailed error message. In addition, we check that
        a final variable doesn't override writeable attribute, which is not safe.

        Other situations are checked in `check_final()`.
        TF)r  r   ro   rg   r  r  r  r@  r  r  r   r   r  r  s       r  r  z+TypeChecker.check_compatibility_final_super{  s     )c8Y%?@@ 	4di   	4 	4= 	
9c8R8R 	
 H((DItDDD5= 	R}
**di;M.M.Mt55diDQQQtr  c                v    d}|r|                      |          }|r| j                            ||           dS dS )a  Check that a final variable doesn't override writeable attribute.

        This is done to prevent situations like this:
            class C:
                attr = 1
            class D(C):
                attr: Final = 2

            x: C = D()
            x.attr = 3  # Oops!
        TN)r  r@  final_cant_override_writable)r,  r  r  r&  writables        r  r  z0TypeChecker.check_if_final_var_override_writable  sT      	=11)<<H 	=H11$<<<<<	= 	=r  c                    | j         S )z:Check whether we a currently checking a final declaration.rj  rw  s    r  get_final_contextzTypeChecker.get_final_context  ry  r  r  c              #  V   K   | j         }|| _         	 dV  || _         dS # || _         w xY w)zDStore whether the current checked assignment is a final declaration.Nr  )r,  r  old_ctxs      r  r  zTypeChecker.enter_final_context  sH       $)	)EEE!(DD((((s    	(8AssignmentStmt | OperatorAssignmentStmt | AssignmentExprc                   t          |t                    r|                     |j                  }n&t          |t                    r	|j        g}n|j        g}t          |t                    r|j        nd}|r| j        	                                x}r|d         }t          |t                    sJ |j        xt          |j        t                    sJ |j        j        rP|j        j        sD| j        s=t          |t                    r(|j        !|j        s| j                            |           |D ]}t          |t                    rt          |j        t                    r|j        j        }| j        	                                }||j        dd         D ]p}|j                            |          }	|	rRt          |	j        t                    r8|	j        j        r,|s*| j                            ||	j        j        du |            nq|j        j        r*|s(| j                            ||j        j        du |           dS )a  Check if this assignment does not assign to a final attribute.

        This function performs the check only for name assignments at module
        and class scope. The assignments to `obj.attr` and `Cls.attr` are checked
        in checkmember.py.
        Fr   Nr~  )r  r^   flatten_lvaluesr  r]   targetr  r  rF  rK  r   r  r   final_unset_in_classfinal_set_in_initrd  r  r  r@  final_without_valuer  r  r`  r  r  cant_assign_to_finalr  )
r,  r  lvsis_final_declrK  r  r  r
  r  rQ  s
             r  r  zTypeChecker.check_final  s`    a(( 	&&qy11CC>** 	8*CC8*C*4Q*G*GRU 	4dj.E.E.G.GGl 	4QBb'*****w"!"'3/////G04G54 !L4 q.114 * )7 +
 H00333 	Q 	QB"g&& Q:bgs+C+C Qw|j--//? !$ 	& 	&"jnnT22  &:ch#<#< &"x0 & & $ = =dCHMUYDY[\ ] ] ] %7# QM QH11$8LaPPP'	Q 	Qr  c                   t          |t                    sd S t          | j                            |j                            }t          |t                    r-|j                                        rt          |j	                  }t          |t                    sd S |j        j        d S |j        |j        j        v rd S |j        j        d d         D ]}|j                            d           d S  |j                            |j                  }|d S |                     ||j                  rd S |                     t&          j                            |j        |j        j                  |           d S )Nr  r  )r  r~   r   rx  r  r  r   r  is_selfr/  r   r  slotsr  r  r`  r  is_assignable_slotr  r   NAME_NOT_IN_SLOTSr  r  )r,  r  inst	base_infor  s        r  r  z%TypeChecker.check_assignment_to_slots  sm   &*-- 	Ft077DDEEdK(( 	5TW__->-> 	5"4#344D$)) 	F9?"F;$)/))Fss+ 	 	I""=11= 	 > Y]]6;//
 F""6:?;; 	F		.55fk49CUVVX^	
 	
 	
 	
 	
r  c                |    t          dd           rdS t          |          }|t          |t                    rdS t          |t                    r|j                            d          d uS t          |t                    rdS t          |t                    r!t           fd|j
        D                       S dS )Nr  FT__set__c              3  D   K   | ]}                     |          V  d S r+  )r&  )r  ur  r,  s     r  r  z1TypeChecker.is_assignable_slot.<locals>.<genexpr>"  s3      MMat..vq99MMMMMMr  )getattrr   r  r   r   r  r  r   r   r_  r  )r,  r  r*  s   `` r  r&  zTypeChecker.is_assignable_slot  s    664(( 	5c"";*S'22;4c8$$ 	7
 8<<	**$66c<(( 	4c9%% 	NMMMMM39MMMMMMur  rvalueslist[Expression]c           	        g }|D ]P}t          |t                    s|                    |           .t          | j                            |j                            }t          |t                    s|                    |           |j        D ]}t          |t                    s#|                    t          |                     :t          |j                  }t          |t                    r|j        }n)t          |t                    r|j        j        dk    sJ |}|                    t          t          |                               ĐR|S )zFlatten expression list by expanding those * items that have tuple type.

        For each regular type item in the tuple type use a TempNode(), for an Unpack
        item use a corresponding StarExpr(TempNode()).
        builtins.tuple)r  r   r1  r   rx  r  r  r   r  r   r   r  r   r/  r   r  )r,  r/  new_rvaluesrvr*  r  unpackedr  s           r  flatten_rvalueszTypeChecker.flatten_rvalues%  s`     	E 	EBb(++ ""2&&&!$"3":":27"C"CDDCc9-- ""2&&&Y E E!!Z00 E&&x{{3333.qv66H!(,<== ,#+#7 'x:: ( 6:J J J J J#+&&x0B0B'C'CDDDDE r  r  list[Lvalue]c                >   t          |t          t          f          rg }d d }t          |                     |j                            D ]T\  }t          t                    r#t          | j        	                    j
                            }|                     |          rt          |t                    r;|                     ||          k    r!|                     t          j        |           |	|dz   |k    r.|                               |}|                     ||          |                     t          j        |           
|                     t          j                            |          |           ?|                               Vd }	d }
t          |          D ]v\  }t          t                    r\t          | j        	                    j
                            }|                     |          rt          |t                    r|	|}	|}
w|	i|
ge|
|	z
  dz   }t)          |          t)          |          |z
  z
  }|dk    r5|d|	         fdt+          |          D             z   ||
dz   d          z   }|                     |t)          |          |          rDt/          d t          |          D             t)          |                    }|d |         }|t)          |          k    rt1          t          ||                   nd }||dz   d          }|                     ||t)          |                    \  }}}t5          t7          ||                    }|r@t          |          }|                    |           |                    |j
        |f           |                    t7          ||                     |D ]\  }}|                     |||           d S d S |                     ||||           d S )Nr~  r   c                2    g | ]}t                     S )r  r   )r  r  iterable_typervals     r  rq  zDTypeChecker.check_assignment_to_multiple_lvalues.<locals>.<listcomp>y  s&    ___Q8M4@@@___r  c              3  J   K   | ]\  }}t          |t                    |V  d S r+  r  r   r  r  r  s      r  r  zCTypeChecker.check_assignment_to_multiple_lvalues.<locals>.<genexpr>  s5      SS51b*R:R:RSQSSSSSSr  ) r  r   r{   r  r6  r  r   r   rx  r  r  type_is_iterabler   iterable_item_typer  r   CONTIGUOUS_ITERABLE_EXPECTEDr1  ITERABLE_TYPE_EXPECTEDr  r  r   check_rvalue_count_in_assignmentrm  r   split_around_starr  r  set_lineextendr  check_multi_assignment)r,  r  r  r  r  r/  last_idxidx_rvaltypsiterable_startiterable_endr  iterable_numrvalue_needed
star_indexleft_lvsstar_lv	right_lvsleft_rvsstar_rvs	right_rvslr_pairsrv_listr  r4  r;  r<  s                            @@r  r  z0TypeChecker.check_assignment_to_multiple_lvaluesD  s|    fy(344 K	U
 )+G)-M#'H"+D,@,@,N,N"O"O ) )$dH-- )*4+<+C+CDI+N+NOOD,,T22 az$7Q7Q a(4$JaJa &K K : : !II&6&SU\]]]]'/8a<83K3K 't 4 4 4+3040G0Gf0U0U $		*:*WY` a a a a		"2"I"P"PQU"V"VX_````NN4(((()-N'+L$W-- ) )4dH-- )*4+<+C+CDI+N+NOOD,,T22 )z$7Q7Q ))1-.N'(* ,!-+n<q@ #GG|0K L 1$$. 01_____%P]J^J^___`!,"2"4"456  44Wc'llGTT E!SSIg$6$6SSSUXY`UaUa 
 #;J;/;EW;U;UD7:#6777[_  $JN$4$45	040F0FZW1 1-(I  Hh 7 788 =&x00G$$V,,,OOW\7$;<<<Iy 9 9:::& E EFB))"b2CDDDD/E E,E E ''BSTTTTTr  rvalue_countrvalue_unpack
int | Nonec                   |t          d |D                       s|                     d|           dS t          |          |k    r"|                     t          j        |           dS t          d t          |          D                       }|}t          |          |z
  dz
  }|}||z
  dz
  }	||	k    s||k    r |                     t          j        |           dS t          d |D                       rEt          |          dz
  |k    r.| j                            |t          |          dz
  |           dS n>|t          |          k    r+| j                            |t          |          |           dS dS )Nc              3  @   K   | ]}t          |t                    V  d S r+  r>  )r  es     r  r  z?TypeChecker.check_rvalue_count_in_assignment.<locals>.<genexpr>  s,      @@1z!X..@@@@@@r  z/Variadic tuple unpacking requires a star targetFc              3  J   K   | ]\  }}t          |t                    |V  d S r+  r>  r?  s      r  r  z?TypeChecker.check_rvalue_count_in_assignment.<locals>.<genexpr>  s7      "a"aB
SUW_H`H`"a1"a"a"a"a"a"ar  r~  Tc              3  @   K   | ]}t          |t                    V  d S r+  r>  )r  r  s     r  r  z?TypeChecker.check_rvalue_count_in_assignment.<locals>.<genexpr>  s,      BBz&(++BBBBBBr  )	r@  r  r  r   $TOO_MANY_TARGETS_FOR_VARIADIC_UNPACKrm  r  r@  wrong_number_values_to_unpack)
r,  r  rY  r  rZ  left_star_indexleft_prefixleft_suffixright_prefixright_suffixs
             r  rD  z,TypeChecker.check_rvalue_count_in_assignment  s    $@@@@@@@ 		KWUUUu7||l**		*OQXYYYu""a"a)G2D2D"a"a"aaaO)Kg,,81<K(L'-7!;L\))[<-G-G 		*OQXYYY4BB'BBBBB 	7||a,..66|S\\TUEUW^___u / S\\))H22<WwWWW5tr  rv_typeundefined_rvaluec                .   t          |p| j                            |                    }t          |t                    rt          |j                  }t          |t                    r<|                                }t          |          dk    rt          |d                   }t          |t                    r$t          |j                  t          |i           }t          |t                    ri|D ]d}	t          |	t                    r|	j        }	|                     t          t"          j        |          |          }
|                     |	|
|           edS t          |t                    r|                     ||||||           dS t          |t                    r|                     |||||           dS t          |t,                    r,|j        j        dk    r| j                            |           dS |                     ||||           dS )z:Check the assignment of one rvalue to a number of lvalues.r~  r   Nrl  r  )r   rx  r  r  r   r/  r   r`  r  r   r   r  r8   r   r   r  r%  r   rr  r  !check_multi_assignment_from_tuple!check_multi_assignment_from_unionr   r  r  r@  unpacking_strings_disallowed$check_multi_assignment_from_iterable)r,  r  r  r  r  rh  ri  r  r`  r  r%  s              r  rH  z"TypeChecker.check_multi_assignment  sL    &g&Q1B1I1I&1Q1QRRk?33 	C)+*ABBKk9-- 	A(7799N>""a''-nQ.?@@ {I..	7#K$566B &k266Kk7++ 	 H Hb(++ !B NNI6;OOOQX 	 %%b)5FGGGGH H Y// 	22g7GIZ     Y// 		22g7H     X.. 	;3C3LP^3^3^H11':::::55g/@    r  r  r   c                   d| _         t          d |                     |          D                       }| j                                        5 }|j        D ]}|                     |||||d           t          ||                     |                    D ]P\  }	}
|	                    | j	        d         
                    |
t          t          j                                       Q	 ddd           n# 1 swxY w Y   t          d |D                       }|                                D ]\  }}t          |t                    r|j        }g }|D ] \  }}|J |                    ||f           !t          | \  }}| j                            |t%          t'          |                    t%          t'          |                               t          ||                     |                    D ]N\  }}
|                     |
          \  }}}|r|                     ||
|           8|                     |
|           Od| _         dS )a  Check assignment to multiple lvalue targets when rvalue type is a Union[...].
        For example:

            t: Union[Tuple[int, int], Tuple[str, str]]
            x, y = t
            reveal_type(x)  # Union[int, str]

        The idea in this case is to process the assignment for every item of the union.
        Important note: the types are collected in two places, 'union_types' contains
        inferred types for first assignments, 'assignments' contains the narrowed types
        for binder.
        Tc              3     K   | ]}g V  d S r+  r  )r  r  s     r  r  z@TypeChecker.check_multi_assignment_from_union.<locals>.<genexpr>  s"      2]2]!22]2]2]2]2]2]r  )r  rh  ri  r  Nc              3  4   K   | ]}t          |          V  d S r+  )r   )r  cols     r  r  z@TypeChecker.check_multi_assignment_from_union.<locals>.<genexpr>  s+      MM31#66MMMMMMr  F)rS  tupler  rA  accumulate_type_assignmentsr  rH  r  r1  r0  r;  r   r   r  r  r   r  r  r   r  r  r  r  )r,  r  r  r  r  r  
transposedr  r  r  r  union_typesr  r  clean_itemsr  declared_typer  declared_typesunion_1_2r  s                          r  rl  z-TypeChecker.check_multi_assignment_from_union  s   ( !%-22]2]t?S?ST[?\?\2]2]2]-]-]
[4466 	[+#) [ [ ++&7 %) ,    !T-A-A'-J-JKK [ [EAr HHT_R044RAW9X9XYYZZZZ[[	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[  MM*MMMMM&,,.. 	 	KD%$)) !y 46K', : :#m$000""D-#89999$'$5!E>K##%d5kk22%d>&:&:;;   
 [$*>*>w*G*GHH 	+ 	+IE2#0044BH +&&xU;;;;E**** %s   BC44C8;C8c                   g }|D ]|}t          |t          t          f          r-|                    |                     |j                             t          |t                    r|j        }|                    |           }|S r+  )	r  r   r{   rG  r  r  r   r  r1  )r,  r  resr  s       r  r  zTypeChecker.flatten_lvalues5  s~     " 	 	B"y(344 ;

4//99:::"h'' WJJrNNNN
r  r   c                    t          |j                  }                     |t          |j                  |          rt	          d t          |          D             t          |                    }|d |         }	|t          |          k    rt          t          ||                   nd }
||dz   d          }|s                     ||          }t           j
                            ||                    }t          |t                    rt          |j                  }t          |t                    r<|                                }t          |          dk    rt          |d                   }t          |t                    r                     ||||           d S t          |t$                    rd S t          |t&                    sJ |}                     |j        |t          |                    \  }}}t+          |	|          D ]0\  }}                     |                     |          |           1|
rMt1           fd|D                       }|                                                    |
j        ||           t+          ||          D ]0\  }}                     |                     |          |           1d S |r |D ]}t          |t6                    rJt          |j        t:                    r0|j        j        $t%          t>          j                   |j        _        at          |t                    rt          |j        t6                    rmt          |j        j        t:                    rN|j        j        j        = !                    dt%          t>          j                   g          |j        j        _        d S d S )N)rZ  c              3  J   K   | ]\  }}t          |t                    |V  d S r+  r>  r?  s      r  r  z@TypeChecker.check_multi_assignment_from_tuple.<locals>.<genexpr>N  s5      OOuq"jX6N6NOOOOOOOr  r~  r   c                    g | ]U}t          |t                    s                    |          n't                              |j                            VS r  )r  r   r%  r   r  )r  rh  r  r,  s     r  rq  zATypeChecker.check_multi_assignment_from_tuple.<locals>.<listcomp>{  si        $ $.gz#B#BQDNN7G<<<!)$..w*O*O!P!P	  r  r  )"r   r  rD  r  rm  r  r   r   lvalue_type_for_inferencer   rx  r  r  r   r/  r   r`  rl  r   r   rE  r  r  r%  r{   rF  r  r   r  r   r  r   rs  r  )r,  r  r  r  r  ri  r  rZ  rP  rQ  rR  rS  r  reinferred_rvalue_typer`  left_rv_typesstar_rv_typesright_rv_typesr  rh  	list_exprs   `   `                r  rk  z-TypeChecker.check_multi_assignment_from_tuple@  s*    ,K,=>>00S*++WM 1 
 
 Q	 OO	' 2 2OOOQTU\Q]Q] J {
{+H=G3w<<=W=Wd8WZ%8999]aG
Q 0 01I# 5"<<WkRR)8%,,V[AA* *& 4oFF a-<=S=_-`-`*4i@@ T%;%J%J%L%LN>**a//1@PQAR1S1S.4i@@ ::)?J[   F4g>>  F!"8)DDDDD4;?;Q;Q!:s7||< <8M=.  #8];; _ _G%%b$..'*J*JL]^^^^ R$     (5  	 		 ""7+++%%glI?PQQQ"9n== _ _G%%b$..'*J*JL]^^^^_ _
 ! !  B"2x00&rw44 GL0'.y/C'D'D#B11 &rw99 *27< = = !# 1 9040G0G /'):N2O2O1P1 1BGL-  r  c                    t          d t          |          D             t          |                    }|d |         }|t          |          k    rt          t          ||                   nd }||dz   d          }                     |j        |t          |                    \  }}}	g d fd	}
 |
||           |rq                     |j                  \  }}}|r<t          |t                    s'                    |gt          |          z             n                    |            |
||	           t                               d
                    S )Nc              3  J   K   | ]\  }}t          |t                    |V  d S r+  r>  r?  s      r  r  z8TypeChecker.lvalue_type_for_inference.<locals>.<genexpr>  s5      KK51b*R2J2JKQKKKKKKr  r~  r!  r0  rv_typesrG  r(  r)  c                    t          | |          D ]`\  }}                    |          \  }}}|r+t          |t                    s                    |           K                    |           ad S r+  )r  r  r  r   r1  )	r!  r  r  rh  sub_lvalue_type
index_exprr  r,  type_parameterss	          r  append_types_for_inferencezITypeChecker.lvalue_type_for_inference.<locals>.append_types_for_inference  s    "311 4 4G8<8I8I"8M8M5X" 4:o{+S+S 4#**?;;;; $**733334 4r  r2  )r!  r0  r  rG  r(  r)  )rm  r  r  r   r   rE  r  r  r  r  r   rG  r   r  )r,  r  r  rP  rQ  rR  rS  r  r  r  r  r  r  r  r  s   `             @r  r  z%TypeChecker.lvalue_type_for_inference  s   KKIg..KKKSQX\\
 

 ;J;'9Cs7||9S9S$x!4555Y]JN,,-	7;7M7Mz3w<<8
 8
4}n ')	4 	4 	4 	4 	4 	4 	4 	#"8];;; 	6484E4Egl4S4S1OZ 6z/;'O'O 6&&'83};M;M'MNNNN  &&}555""9n===$//:J*K*KLLLr  r  list[T]rP  length tuple[list[T], list[T], list[T]]c                    ||z
  dz
  }|dk    r| nt          |          }|d|         }|||         }||d         }|||fS )a  Splits a list of items in three to match another list of length 'length'
        that contains a starred expression at 'star_index' in the following way:

        star_index = 2, length = 5 (i.e., [a,b,*,c,d]), items = [1,2,3,4,5,6,7]
        returns in: ([1,2], [3,4,5], [6,7])
        r~  r   N)r  )	r,  r  rP  r  nr_right_of_starright_indexrt  starru  s	            r  rE  zTypeChecker.split_around_star  sj     "J.2+;q+@+@'''c%jj[j[!Z+,kll#T5  r  r  c           	         t          |          }t          |t                    r|                                r|j        }t          ||                     dt          t          j	                  g                    S )Nr  )
r   r  r   rv  r  r   r  r   r   r  r,  r  s     r  r@  zTypeChecker.type_is_iterable  sq    t$$dL)) 	!d.>.>.@.@ 	!=D$))*;giF\>]>]=^__
 
 	
r  c                   t          |          }|                     |          rt          |t          t          t
          t          f          r|                     ||          }|D ]}t          |t                    rH| 	                    d|g          }| 
                    |j        |                     ||          |           _| 
                    ||                     ||          |           d S | j                            ||           d S )Nr  )r   r@  r  r   r   r   r   rA  r   r  r  r  r%  r@  type_not_iterable)r,  r  r  r  r  r  r  
items_types           r  rn  z0TypeChecker.check_multi_assignment_from_iterable  s)    &k22  -- 	=*(L(JG3
 3
 	= //WEEI 	 	b(++ !%!8!89+!V!VJ))
G!D!DFW    ))DNN9g>>@Q   	 	 H&&{G<<<<<r  0tuple[Type | None, IndexExpr | None, Var | None]c                    d }d }d }                      |          rt          |t                    rt          |j        t                    ryt          |t                    r%t          |j        t                    sJ |j        }nt          |t
                    sJ  j                            |j                   |j	        }nt          |t                    r|}nkt          |t
                    r4 j                            |d|          }                     ||           n"t          |t                    rl j                            |d          } j        j        r-t          |j        t                    r|j        j        r|j        }                     ||           nt          |t"          t$          f          r7 fd|j        D             }t)          |                     d                    }nNt          |t,                    r                     |j                  \  }}}n j                            |          }|||fS )NT)r  c                b    g | ]+}                     |          d          pt                      ,S r   )r  r   )r  sub_exprr,  s     r  rq  z,TypeChecker.check_lvalue.<locals>.<listcomp>  sN       
 	 !!(++A. "  !!	  r  r2  )is_definitionr  r   r  r   r~   rx  r  r  def_varrx   analyze_ordinary_member_accessr  analyze_ref_exprrQ  r  r  r   r{   r  r   r  r   r  )r,  r  r  r  r  r  r  r  s   `       r  r  zTypeChecker.check_lvalue  sN    f%% $	;68,,$	;0:6;0L0L$	; &(++ *!&+s33333!;!&*55555!((555!>	** 	;!LL
++ 	;+JJ6SWY_``KOOFK0000)) 	;+<<VD<QQK3'v{C00' K+'
 ";OOFK0000H 566 	;   
 !'  E $E4??;K+L+LMMKK)) 	; $ 1 1&+ > >KAA+226::KL(22r  c                    t          |t                    r/|j        rdS |j        }t          |t                    r	|j        d u S nt          |t                    r|j        S dS r  )r  r   is_inferred_defr  r   r  r~   )r,  r  r  s      r  r  zTypeChecker.is_definition#  sq    a"" 	%  t 6D$$$ )yD(():&& 	%$$ur  	init_typec           	     p   t          |t                    r| j                            ||           dS t	          || j        |j        t          |t                              sl| j        se|j	        dk    rV| 
                    |||          sA| j                            ||| j        j                   |                     |||           dS dS dS t          |t                    r| j        {|j        rt|j        | j        v rft!          | j        |j                 |          sF| j                            ||| j        j                   t#          t$          j                  |_        dS t+          |          }|                     |||           | j        j        r| j                            |||           dS dS )z>Infer the type of initialized variables from initializer type.)r  is_lvalue_memberr  N)r  r   r@  deleted_as_rvaluer  rQ  r  r~   rS  r  r  need_annotation_for_varpython_version!set_inference_error_fallback_typerR  r  r   r   r   rs  r  r   r  r  rA  r  )r,  r  r  r  r  s        r  r  zTypeChecker.infer_variable_type3  s    i-- $	FH&&y':::::& $!+FJ!?!?	  "	F )"	F yC(?(?fi(X(X00w@[\\\66tVYOOOOO   vz**	F-9 :$"??? !>v~!NPYZZ @ H,,T7DL<WXXX	 455DIII
 #9--I""4;;;|2 F''	9EEEEEF Fr  c                   t          |          }t          |t                    r3t          |t                    s| j        j        st          d |          }nBt          |t                    r*|j        j	        }t          |t                    }|rY|dk    s|dk    s|dk    s|dk    rAt          d t          |j                  D                       rt          |j        |          }n|r|dk    rt          |j        d                   }t          |j        d                   }t          |t          t          f          rR|                     |          r=t!          |          }t          |t                    sJ t          |j        ||          }nd	S d	S d	S |                     |||           || j        d
         j        |<   dS )Nr  r  builtins.dictcollections.OrderedDictc              3  N   K   | ] }t          |t          t          f          V  !d S r+  )r  r   r   r  r  s     r  r  z1TypeChecker.infer_partial_type.<locals>.<genexpr>p  sE         q8_"=>>     r  collections.defaultdictr   r~  Fr  T)r   r  r   r~   rQ  r  r   r   r  r  r   r_  r   rt  r   'is_valid_defaultdict_partial_value_typer+   r  rJ  r   )	r,  r  r  r  partial_typer  is_refarg0arg1s	            r  r  zTypeChecker.infer_partial_type]  s   #I..	i** %	vz**%	26,2U%	
 'tT22LL	8,, 	 ~.H00F //>11?22#<<<  -in==     =  +9>4@@ H(AAA&y~a'899&y~a'8998_5  !BB4HH! &d++D%dH55555#.y~tT#J#JLL 5u5tV\:::+12"4(tr  r  r   c                j   t          |t                    sdS t          |j                  dk    rdS t          |j                  dk    rit	          |j        d                   }| j        j        r#t          |t          t          t          f          }nt          |t          t          f          }|rdS dS )a  Check if t can be used as the basis for a partial defaultdict value type.

        Examples:

          * t is 'int' --> True
          * t is 'list[Never]' --> True
          * t is 'dict[...]' --> False (only generic types with a single type
            argument supported)
        Fr   Tr~  )
r  r   r  rt  r   rQ  old_type_inferencer   r   r   )r,  r  r  alloweds       r  r  z3TypeChecker.is_valid_defaultdict_partial_value_type  s     !X&& 	5qv;;!4qv;;!!!&),,C|. G$S?Hk*RSS$S?H*EFF tur  c                
   |rw| j         sq||_        d|_        d|_        || j        vrd | j        j        D             | j        |<   t          |t                    r| j	        |j
        || j	        |j
        <   |                     ||           t          |          }d}t          |t                    r|j        }n't          |t                    r|j        d         j        }|rt#          |          r	d|_        dS t'          |          r	d|_        dS t+          |          r[d|_        t          |t                    rAd|_        t          |t.                    s
J |            |j        j        |_        dS dS dS dS dS dS )zStore inferred variable type.

        Store the type to both the variable node and the expression node that
        refers to the variable (lvalue). If var is None, do nothing.
        Tc                    h | ]	}|j         
S r  r  )r  r  s     r  r  z0TypeChecker.set_inferred_type.<locals>.<setcomp>  s    ,V,V,V%UX,V,V,Vr  Nr   )rc  r  r  is_readyrV  rA  r  r  r~   rR  r  r  r   r   r  r   r  is_node_staticis_staticmethodis_classmethod_noderL  r  r   rg   r  r  )r,  r  r  r  p_typer  s         r  r  zTypeChecker.set_inferred_type  s     	Et1 	ECH"COCL$...,V,V4;CU,V,V,V$S)&*-- I$2O2[>-DHD1&.AOOFD)))$T**FJ&,// 8#.

FJ// 8 $\!_7
 E!*-- 
E*.C'''(44 E)-C&&& ,, E&*CO!&*55 E370)*i@@LL*LLL*4.*D?	E 	E 	E 	E(E E
E EE Er  c                ^    |                      |          }|                     |||           dS )a  Store best known type for variable if type inference failed.

        If a program ignores error on type inference error, the variable should get some
        inferred type so that it can used later on in the program. Example:

          x = []  # type: ignore
          x.append(1)   # Should be ok!

        We implement this here by giving x a valid type (replacing inferred Never with Any).
        N)inference_error_fallback_typer  )r,  r  r  r  r  s        r  r  z-TypeChecker.set_inference_error_fallback_type  s5     55d;;sFH55555r  c                b    |                     t                                }t          |          S r+  )r  SetNothingToAnyr,   )r,  r  r  s      r  r  z)TypeChecker.inference_error_fallback_type  s)    ;;0011 h'''r  c                   t          |t          t          t          t          t
          f          rdS t          |t                    rt          |j        t
                    rt          |j        j        t                    rb|j        j        j
        }t          |t                    r|j         S t          |t                    rt          d |j        D                        S dS )a  Returns True for expressions for which inferred type should not depend on context.

        Note that this function can still return False for some expressions where inferred type
        does not depend on context. It only exists for performance optimizations.
        Tc              3  $   K   | ]}|j         V  d S r+  rO  r  s     r  r  z,TypeChecker.simple_rvalue.<locals>.<genexpr>  s$      "H"Hd4>"H"H"H"H"H"Hr  F)r  ry   r   ra   rm   r   rb   r@  r  r[   r  r   rO  r   r@  r  )r,  r  r*  s      r  simple_rvaluezTypeChecker.simple_rvalue  s     fwIwOPP 	4fh'' 	I&-11 Ij"$97 7 I m(-c<00 I"},,Z00 I""H"Hci"H"H"HHHHHur  r  
expression)r)  r  r  r  rA   r'  r(  r)  list[str] | None
Var | Nonetuple[Type, Type | None]c          	        | j         r0t          |t                    rt          t          j                  |fS |d uo"t          t          |          t                     }
|	t          |          r|}nd }| j        	                    |||
          }||t          || j                  s{| j        	                    |||
          }t          || j                  sI|	G| j                            |	|| j        j                   |	                    t                                }t          |t                     r|	|	j        |	j        st'          |          }t)          |	j        |          s|                     |          st-          |	j        |g          }t)          ||	j                  st          |	j        t.                    sq| j                            |	j                   |                     |	||           | j                            ||           t=          |          }||| j        j        |<   t          t          |          t@                    rtC          |          s| "                    |          s| j        #                                5 }| j$        5 }| j        	                    |d |
          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |%                                s^t          t          |          t                    s<t          || j                  r'tM          ||          r|}| '                    |           t          |tP                    r| j        )                    ||           t          |tP                    r| j        *                    ||           n$|r"| +                    ||||| d| d|           ||fS )N)r|  r<  )r<  z	 has type)r)  ),rd  r  rj   r   r   r  r   is_typeddict_type_contextrx  r  r  rQ  r@  r  r  r  r   r  r  r-   r   refers_to_different_scoper   r   rL  r1  r  r  rA  putr<   r  r   r   r  r  rh  has_new_errorsr   store_typesr   r  deleted_as_lvaluer  )r,  r  r  r  r@  r'  r(  r)  r  r  r<  r|  r  new_inferredlitlocal_errorstype_mapalt_rvalue_types                     r  r-  z#TypeChecker.check_simple_assignment  s    < ^	,Jv|<< ^	,9122K??*$6  z,,g@ @ < #<[#I#I*#+22\DT 3  K ' (.{DLII )
 #/66GW 7   .k4<HH HXMaH44 '4<+F   #."4"4_5F5F"G"GK 68,,L(M- ) .  AMM#HM<@@ L  99&AA L&;X]L<Y&Z&Z+KGG LPZ$M;Q Q L !-44X]CCC 228V[QQQ KOOFK@@@ #/v"6"6C"@K 8 =?;77CC/ -[99/ **622	/ X++-- t?R V^&*&7&>&>7G '? ' 'O                             
 %3355/ ''G'GQQ/ /MM	/
 */;GG/ #2K$$X...+{33 A**;@@@+{33 **;@@@@ 
"""---"--- # 	 	 	 ++s6   K#"K K#K	K#K	K##K'*K'r   c                    |j         t          k    rdS | j                                        dS |j         t          k    r0|j                            d          d         | j        j        k    rdS dS )NFT.r   )r  rW   rF  r  rS   r  
rpartitionrZ  r,  r  s     r  r  z%TypeChecker.refers_to_different_scope]  sh    95Z**,,84Y$4=#;#;C#@#@#CtyGY#Y#Y4ur  r~   r  set_lvalue_typetuple[Type, Type, bool]c                   t          |          }t          |t                    r|                                st          |t                    r|                     |||          \  }}||dfS | j                            d          5  | j        	                    |d          }ddd           n# 1 swxY w Y   |                     |||          \  }}t          ||          r|n|}||t          ||          fS )a:  Type member assignment.

        This defers to check_simple_assignment, unless the member expression
        is a descriptor, in which case this checks descriptor semantics as well.

        Return the inferred rvalue_type, inferred lvalue_type, and whether to use the binder
        for this assignment.
        Tr  F)r+  N)r   r  r   rv  r   r-  r@  r  rx  r  r   )	r,  r  r  r  r  r  r  r  get_lvalue_types	            r  r  z#TypeChecker.check_member_assignmenti  sX     (66}l33 	68Q8Q8S8S 	6Xb8Y
 Y
 	6 "99/6SZ[[NK55X##d#;; 	 	"/NN% O  O	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 55ovwWWQ%/_%M%MbkkSbOZ-Y-YYYs   B11B58B5rx   c                   |                      ||           t          | j                            |j                            }| j                            d||          }||_        | j                            d|||j        |gt          j
        t          j
        g|          \  }}t          |          }t          |t                    r"|j        s| j                                         dS dS dS )zxType check indexed assignment base[index] = rvalue.

        The lvalue argument is the base[index] expression.
        __setitem__N).try_infer_partial_type_from_indexed_assignmentr   rx  r  r  rc  re  check_method_callr  r   rN   r  r   	ambiguousrA  r  )r,  r  r  r  basetypere  res_typer  s           r  r  z$TypeChecker.check_indexed_assignment  s     	;;FFKKK"4#4#;#;FK#H#HII'FF8V
 
 )'99\6"]EM*
 
! #8,,h00 	&9K 	&K##%%%%%	& 	& 	& 	&r  r  c                    ||_         | j        xj        dz  c_        ||= | j        j        r9t          |j                  }||_        | j                            |||           dS dS )z8Replace the partial type of var with a non-partial type.r~  N)	r  rA  versionrQ  r  r   r  r  r  )r,  r  r  rJ  r  s        r  replace_partial_typez TypeChecker.replace_partial_type  sx     q #<. 	; ""AAFK##Ax:::::	; 	;r  c                   d }t          |j        t                    r,t          |j        j        t                    r|j        j        }n9t          |j        t
                    r| j                            |j                  }t          |t                    r$t          |j        t                    r|j        j        }|d S | 
                    |          }|d S |j        }|dk    s|dk    s|dk    r| j                            |j                  }| j                            |          }t          || j                  r}t          || j                  rl| j        sg|dk    r&|j        j        t%          ||j        j                  r=|                     |||g          }	|                     ||	|           d S d S d S d S d S d S d S d S )Nr  r  r  )r  r  r   r  r   r~   rx  r  r  r   r  r  r  r  r  rQ  rc  
value_typer   r  r  )
r,  r  r  r  rO  rJ  typenamekey_typer  r  s
             r  r  z:TypeChecker.try_infer_partial_type_from_indexed_assignment  s    fk7++ 	F
6;;KS0Q0Q 	F+"CCZ00 	F#88EECc3 	P#(K00 PHM	$F $ 7 7 < < (F$-//#<<<#<<<  $077EEH!%!2!9!9&!A!AJ.xFFP2:t|LLP !% :P
 %(AAA # 3 ?$1*ch>Q$R$R !@ $(#:#:8hPZE[#\#\11#xOOOOO9	P 	PP P P P =<
P P P P !@ ?r  tuple[str, ErrorCode] | Nonec                    t          |          }t          |t                    r<|j        j        dk    r	dt
          fS |j                            d          	dt          fS dS )zSome types require usage in all cases. The classic example is
        an unused coroutine.

        In the case that it does require usage, returns a note to attach
        to the error message.
        ztyping.CoroutinezAre you missing an await?	__await__N)r   r  r   r  r  r0   r  r/   )r,  r*  proper_types      r  type_requires_usagezTypeChecker.type_requires_usage  sl     &c**k8,, 	G (,>>>35EFF##K00<35EFFtr  rl   c                F   | j                             |j        dd          }|                     |          }|rg|\  }}|                     t
          j                            t          || j	                            ||           | 
                    |||           d S d S )NTr:  r  )rx  r  r  r  r  r   TYPE_MUST_BE_USEDr  rF   rQ  r  )r,  r  	expr_typeerror_note_and_code
error_noter  s         r  visit_expression_stmtz!TypeChecker.visit_expression_stmt  s    %,,QVt^b,cc	"66yAA 	02JII 299+iQUQ]:^:^__    
 IIj!$I/////	0 	0r  r   c                b    |                      |           | j                                         dS )zType check a return statement.N)check_return_stmtrA  r  r,  r  s     r  visit_return_stmtzTypeChecker.visit_return_stmt  s0    q!!!!!!!!r  r  type_ctxallow_none_func_callc           	     T   | j                             ddd          5 }| j        5 }t          | j                            |||                    }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                                s|                     |           |S |                                }|}| j                             ddd          5 }| j        5 }t          | j                            |d|                    }	ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                                s't          |	|          r|                     |           |	S | j         
                    |           |                     |           |S )z@Infer type of an expression with fallback to empty type context.T)r  r  save_filtered_errorsr;  N)r@  r  rh  r   rx  r  r  r  filtered_errorsr   
add_errors)
r,  r  r   r  r@  r  r*  original_messagesoriginal_type_mapalt_typs
             r  infer_context_dependentz#TypeChecker.infer_context_dependent   s    X##$T $ 
 
 	$ %%,,h:N -                 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 !!## 	X&&&J  //11$X##$T $ 
 
 	$ )%,,T4K_,``               	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 !!## 	
7H(E(E 	X&&&N 	-...*+++
sj   A4+AA4A!	!A4$A!	%A44A8;A8D3%+DD3D 	 D3#D 	$D33D7:D7c           	     H   | j                                         }||j        r'|                     | j        d         |j                  }n5|j        r!|                     | j        d                   }n| j        d         }t          |          }t          |t                    }t          |t                    r+|s)|j        s"|                     t          j        |           d S |j        r;t          |t                     }t          |t"                    }|p|p|}t          |j        t$          t&          t(          t*          t,          t.          f          r|                     |j        ||          }n/t          | j                            |j        ||                    }t          |t6                    r)|j        j        dk    rt#          t<          j                  }|j         r"|                     t          j!        |           d S t          |t"                    r| j"        j#        r| j$        stK          t#          t<          j                  |          sd|j&        tN          v rtQ          |j                  sBt          |t6                    r|j        j        dk    s|s| j)        *                    ||           d S |r;|st          |t                     rd S |                     t          j+        |           d S | ,                    d|d||j        |t          j-                   d S |j        r|j        st          |t"                    rd S t          |t           t"          f          rd S | .                                r$|                     t          j/        |           d S d S d S )Nr  r  builtins._NotImplementedTyper  gotr  )r  r  r  r  r  outer_contextr@  )0rF  current_functionr  r~  rH  r]  r{  r   r  rz   r   r  r  r   NO_RETURN_EXPECTEDr  r   r   rb   r{   r   ri   r   r   r
  rx  r  r   r  r  r   r  r  RETURN_IN_ASYNC_GENERATORrQ  warn_return_anyrc  r   r  r   is_literal_not_implementedr@  incorrectly_returning_anyNO_RETURN_VALUE_EXPECTEDr  r  r  RETURN_VALUE_EXPECTED)	r,  r  r  rj  	is_lambdadeclared_none_returndeclared_any_returnr  r*  s	            r  r  zTypeChecker.check_return_stmt$  s   z**,,  4"<<%b)4+<  " 4"<<T=Nr=RSS"/3)+66K"444I+77   )> II.A1EEEFv XI'1+x'H'H$&0g&F&F# (1'_4H'_L_$ afx9hPWY_&`aa 
 66qv{L`aaCC))00FKCW 1   C sH--:)-KKK!)"899C* II.H!LLLFc7++  4K $ :K !2'):P2Q2QS^ _ _K
 !I)=== :16 B B > '{H==	 >
 !, 0 9=N N N ) !O ::;JJJF (  ! JsH$=$= II.GKKKKK&&&+ #(2"- !&',K '      % - #;88
 FkHg+>?? F++-- III.DaHHHHHU RI Ir  rs   c                (   | j                             ddd          5  t          |j        |j                  D ]\  }}t          | j                            |                    }t          |t                    r| j
                            ||           |                     |          \  }}| j                             dd          5  |                     |d           |                     |           ddd           n# 1 swxY w Y   |                     |d           | j                             dd          5  |j        r|                     |j                   ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )	zType check an if statement.FTr   r  r  fall_throughr  r  r  from_assignmentN)rA  r  r  r  r  r   rx  r  r  r   r@  r  r  r  r  )r,  r  r^  r\  r  if_mapr  s          r  visit_if_stmtzTypeChecker.visit_if_stmt  sO    [&&\]&^^ 	- 	-AFAF++ D D1#D$5$<$<Q$?$?@@a-- 5H..q!444#'#=#=a#@#@  [..1.MM # #&&vu&EEEKKNNN# # # # # # # # # # # # # # #
 ""8U"CCCC**E*JJ - -; -KK,,,- - - - - - - - - - - - - - -#	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-sZ   B+F	-D6FDF	D
7F"E/#F/E3	3F6E3	7FFFr   c                    t          |j        g|j        gd          }|                    |           |                     ||j        |j                   dS )zType check a while statement.N)r  )rs   r  r  rF  r  r  )r,  r  if_stmts      r  visit_while_stmtzTypeChecker.visit_while_stmt  sT    !&AF8T22!+afEEEEEr  r   c                   |                      |j        |j        |j                   t	          |j        t
                    r!| j                            |j        d          }n| j                            |j                  }t          ||j                  \  }}|rV| j        
                    |||j        |          \  }}t          ||          s | j                            |j        |           nSt          |j        |j        |j                  }|                    |           |                     |j        |dd           |                     |           dS )z9Type check an operator assignment statement, e.g. x += 1.TF)r  r  r  r  N)r  r  r  r  r  r~   rx  visit_member_exprr   infer_operator_assignment_methodcheck_opr   r@   incompatible_operator_assignmentr   rF  r  r  )r,  r  r  inplacer~  r  r  r  s           r  visit_operator_assignment_stmtz*TypeChecker.visit_operator_assignment_stmt  sJ   ;;AHahPQPTUUUah
++ 	= +==ahMMKK+2218<<K:;MM 	!.77QXWXYYNKk;77 C99!$BBB !$!(33DMM!!!xQV "    	r  r\   c                   | j                             |j                   t          |j        t                    r=t          |j        j                  dk    r |                     t          j	        |           | 
                    |j                  \  }}|j        #| j                             ||j        d d           |                     |           d S )Nr   F)suppress_unreachable_errors)rx  r  r  r  r   r  r  r  r   MALFORMED_ASSERTr  r@  analyze_cond_branchr  )r,  r  true_mapr  s       r  visit_assert_stmtzTypeChecker.visit_assert_stmt  s      (((afi(( 	<S->->-B-BII&7;;; "77??(511!%5 2    	8$$$$$r  r   c                    |j         r|                     |j         |           |j        r|                     |j        |d           | j                                         dS )zType check a raise statement.T)optionalN)r  type_check_raise	from_exprrA  r  r  s     r  visit_raise_stmtzTypeChecker.visit_raise_stmt  sf    6 	-!!!&!,,,; 	A!!!+q4!@@@!!!!!r  r^  r3  c                   t          | j                            |                    }t          |t                    r| j                            ||           d S |                     d          }|t          |          g}|r!|	                    t                                 |                     |t          j        |          |t          j                   t          |t                     r| j                            |g g |           t          |t$                    rE|j        j        dk    r7|                     t          j                            d          |           d S d S d S )Nbuiltins.BaseExceptionr  z%; did you mean "NotImplementedError"?)r   rx  r  r  r   r@  r  r  r   r1  r   r  r   
make_unionr   INVALID_EXCEPTIONr   r&  r   r  r  r  r  )r,  r^  r  r3  r*  r4  expected_type_itemss          r  r4  zTypeChecker.type_check_raise  sh   d/66q99::c;'' 	H&&sA...F??#;<<'(););< 	3  &&xzz222%&9::A?O?a	
 	
 	
 c<(( 	9((b"a888c8$$ 	):>\)\)\II 2FF;  	    	 	)\)\r  r   c                   d}| j                             dd          5  |                     |t          |j                             |j        rZt                      }t          | j        j        |          5  | 	                    |j                   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |j        r|J | j         
                                sLt          | j        j        |          5  | 	                    |j                   ddd           n# 1 swxY w Y   | j                            |           dS dS )zType check a try statement.NFr   r  )	try_frame)rA  r  visit_try_without_finallyr!  finally_bodyr5   r6   r@  r?  r  r  r  )r,  r  r  s      r  visit_try_stmtzTypeChecker.visit_try_stmt  s    
 [&&A&FF 	0 	0 **1Q^8L8L*MMM~ 0688*48?KHH 0 0KK///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 > 	= ***;--// 0*48?KHH 0 0KK///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0H//<<<<<!	= 	=sH   AB68BB6B#	#B6&B#	'B66B:=B:?D&&D*-D*r=  c                   | j                             dd|          5  | j                             ddd          5  | j                             ddd          5  |                     |j                   ddd           n# 1 swxY w Y   t	          t          |j                            D ][}| j                             dd          5  |j        |         }|r[|                     ||j	                  }|j
        |         }|r1d|_        |                     ||                     ||                     |                     |j        |                    |j
        |         }|r|j        }t          |j        t"                    rDt%          |	          }||j        _        | j        j        r| j                             |||           | j        j        s| j                             |           ddd           n# 1 swxY w Y   ]	 ddd           n# 1 swxY w Y   |j        r|                     |j                   ddd           dS # 1 swxY w Y   dS )
a2  Type check a try statement, ignoring the finally block.

        On entry, the top frame should receive all flow that exits the
        try block abnormally (i.e., such that the else block does not
        execute), and its parent should receive all flow that exits
        the try block normally.
        Fr  )r  r  r=  Tr  N   r  source)rA  r  r  r  r  r  handlersr  check_except_handler_testis_starvarsr  r  r%  r  r  r  r   r   r  rQ  r  r  cleanser  )	r,  r  r=  r  r*  r  r  rD  r  s	            r  r>  z%TypeChecker.visit_try_without_finally%  sP    [&&AQZ&[[ !	) !	)**ET`a*bb 9 9[..AY].^^ ( (KK'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (s1:// 9 9A22Dq2QQ 9 9gaj S $ > >sAI N NA"#&)C" S 7; 3 $ 5 5c4>>!S;Q;Q R R RAJqM222fQi 9 &)XF)#(C88 U+6f+E+E+E08#'<#F !U$(K$;$;C8$T$T$T#'<#F 9 $ 3 3C 8 8 819 9 9 9 9 9 9 9 9 9 9 9 9 9 99	9 9 9 9 9 9 9 9 9 9 9 9 9 9 9< { )AK(((C!	) !	) !	) !	) !	) !	) !	) !	) !	) !	) !	) !	) !	) !	) !	) !	) !	) !	)s~   IHB5HBHB	AHD%G=	1H=HHHHIH	IH	$IIIr  rG  c                   | j                             |          }g }|                     ||          }t          |          D ]s}t	          |t
                    r|                    |           .t	          |t                    rm|j        d         }|	                                s7| 
                    t          j        |           |                     |          c S t          |j                  }nTt	          |t                     r|j        }n7| 
                    t          j        |           |                     |          c S t%          ||                     d                    s7| 
                    t          j        |           |                     |          c S |                    |           u|rg }	|D ]}t)          ||                     d                    rM| 
                    t          j        |           |	                    t          t,          j                             r|	                    |           |                     |	          S t3          |          S )z,Type check an exception handler test clause.r   r8  builtins.BaseExceptionGroup)rx  r  get_types_from_except_handlerr   r  r   r1  r   r  rv  r  r   INVALID_EXCEPTION_TYPEdefault_exception_typer,   r  r   r  r   r  r   INVALID_EXCEPTION_GROUPr   rs  wrap_exception_groupr   )
r,  r  rG  r*  	all_types
test_typesttyper  r4  new_all_typess
             r  rF  z%TypeChecker.check_except_handler_testS  sJ   &&q)) "	77Q??
%j11 	' 	'E%))   '''%.. 
<{1~'')) @II.EqIII66w?????)$-88E8,, < :		*A1EEE227;;;;;h8P(Q(QRR <		*A1EEE227;;;;;X&&&& 	<(*M  . .$S$//:W*X*XYY .II.FJJJ!((1E)F)FGGGG!((----,,];;;$Y///r  c                j    t          t          j                  }|r|                     d|g          S |S )z:Exception type to return in case of a previous type error.builtins.ExceptionGroup)r   r   rs  r  )r,  rG  r  s      r  rN  z"TypeChecker.default_exception_type|  s9    9/00 	R**+DxjQQQr  r  Sequence[Type]c                    t          |          }t          ||                     d                    rd}nd}|                     ||g          S )zDTransform except* variable type into an appropriate exception group.zbuiltins.ExceptionrV  rK  )r   r   r  r  )r,  r  r  r  s       r  rP  z TypeChecker.wrap_exception_group  sR    #E**c4??+?@@AA 	1,DD0D&&tcU333r  c                
    t          |          }t          |t                    r|j        S t          |t                    r! fd|                                D             S t          |d          r|j        d         gS |gS )z?Helper for check_except_handler_test to retrieve handler types.c                F    g | ]}                     |          D ]}|S r  )rL  )r  r  	union_typr  r,  s      r  rq  z=TypeChecker.get_types_from_except_handler.<locals>.<listcomp>  sP       !%!C!CD!!L!L      r  r2  r   )r   r  r   r  r   r`  r   rt  )r,  r*  r  s   ` `r  rL  z)TypeChecker.get_types_from_except_handler  s    c""c9%% 	9Y'' 
	    ..00   
 s$455 	HQK= 5Lr  rn   c                     j         r                     j                  \  }n                     j                  \  }_        |_                             j        j         fd           dS )zType check a for statement.c                 L                         j         j        d u           S r+  )analyze_index_variablesr  
index_type)r  r  r,  s   r  r?  z,TypeChecker.visit_for_stmt.<locals>.<lambda>  s)    $">">ALD$8!# # r  )r  N)	is_async analyze_async_iterable_item_typer  analyze_iterable_item_typeinferred_item_typeinferred_iterator_typer  r  r  )r,  r  iterator_typer  s   `` @r  visit_for_stmtzTypeChecker.visit_for_stmt  s    : 	O'+'L'LQV'T'T$M99'+'F'Fqv'N'N$M9(#0 FK      	 	
 	
 	
 	
 	
r  tuple[Type, Type]c                    | j         }|                    |          }|                    d|g g |          d         }|                    d|g g |          d         }|                    ||t          j                  }||fS )zNAnalyse async iterable expression and return iterator and iterator item types.	__aiter__r   	__anext__)rx  r  check_method_call_by_namecheck_awaitable_exprr   INCOMPATIBLE_TYPES_IN_ASYNC_FOR)r,  r  echkiterableiterator	awaitabler  s          r  ra  z,TypeChecker.analyze_async_iterable_item_type  s     ;;t$$11+xRQUVVWXY22;"bRVWWXYZ	--t-M
 
	 ""r  c                    |                      | j                            |          |          \  }}|                     |          }|r||fS ||fS )zHAnalyse iterable expression and return iterator and iterator item types.r  )-analyze_iterable_item_type_without_expressionrx  r  analyze_range_native_int_type)r,  r  rp  ro  int_types        r  rb  z&TypeChecker.analyze_iterable_item_type  sk    !OO$$T**D P 
 
( 55d;; 	&X%%!!r  c                >   | j         }t          |          }|                    d|g g |          d         }t          |t                    r1|j        j        j        dk    r|t          |          j	        d         fS |                    d|g g |          d         }||fS )zBAnalyse iterable type and return iterator and iterator item types.__iter__r   r2  __next__)
rx  r   rk  r  r   partial_fallbackr  r  r   rt  )r,  r  r  rn  ro  rp  s         r  rs  z9TypeChecker.analyze_iterable_item_type_without_expression  s      "4((11*hBPWXXYZ[ x++	&).7;KKK^H55:1=== 55j(BPRT[\\]^_HX%%r  c                   t          |t                    rt          |j        t                    r|j        j        dk    rdt          |j                  cxk    rdk    rn nt          d |j        D                       rkd}d}|j        D ]Y}t          | 
                    |                    }t          |t                    r |j        j        t          v r||}Q||k    rd}Z|r|r|S dS )zTry to infer native int item type from arguments to range(...).

        For example, return i64 if the expression is "range(0, i64(n))".

        Return None if unsuccessful.
        zbuiltins.ranger~  r  c              3  ,   K   | ]}|t           k    V  d S r+  )rN   )r  r  s     r  r  z<TypeChecker.analyze_range_native_int_type.<locals>.<genexpr>  s&      ??DGO??????r  NTF)r  rb   r@  r   r  r  rt  r_  r  r   r  r   r  r   )r,  r  
native_intr  r  argts         r  rt  z)TypeChecker.analyze_range_native_int_type  s    tX&&	"4;00	" $(888S^^((((q(((((??????? ) '+JBy # #&t'7'7'<'<==dH-- #$)2DH^2^2^!)%)

++" "j "!!tr  c                T   t          |          }t          |t                    rLg }|j        D ].}|                     |          }|r|                    |           /t          j        |          S t          |t                    rk|j        	                    d          rQ| 
                    d          j        }t          ||          }t          |j                  dk    sJ |j        d         S t          |t                    r"|                     t          |                    S dS )zzCheck if a type is a nominal container of a union of such.

        Return the corresponding container item type.
        ztyping.Containerr~  r   N)r   r  r   r  analyze_container_item_typer1  r9  r   r  r  r  r=   r  rt  r   r   )r,  r*  r  r  c_typer  super_instances          r  r  z'TypeChecker.analyze_container_item_type  s$   
 c""c9%% 	/ "E	 ) )99$?? )LL((('...c8$$ 	*):):;M)N)N 	*(:;;@I6sIFFN~*++q0000!&q))c9%% 	I33N34G4GHHHtr  r  r  c                \    |                      ||                     ||          |           dS )z>Type check or infer for loop or list comprehension index vars.N)r  r%  )r,  r  r  r  r  s        r  r^  z#TypeChecker.analyze_index_variables  s1     	eT^^Iw%G%GIZ[[[[[r  rh   c                d   t          |j        t                    r|j        }t          |j        d          }|j        |_        |j        |_        t          ||j        gt          j
        gd g          }|j        |_        |j        |_        | j                            |d           d S |j                            | j                   t          |j                  D ]S}t          |t                    r<| j                            |t#          |j                  t'          |                     Td S )N__delitem__Tr  rC  )r  r  rx   r~   r  r  r  rb   r  r   rN   rx  r  flattenr   rA  r  r   r  r   )r,  r  r^  mr  elts         r  visit_del_stmtzTypeChecker.visit_del_stmt  s   afi(( 	A16=11AVAFxAHQWI??AVAFxAH$$Q$$?????FMM$+,,,qv  c8,, K++[999?3;O;O   r  rg   c                    |j         D ]T}t          |t                    r=|j        dk    r2t	          t
          j                  |j        _        d|j        _	         d S U| 
                    |           d S )Nztyping.no_type_checkT)r"  r  r   r  r   r   r  r  r  r  r  )r,  r^  r  s      r  r  zTypeChecker.visit_decorator  sr     	 	A!W%% :!777!()?!@!@AEJ%)AENFF""1%%%%%r  r  c           	     r   | j         r^| j                            |j                  5  |                     |j        |j        j        |           d d d            n# 1 swxY w Y   |                     |j                  }d}t          |r|j        dd          n|j                  D ]W}t          |d          rt          |t                    r#|s |                     t          j        |           Ld}| j                            |          }|                     ||          }d }	t#          |t$                    r	|j        pd }	d }
|	it#          |t(                    rT|                     |j                  r:|                     |j                  }
| j                            |
|j                  }	|                     |j        ||           | j                            ||gt6          j        g||	|
          \  }}Y|r|                     ||j                   |                     ||j                   t?          ||j                  }t#          |t@                    r||_!        ||j"        _#        d|j"        _$        |j        j%        rgt#          |t@                    r=tM          d |j'        D                       dk    r| j(                            d	|           | )                    |           |s|rd S |j        j*        r|j+        s{| ,                    |          }|j        j-        r?|s=|;|j        j*        j.        s*| j(        /                    |j        j        |j                   | 0                    |j        |           |j        j*        rc|j        j        d
v rU|j#        rNt#          tc          |j#                  td          tf          f          s |                     t          j4        |           |j        j5        r2t#          |td                    r| 6                    |j        |           d S d S d S )Nr  Fr~  zabc.abstractmethodTr  )r  ra  c                :    g | ]}|                                 |S r  )is_required)r  ks     r  rq  z5TypeChecker.visit_decorator_inner.<locals>.<listcomp>W  s%    DDDaAMMOODDDDr  zToo many arguments for propertyr  )7ri  rE  r  r  r	  r  r   r#  r"  r   r   r  r   r  rx  r  r%  r  r   r  r~   r  r  r  method_fullnamecheck_for_untyped_decoratorr&  r   rN   check_untyped_after_decoratorr  r   r   r  r  r  r  r  r  r  r@  $check_incompatible_property_overrider  r  r  r  r  r  r  r   r   r   BAD_CONSTRUCTOR_TYPEr  r  )r,  r^  r  r  r*  non_trivial_decoratorr  r,  r-  r  ra  t2r!  s                r  r  z!TypeChecker.visit_decorator_inner(  s    & 	X++AF33 X X$$QV!&+;$WWWX X X X X X X X X X X X X X X
 &&qv.. %oO!,qrr**1<PP 	 	A!!%9::  !!^44 " OII.JANNN$(!#**1--C>>#q>11DH!W%% .:- (,KJq*$=$=$--PQPVBWBW"..qv66,<<[!&QQ,,QVS!<<<'22dVem_axU` 3  GC ! 	<..sAF;;;**3777QV,,c<(( 	CN
6 	9#|,, HDD3=DDDEEIIHMM"CQGGG55a888 	/ 	F6; 	Vq} 	V(,(B(B1(E(E%+D1D .9 3 :
 ..qv{AFCCC2216;TUUU6; 	D16;*AAAv Dj)@)@<QXBYZZ D		*?CCC6 	6:c<#@#@ 	6((55555	6 	6 	6 	6s   (AA"Adec_typedec_exprc                    | j         j        rLt          |j                  r:t	          |          r-| j        s(| j                            |j        |           d S d S d S d S d S r+  )	rQ  disallow_untyped_decoratorsis_typed_callabler  is_untyped_decoratorrc  r@   typed_function_untyped_decoratorr  )r,  r  r  r  s       r  r  z'TypeChecker.check_for_untyped_decoratorr  s     L4	K!$),,	K %X..	K .		K H55diJJJJJ	K 	K 	K 	K 	K 	K 	K 	Kr  c                   |j         j        s|j        j        r|j        j        }|j        j        j        dd          D ]}|j                            |          }|st          |j	        t                    r[|j	        j        rOt          t          |j	        j        d                   j         j        r |                     t           j        |           d S d S d S Nr~  r   )r  r   r  r  r  r  r`  r  r  r  r   r  r   rg   r  r  r   'READ_ONLY_PROPERTY_OVERRIDES_READ_WRITE)r,  r^  r  r  r  s        r  r  z0TypeChecker.check_incompatible_property_override}  s    u) 	[afk 	[6;D+ 	[ 	[ JNN400	  y~/@AA[!2[ Y	(<Q(?@@DY[
 II.VXYZZZ	[ 	[ 	[ 	[	[ 	[r  r   c                v   d}t          |j        |j                  D ]\  }}|j        r|                     |||j        d u           }n|                     |||j        d u           }t          |          }t          |dd          rjt          |dd          s1t          |t                    r|j        j        dk    rt          j        rd}|rQ| j                            dd          5  |                     |j                   d d d            d S # 1 swxY w Y   d S |                     |j                   d S )NFbuiltins.boolT)r  r=  )r  r  r  r`  check_async_with_itemr  check_with_itemr   r   r  r   r  r  r   r  rA  r  r  r  )r,  r  exceptions_maybe_suppressedr  r  exit_ret_types         r  visit_with_stmtzTypeChecker.visit_with_stmt  s   &+#11 	3 	3LD&z ^ $ : :4IZ^bIb c c $ 4 4T61CTX\C\ ] ] ,M::M}ouEE }otDD 3=(333!&/?BB) C
 /3+& 	  **DD*II $ $AF###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ KKs   *DDDc                    | j         j        r| j        s| j        rd S t          j                            |          r| j                            ||           d S d S r+  )	rQ  disallow_any_decoratedrd  rc  rn  ro  has_any_typer@  untyped_decorated_function)r,  r*  r  s      r  r  z)TypeChecker.check_untyped_after_decorator  sg    |2 	dl 	dF` 	F>&&s++ 	;H//T:::::	; 	;r  r  c                   | j         }|                    |          }|                    d|g g |          d         }|                    ||t          j                  }|r+|                     ||                     ||          |           |                     t          t          j
                  |          }|                    d||gdz  t          j        gdz  |          \  }}	|                    ||t          j                  S )N
__aenter__r   	__aexit__r  )rx  r  rk  rl  r   'INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AENTERr  r%  r   r   r  r   rN   &INCOMPATIBLE_TYPES_IN_ASYNC_WITH_AEXIT
r,  r  r  r  rn  r&  objr  r~  r  s
             r  r  z!TypeChecker.check_async_with_item  s     kk$,,\3BMMaP'''O
 
  	X!!&$..d*C*CEVWWWnnWY%;<<dCC//seai%-1)<d
 
Q (('N
 
 	
r  c                   | j         }|                    |          }|                    d|g g |          d         }|r+|                     ||                     ||          |           |                     t          t          j                  |          }|                    d||gdz  t          j	        gdz  |          \  }}	|S )Nr3  r   r<  r  )
rx  r  rk  r  r%  r   r   r  r   rN   r  s
             r  r  zTypeChecker.check_with_item  s      kk$,,[#r2tLLQO 	X!!&$..d*C*CEVWWWnnWY%;<<dCC//cUQY!(;T
 
Q 
r  r`   c                8    | j                                          d S r+  )rA  handle_breakr  s     r  visit_break_stmtzTypeChecker.visit_break_stmt  s      """""r  rf   c                8    | j                                          d S r+  )rA  handle_continuer  s     r  visit_continue_stmtzTypeChecker.visit_continue_stmt  s    ##%%%r  r}   c           
     	    t          |j                  }                     ||          } j                            dd          5  t           j                            |j                            t          t                    r j
                            |            fd|j        D             }d |D             }                     |          }d }t          |j        |j        |j                  D ]N\  }}	}
 j                            |          } j                            ||          } j                            dd          5  |
j        s't          t          |j                  t*                    r                     d d           i }nt/          ||j        |j                  \  }}|r||v r||         ||<   |r||v r||         ||<                        |          }                     |          }                     |j        |                                |d           |rE|                                D ]0\  }}                                          ||          d           1                     |j        d           |	e j                            dd	          5  t           j                            |	                    }t          |t                    r j
                            ||                                |	          \  }}t?          ||          }t          |t@                    rp|j!        p|j"        }t          |tF                    rM||fD ]H}|stI          |          D ]3}t          |tF                    r|j%        |j%        k    s(||         ||<   4I                     |d                                |
           d d d            n# 1 swxY w Y   n                     |
           d d d            n# 1 swxY w Y                        |d           |}P|?tI          |&                                          D ]} j
        '                    ||            j                            dd          5  	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )
NFr   r  c                F    g | ]}j                             |          S r  )rD  r  )r  pr,  subject_types     r  rq  z0TypeChecker.visit_match_stmt.<locals>.<listcomp>  s,    ^^^aT188LII^^^r  c                    g | ]	}|j         
S r  )capturesr  s     r  rq  z0TypeChecker.visit_match_stmt.<locals>.<listcomp>  s    'J'J'Jq
'J'J'Jr  Tr  r  r  )(collapse_walrussubject_make_named_statement_for_matchrA  r  r   rx  r  r  r   r@  r  patterns#infer_variable_types_from_type_mapsr  guardsbodiesnarrow_type_from_binderrD  r  r  r   r  conditional_types_to_typemaps	rest_typepropagate_up_typemap_inforemove_capture_conflictsr  r  _get_recursive_sub_patterns_mapr  or_conditional_mapsr   patternr  r   r  r  r  "match_statement_inexhaustive_match)r,  r  unwrapped_subjectnamed_subjectpattern_types	type_mapsinferred_typesunmatched_typesr  gr\  current_subject_typepattern_typer  pattern_mapr  r*  rc  	guard_mapguard_else_mapcase_targetr  r  s   `                     @r  visit_match_stmtzTypeChecker.visit_match_stmt  se    ,AI66<<Q@QRR[&&A&FF X	 X	*4+<+C+CAI+N+NOOL,44 <**<;;; _^^^^STS]^^^M'J'JM'J'J'JI!EEiPPN (,Oqz18QX>> >+ >+1a'+'8'P'P!<( ($  $3::1>RSS[..1.MM 7' 7'' Y:'(9::O, , Y **4*GGG,.0M)<+<l>T1 1-X
 ' X=K+G+G=H=WK(9:# R(A(A:B=:QH%67&*&D&D[&Q&Q#'#A#A(#K#K55l6K^\\\**;*NNN& "-8->->-@-@ " "	c $ 2 2$($H$Hs$S$S49 !3 !" !" !" !" **<+@RW*XXX}![66TU6VV + +!01B1I1I!1L1L!M!MB)"k:: B $ : :2q A A A8<8R8RST8U8U5I~':8^'T'TH  *!Y77 U./i.A16#-k8#D#D 
!U5>4I 	%U 	%U/7 )5,448NN )U )UD0:40J0J-948M[EY4Y4Y08FNtnH],C,C)U !..y%.PPP KKNNN3+ + + + + + + + + + + + + + +6 Ao7' 7' 7' 7' 7' 7' 7' 7' 7' 7' 7' 7' 7' 7' 7'p ""8U"CCC"** 6 6 8 899 H HCH??QGGGG **E*JJ                oX	 X	 X	 X	 X	 X	 X	 X	 X	 X	 X	 X	 X	 X	 X	 X	 X	 X	s   	DSE'P'=D1O:	.P':O>>P'O>P'S'P++S.P+/A;S*R8,S8R<	<S?R<	 SSSr  c                    | j                             |          r|S |j        |j        S |                     d          }t	          |          }t          |          }||_        ||_        |S )zEConstruct a fake NameExpr for inference if a match clause is complex.Nmatch)rA  can_put_directlysubject_dummynew_unique_dummy_namer   r   r  )r,  r  r  r  r  r  s         r  r  z+TypeChecker._make_named_statement_for_match>  so    ;''00 	!N_(?"
 --g66DD		A$TNNM!"M+AO  r  r.  c                p   i }t          |          }t          |t                    rt          |t                    rzt	          |j                  t	          |j                  k    sJ t          |j        |j                  D ]3\  }}|||<   |                    |                     ||                     4|S r+  )	r   r  r   r   r  r  r  updater  )r,  r  r*  sub_patterns_maptyp_	item_expritem_typs          r  r  z+TypeChecker._get_recursive_sub_patterns_mapP  s     46s##dI&& 	c:dI+F+F 	ctz??c$*oo5555'*4:tz'B'B c c#	8.6 + ''(L(LYX`(a(abbbbr  r  list[TypeMap]dict[SymbolNode, Type]c           
     .   t          t                    }|D ][}|W|                                D ]B\  }}t          |t                    r(|j        }|J ||                             ||f           C\i }|                                D ]
\  }}	d}
g }|	D ]\  }}|                    |           |                     |          \  }}}|sd}
t          |j        t                    r-|j        j	        r!| j
                            |j        d|           |                     |||t          j        dd          r|||<   |
sSt!          j        |          }|	d         \  }}t          |t                    sJ |||<   |                     ||||           |S )NFTzpattern captures typezvariable has type)r@  r  r  r   )r   r  r  r  r   r  r1  r  r   r  r@  r   r  r  r   INCOMPATIBLE_TYPES_IN_CAPTUREr   r9  r  )r,  r  all_capturestmr  r*  r  r  r  r  already_existsr  previous_typer  r  first_occurrences                   r  r  z/TypeChecker.infer_variable_types_from_type_maps^  s   
 GRRVFWFW 	? 	?B~!# ? ?ID#!$11 ?#y#///$T*114+>>>13)//11 	\ 	\MC"N "E% < <	cS!!!&*&7&7&=&=#q! ,%)N!$)S11 Ndi6H N55diMMM))%,J&=(; *   < /<s+! \$/66&.qk# !!#s+++++&.s#((.>JZ[[[r  r  r  r  c                    |r`t          |                                          D ]@\  }}t          |t                    r$|j        }||vst          |||                   s||= ?d S d S r+  )r  r  r  r   r  r   )r,  r  r  r  r*  r  s         r  r  z$TypeChecker.remove_capture_conflicts  s      	+!(.."2"233 + +	cdH-- +9D>11CX\I]9^9^1$TN	+ 	++ +r  or   c                    |j         r|                     |j         j                   | j                                        5  | j                            |j                   d d d            d S # 1 swxY w Y   d S r+  )
alias_noder  alias_tvarsr@  r  rx  r  r  r,  r  s     r  visit_type_alias_stmtz!TypeChecker.visit_type_alias_stmt  s    < 	B''(@AAAX##%% 	. 	.$$QW---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s     A--A14A1curr_module_fullnameclass_gen_nameclass_short_namer  list[Instance]tuple[ClassDef, TypeInfo]c                   t          |t          g                     }|dz   |z   |_        t          t	                      ||          }||_        ||_        t          |           |                                |_	        ||fS )Nr  )
rc   r_   r  r   r   r  r  rL   calculate_metaclass_typer  )r,  r  r  r  r  cdefr  s          r  make_fake_typeinfozTypeChecker.make_fake_typeinfo  s{     (%))44,s2^Ct-ABB	
d";;==Tzr  	instancestuple[Instance, Instance]list[tuple[str, str]]Instance | Nonec                     j         j        d         }t          |t                    sJ |\  }}t	          ||d          r|S t	          ||d          r|S dd}d fd} ||          }t          t          | j        ddd          }	t          |          s|	                    |	df           dS g }
|D ]3}|j
        j        r%|
	                    |	d|j
        j         df           4|
r|                    |
           dS 	  ||| j                  \  }} j                                        5 }                     |           ddd           n# 1 swxY w Y   |                                ro ||ddd                   } ||| j                  \  }} j                                        5 }                     |           ddd           n# 1 swxY w Y   d|_        n(# t&          $ r |	                    |	df           Y dS w xY w|                                r|	                    |	df           dS t)          t*          |          |j        |<   t/          |g |d         j        p|d         j                  S )a  Try creating an ad-hoc intersection of the given instances.

        Note that this function does *not* try and create a full-fledged
        intersection type. Instead, it returns an instance of a new ad-hoc
        subclass of the given instances.

        This is mainly useful when you need a way of representing some
        theoretical subclass of the instances the user may be trying to use
        the generated intersection can serve as a placeholder.

        This function will create a fresh subclass the first time you call it.
        So this means calling `self.intersect_intersection([inst_1, inst_2], ctx)`
        twice will return the same subclass of inst_1 and inst_2.

        Returns None if creating the subclass is impossible (e.g. due to
        MRO errors or incompatible signatures). If we do successfully create
        a subclass, its TypeInfo will automatically be added to the global scope.
        r   Fignore_promotions
instances_r  r(  r  c                    g }| D ]8}|j         j        r|j         j        }n|g}|D ]}|                    |           9|S r+  )r  is_intersectionr  r1  )r  base_classes_r(  r  expanded_insts        r  _get_base_classesz:TypeChecker.intersect_instances.<locals>._get_base_classes  sf    M" 8 89, &#yHH $vH%- 8 8M!((77778  r  r
  curr_module_r   rQ  r   tuple[TypeInfo, str]c                   fd| D             }dt          |d           d}|j                            |          x}%t          |j        t
                    sJ |j        |fS                     |j        |||           \  }}||fS )Nc                4    g | ]}t          |d           S )r  )rQ  	verbosity)rG   )r  r^  rQ  s     r  rq  z^TypeChecker.intersect_instances.<locals>._make_fake_typeinfo_and_full_name.<locals>.<listcomp>  s)    ^^^1%aAFFF^^^r  z<subclass of and>)rJ   r`  r  r  r  r   r  r  )	r
  r  rQ  r`  r  symbolr  info_r,  s	     `     r  !_make_fake_typeinfo_and_full_namezJTypeChecker.intersect_instances.<locals>._make_fake_typeinfo_and_full_name  s     _^^^P]^^^E>:eU#;#;>>>D&,00666C!&+x88888{D((11,2GtUbccKD%$;r  T)rQ  barer  zhave distinct disjoint basesNr  z
" is finalr  z/would have inconsistent method resolution orderz)would have incompatible method signaturesr~  extra_attrs)r  r  r(  r  )r
  r  r  r   rQ  r   r(  r  )rF  r  r  r   r   rJ   rH   rQ  r   r1  r  r  r  rG  r@  r  r  r  r	  rK   r   rS   r`  r   r  )r,  r   r?  curr_modulert  ru  r  r  base_classespretty_names_list
new_errorsr  r  	full_namer  s   `              r  intersect_instanceszTypeChecker.intersect_instances  s   * j&q)+x00000  eT5EBBB 	KUDEBBB 	L
	! 
	! 
	! 
	!		 		 		 		 		 		 )(33 '"L$,TRRRTY
 
 -\:: 	MM,.LMNNN4
  	W 	WDy! W!!#46T$).6T6T6T"UVVV 	MM*%%%4	??k4< OD) '')) 6\//5556 6 6 6 6 6 6 6 6 6 6 6 6 6 6**,, :0044R4AA"C"C +t|# #i X++-- :33D999: : : : : : : : : : : : : : :#'D   	 	 	MM,._`aaa44	 &&(( 	MM,.YZ[[[4'6tT'B'B)$bil.F.b)TU,Jbccccs[   .G- 5EG- EG- EAG- 8GG- GG- !G"
G- -!HHr   callable_typec                   | j         j        d         }t          |t                    sJ t	          d|j        j         d|j                  }t          || j	                  }| 
                    |j        |||g          \  }}t          dg t          g           |          }|j        dz   |_        ||_        t!          t"          |          |j        d<   t!          t$          |          |j        |<   t'          |g |j                  S )zCreates a fake type that represents the intersection of an Instance and a CallableType.

        It operates by creating a bare-minimum dummy TypeInfo that
        subclasses type and adds a __call__ method matching callable_type.
        r   z<callable subtype of r  r)  z	.__call__r  )rF  r  r  r   gen_unique_namer  r  r`  rG   rQ  r  r  rp   r_   	_fullnamer  r   rY   rS   r   r  )	r,  r*  r   
cur_modulegen_name
short_namer  r  func_defs	            r  intersect_instance_callablez'TypeChecker.intersect_instance_callable  s     Z%a(
*h/////"#K38=#K#K#KZM]^^ &c4<88
,,Z-@(JY\X]^^
d :r599mDD!][8!0x!@!@
:%4T4%@%@
"bco>>>>r  c                @   |                      d          }t          t          t          j                  t          t          j                  gt
          j        t
          j        gddgt          t          j                  |d          }|                     ||          S )zIProduce a new type that makes type Callable with a generic callable type.r  NT)r  r  is_ellipsis_args)	r  r   r   r   explicitr   rO   r  r(  )r,  r*  r  r   s       r  make_fake_callablezTypeChecker.make_fake_callable5  s     ??#677$Y'((')2D*E*EF^U_-4LY/00!
 
 
 //]CCCr  unsound_partitiontuple[list[Type], list[Type]]c                   t          |          }t          |t          t          f          r|gg fS t          |t                    r|g|gfS t          |t
                    rg |gfS t          |t                    rVg }g }|j        D ]F}|                     |d          \  }}|	                    |           |	                    |           G||fS t          |t                    r1|                     t          |          |          \  }}|r|gng }||fS |}t          |t                    rt          |          }t          |t                    r|j                            d          }	|	r/|	j        r(|                     |	j        d          \  }}|r|s|gg fS |s_|                     |          }
t          |t                    r/t          |j        |
          |
j        _        |
j        j        g|gfS |
g|gfS |rg |gfS |g|gfS )a(  Partitions a type into callable subtypes and uncallable subtypes.

        Thus, given:
        `callables, uncallables = partition_by_callable(type)`

        If we assert `callable(type)` then `type` has type Union[*callables], and
        If we assert `not callable(type)` then `type` has type Union[*uncallables]

        If unsound_partition is set, assume that anything that is not
        clearly callable is in fact not callable. Otherwise we generate a
        new subtype that *is* callable.

        Guaranteed to not return [], [].
        Tr-  r)  F)r   r  r   r   r   r   r   r  partition_by_callablerG  r   r   r   r   r   r  
get_methodr,  r  )r,  r*  r-  	callablesuncallablesr  subcallablessubuncallablesitypr~  fakes              r  r1  z!TypeChecker.partition_by_callableD  s   " c""cL(344 	5"9c7## 	 53%<c8$$ 	u9c9%% 	*IK9 3 3 04/I/It 0J 0 0,n   ..."">2222k))c;'' 	* &*%?%?',,.?& &"I{ $/63%%BKk)) c9%% 	'!#&&DdH%% 	%Y))*55F %&+ %)-)C)CK5 *D * *&	;  %[ %  5"9$$ %..t44c9-- 9+4SY+E+EDI( I01C588vu}$ 	 u9 53%<r  current_typetuple[TypeMap, TypeMap]c                   |si i fS t          t          |          t                    ri i fS |                     |d          \  }}|r:|r8|r|t	          j        |          ind}|r|t	          j        |          ind}||fS |ri dfS di fS )a8  Takes in an expression and the current type of the expression.

        Returns a 2-tuple: The first element is a map from the expression to
        the restricted type if it were callable. The second element is a
        map from the expression to the type it would hold if it weren't
        callable.
        Fr0  N)r  r   r   r1  r   r9  )r,  r  r9  r3  r4  callable_mapuncallable_maps          r  conditional_callable_type_mapz)TypeChecker.conditional_callable_type_map  s      	r6Mol33W== 	r6M!%!;!;L\a!;!b!b	; 	 	FOYD)"6y"A"ABBUYLJU_dI$8$E$EFF[_N// 	t8ORxr  r;  tuple[Type | None, Type | None]c                   g }g }t          |          }t          |t                    r"t          |                                          }n|g}t          |          }|D ]}|rt          |t                    ru|D ]q}||j        v r|                    |           !||j	        v s|j
        s+|                    |           |                    |           \|                    |           r|                    |           |                    |           |rt          j        |          nd|rt          j        |          ndfS )z
        Narrows the type of `iterable_type` based on the type of `item_type`.
        For now, we only support narrowing unions of TypedDicts based on left operand being literal string(s).
        N)r   r  r   r   r`  r   r   required_keysr1  r  r  r9  )	r,  r  r;  if_types
else_typespossible_iterable_typesitem_str_literalspossible_iterable_typer  s	            r  conditional_types_for_iterablez*TypeChecker.conditional_types_for_iterable  s     "!#
'66mY// 	6&6}7S7S7U7U&V&V##'4o#>yII&= 	: 	:"  :Z0F%V%V :, 	B 	BC4BBB (>????5;;;CYCb; (>???"))*@AAAA"))*@AAAA	B  6777!!"89999 /7@I ***D0:DI ,,,
 	
r  c                    t          |t                    oYt          |j                  oE|j                            d           o*|j                            d           o|j        j        dk    pVt          |t                    pAt          |t                    o,t           fdt          |j
                  D                       S )N__bool____len__r  c              3  B   K   | ]}                     |          V  d S r+  )_is_truthy_typer  r  r,  s     r  r  z.TypeChecker._is_truthy_type.<locals>.<genexpr>  s1      SSA,,Q//SSSSSSr  )r  r   r!  r  r]  r  r   r   r_  r   r  r,  r  s   ` r  rL  zTypeChecker._is_truthy_type  s     1h'' 9LL922:>>>9 229===9 FO'88 !\** 1i(( TSSSS9I!'9R9RSSSSS	
r  c                    t           j        sdS t                                                   sdS d	 fd}d	 fd}t	          t
                    r=                     t          j        	                     |                                 dS t	          t                    r=                     t          j        	                     |                                 dS t	          t                    rj        j        dk    r                     dddg           \  }}                     t          j        	                     |            t#          t          |j                   j                                       dS                      t          j        	                     |                                 dS )
z
        Check if a type can have a truthy value.

        Used in checks like::

            if x: # <---

            not x  # <---
        Nr(  r\  c                    t          j                  } t          t                    rdj         d|  S t          t
                    rj        rdj         d|  S t          t                    rit          j        t                    rdj        j         d|  S t          j        t
                    rj        j        rdj        j         d|  S d|  S d|  S )NzMember "z" has type r  z
" returns zCall returns zExpression has type )	rF   rQ  r  r~   r  r   r  rb   r@  )r*  r  r,  r  s    r  format_expr_typez;TypeChecker.check_for_truthy_type.<locals>.format_expr_type  s   a..C$
++ 4=$)=====D'** 	4t} 	4:4=::S:::D(++ 4dk:66 E@t{/@@3@@@W55 E$+:N EDt{3DDsDDD,s,,,3c333r  c                 |    t           t          t          f          rd j         dS t	          j                  S )Nr  )r  r   r~   r  rF   rQ  )r  r,  r  s   r  get_expr_namez8TypeChecker.check_for_truthy_type.<locals>.get_expr_name  sA    $: 677 4'49'''' #1dl333r  r  typing
Collection)r(  r\  )r   r  r   rL  r  r   r  r   FUNCTION_ALWAYS_TRUEr  r   TYPE_ALWAYS_TRUE_UNIONTYPEr   r  r  r  ITERABLE_ALWAYS_TRUErF   rt  rQ  TYPE_ALWAYS_TRUE)r,  r  r  rQ  rS  r  r  s   ```    r  check_for_truthy_typez!TypeChecker.check_for_truthy_type  s    $ 	FA##A&& 	F	4 	4 	4 	4 	4 	4 	4 	4	4 	4 	4 	4 	4 	4 	4 	4 a&& 	ZII&;BB==??SSUYZZZZZ9%% 	ZII&AHHIYIYI[I[\\^bccccc8$$ 		Z<M)M)M--hlTVWWGAtII 5<<$$&&HT164J4JDL(Y(Y  	     II&7>>?O?O?Q?QRRTXYYYYYr  rd   expr_indices	list[int]c                   dd}g }d}d}|D ]}|j         |         }t          |t                    r, ||          r!|                    |j        d                    P|                     |          }	|	h|i i fc S t          |t                    r&t          |j        t                    r|j        j	        }|	}|si i fS g }
g }|D ]m}| 
                    |                     |          ||          \  }}t          |||          \  }}|
                    |           |                    |           ndd} ||
          }|r ||          }ni }||fS )a  Narrow types based on any checks of the type ``type(x) == T``

        Args:
            node: The node that might contain the comparison
            expr_indices: The list of indices of expressions in ``node`` that are being
                compared
        r  rb   r(  r!  c                \    t          | j        d          ot          | j                  dk    S )z)Is expr a call to type with one argument?r8  r~  )r   r@  r  rt  )r  s    r  is_type_callz8TypeChecker.find_type_equals_check.<locals>.is_type_call.  s'    %dk?CC[DIZ[H[[r  NFr   	list_mapsr  r  c                x    t          d | D                       rdS i }| D ]}||                    |           |S )z2Combine all typemaps in list_maps into one typemapc              3     K   | ]}|d u V  	d S r+  r  r  r  s     r  r  zKTypeChecker.find_type_equals_check.<locals>.combine_maps.<locals>.<genexpr>`  s&      0019000000r  N)r_  r  )r`  
result_mapr  s      r  combine_mapsz8TypeChecker.find_type_equals_check.<locals>.combine_maps^  sZ    00i00000 tJ ) )=%%a(((r  )r  rb   r(  r!  )r`  r  r(  r  )operandsr  rb   r1  rt  get_isinstance_typer   r  r   r  #conditional_types_with_intersectionr  r  )r,  r  r[  r_  exprs_in_type_callstype_being_comparedr  r  r  r9  if_maps	else_mapscurrent_if_typecurrent_else_typecurrent_if_mapcurrent_else_mapre  r   r  s                      r  find_type_equals_checkz"TypeChecker.find_type_equals_check#  s   	\ 	\ 	\ 	\
 136:! 	7 	7E='D$)) 7ll4.@.@ 7#**49Q<8888#77=='&2 r6MMM!$00 6Z	85T5T 6#'9#5*6''" 	r6M!##%	' 	/ 	/D151Y1Y  &&(;T2 2.O. 0Mo'80 0,N, NN>***-....	 	 	 	 g&&
  	#|I..HHHxr  in_boolean_contextrs  c                   |                      ||          \  }}|                     |          }|                     |          }||fS )a  Find any isinstance checks (within a chain of ands).  Includes
        implicit and explicit checks for None and calls to callable.
        Also includes TypeGuard and TypeIs functions.

        Return value is a map of variables to their types if the condition
        is true and a map of variables to their types if the condition is false.

        If either of the values in the tuple is None, then that particular
        branch can never occur.

        If `in_boolean_context=True` is passed, it means that we handle
        a walrus expression. We treat rhs values
        in expressions like `(a := A())` specially:
        for example, some errors are suppressed.

        May return {}, {}.
        Can return None, None in situations involving NoReturn.
        rr  )find_isinstance_check_helperr  )r,  r  rs  r   r  
new_if_mapnew_else_maps          r  r  z!TypeChecker.find_isinstance_checks  s\    *  <<%7 = 
 
 33F;;
55h??<''r  c          
     0   t          |          ri d fS t          |          rd i fS t          |t                    rxt	          |j                  dk    r_t          |j        d                   }t          |j        d          rt	          |j                  dk    ri i fS t          |          t          k    rSt          |g|                     |                     |          |                     |j        d                   |          R  S nt          |j        d          rLt	          |j                  dk    ri i fS t          |          t          k    r|                     ||          S nt          |j        d          rat	          |j                  dk    ri i fS t          |          t          k    r+|                     |          }|                     ||          S nt          |j        d          rt	          |j                  dk    ri i fS t#          |j        d         |                     |j        d                             }t          |          t          k    rE|rCt	          |          dk    r0|                     ||                     |          |d                   S nUd\  }}|                     |j                  }|kt)          |          }t          |t*                    r$t-          d	||d
          }	|	t)          |	          }t          |t.                    r|j        |j        }}t          |j        t4                    r|j        j        |j        j        }}||B|j        d         t8          j        k    rt          |t.          t<          f          r|j        d         j         d         }
|
|j         v r5|j         !                    |
          }t          |j        |                   }n=|dnd}| "                    tF          j$        %                    |          |           i i fS t          |          t          k    r`||tM          |          ii fS |J t          |g|                     |                     |          tO          |d          g|d          R  S nNt          |tP                    r| )                    |          S t          |tT                    ri }i }| +                    |j,                  \  }}||-                    |           ||-                    |           | +                    |j.        d          \  }}||-                    |           ||-                    |           ||d n|||d n|fS t          |t^                    rg|j0        dk    r\| +                    |j1                  \  }}| +                    |j2                  \  }}tg          ||          ti          ||d
          fS t          |t^                    re|j0        dk    rZ| +                    |j1                  \  }}| +                    |j2                  \  }}ti          ||          tg          ||          fS t          |tj                    r,|j0        dk    r!| +                    |j6                  \  }}||fS t          |          t          k    r| 7                    |          r| 8                    |                     |                    rts          |                     |          d          s| j:        j;        r| <                    |                     |          dd          \  }}|t{          |          }nt}                      }|t          |          }nt}                      }t          |t|                    s||ind }t          |t|                    s||ind }||fS |                     |          }|r| @                    ||           t          |d          }t{          |          }t          |          }t          |t|                    s||ind }t          |t|                    s||ind }||fS )Nr   zbuiltins.isinstancer  r~  zbuiltins.issubclasszbuiltins.callablezbuiltins.hasattrr   r)  Tr-  guardnarrowerFis_upper_boundconsider_runtime_isinstancerr  r  )coalesce_anyornotrI  r  r  )Bis_true_literalr  r  rb   r  rt  r  r   r@  r;   rX   r  rh  r  rg  infer_issubclass_mapsr>  r   hasattr_type_mapslookup_type_or_noner   r   r   r   r  r  r   r  r   rN   r   r  r  r  r  r   TYPE_GUARD_POS_ARG_REQUIREDr  r   r"   rd    comparison_type_narrowing_helperr]   r  r  r  r  r   r  rt  ru  and_conditional_mapsr  r   r  r  can_be_narrowed_with_lenr   rQ  r  narrow_with_lenr   r   r   rZ  r   )r,  r  rs  r  vartyper6  r  r  called_typecallr  r  r  r   r  if_assignment_mapelse_assignment_mapif_condition_mapelse_condition_mapleft_if_varsleft_else_varsright_if_varsright_else_varsrt  ru  yes_typeno_typeoriginal_vartypeif_type	else_types                                 r  ru  z(TypeChecker.find_isinstance_check_helper  s    4   	t8OD!! 	8OdH%% _	$#di..A*=*="49Q<00D!$+/DEE Rty>>Q&&r6M4==L008AA ,,T22D4L4LTYWX\4Z4Z\`     1 $DK1FGG Hty>>Q&&r6M4==L0055dDAAA 1#DK1DEE Cty>>Q&&r6M4==L00"..t44G==dGLLL 1 $DK1CDD =ty>>Q&&r6M/	!d>N>NtyYZ|>\>\]]4==L00T0c$ii1nn11$8H8H8N8NPTUVPWXXX&0#"66t{CC*"1+">">K "+x88 @*:{K]abbb+*9$*?*?K!+|<< Z.9.A;CY dk733 V*.+*=t{?UZG)W-@~a(EM99 &kL*3MNN .#.#4Q#7#A!#DD#t~55&*n&:&:4&@&@'6ty~'F'F2<2Hwwj $		$4$P$W$WX\$]$]_c!" !" !" (*2vt}}44 &1$(/**E*E#F#JJ#*#6#6#6#@ $$!%!I!I$($4$4T$:$:%.wu%M%M%M$N$(@E	 "J "" ""$ $ $  n-- J	$88>>>n-- H	$ FH595O5OPTP[5\5\22 ,/000". 3444373M3M
u 4N 4 400  +.///!- 2333 +26F6NTZ,48J8RX`  f%% .	$$'U*:*:+/+E+Edi+P+P(L.-1-G-G
-S-S*M?
 %\=AA $NORVWWW  f%% !	$$'T//+/+E+Edi+P+P(L.-1-G-G
-S-S*M?
 $L-@@$^_EE  i(( 	$TW-=-=44TY??KD%$;DMM\))d## *--d.>.>t.D.DEE * *$*:*:4*@*@*MM	 *
 , * !% 4 4T5E5Ed5K5KSRS T THg#$X..*,,"$W--)++-7/-R-R\dH%%X\F.8/.R.R\gX\H8##  ++D11 	? &&'7>>>12BOTTG$$w''	(27O(L(LV$RV,6y/,R,R\D)$$X\xr  c           	        d |j         D             }g }i }t          |          D ]\  }}|                     |          si i fc S |                     |          }|                    |           t          |          t          k    r:t          |          s+|                     |          st          |          }||||<   t          |                                |ddh          }	g }
|	D ]D\  }}|dv r|                     ||||||          \  }}n|dv rt          |          dk    sJ |\  }}||         }||         }i i }}||v rt          |          rzt          t!          |                    }|\t          |          sMt#          |t$                    r|j        j        dk    s(t+          ||          rt-          |          |||         <   ||v r5|                     ||          \  }}||         }|d}n|||<   |d}n
|||<   ni }i }|d	v r||}}|
                    ||f           Ft1          d
 |
D                       rt3          |
          S t3          |                     |          d          S )z2Infer type narrowing from a comparison expression.c                ,    g | ]}t          |          S r  )r  )r  r^  s     r  rq  z@TypeChecker.comparison_type_narrowing_helper.<locals>.<listcomp>M  s     >>>1OA&&>>>r  N==is>   r  !=r  is not>   innot inr  r  >   r  r  r  c              3  &   K   | ]}|i i fk    V  d S r+  r  rc  s     r  r  z?TypeChecker.comparison_type_narrowing_helper.<locals>.<genexpr>  s*      88qRH}888888r  Tuse_meet)rf  r  r  r  r1  r;   rX   r  is_literal_enumr<   group_comparison_operandspairwiseequality_type_narrowing_helperr  r   r   builtin_item_typer  r   r  r  r>   r   rG  r@  reduce_conditional_mapsfind_tuple_len_narrowing)r,  r  rf  operand_types narrowable_operand_index_to_hashr  r  r  hsimplified_operator_listpartial_type_mapsoperatorr[  r   r  
left_indexr  r  r;  collection_item_typer  r  s                         r  r  z,TypeChecker.comparison_type_narrowing_helperG  sC    ?>>>>+-( ** 	< 	<GAt==&& 2v((..I  +++ --'-- .,,T22 . !&&=:;4Q7$ $=MMOO=d|$
 $
  &> 6	9 6	9"Hl777#'#F#F! 4$ $  ---<((A----*6'
K)*5	 -k :#%r!AAA*955 V/>?PQ^?_?_/`/`,0<$78L$M$M = !++? J J = %9$=$FJ[$[$[ ;IG[ \ \ %\ <K9;U;UF8J#78"BBB)-)L)L!=* *&GY $K0D!%'.t (#')2 555#+V$$fh%78888
 88&788888 	_*+<=== +4+H+H+N+NY]^^^^r  r  rf  r  r  dict[int, tuple[Key, ...]]c                   |dv rt           }d}d}	nGdd}
dd	}|
}d}fd
|D             }t          t          ||                    ot          |           }	i }i }|	r/|                     |||                                ||          \  }}|i k    r3|i k    r-|                     |||                                          \  }}|i k    r|i k    r|                     ||          \  }}||fS )z@Calculate type maps for '==', '!=', 'is' or 'is not' expression.>   r  r  FTr  r   r(  r!  c                F    t          t          |           t                    S r+  )r  r   r   r:  s    r  is_exactly_literal_typezKTypeChecker.equality_type_narrowing_helper.<locals>.is_exactly_literal_type  s    !/!"4"4kBBBr  c                N    t          | dd           ot          | dd           S )NrW  F)	check_allrX  )r   r:  s    r  has_no_custom_eq_checkszKTypeChecker.equality_type_narrowing_helper.<locals>.has_no_custom_eq_checks  sA    0x5    N/8uMMMMNr  c                     g | ]
}|         S r  r  )r  r  r  s     r  rq  z>TypeChecker.equality_type_narrowing_helper.<locals>.<listcomp>  s    AAAq-*AAAr  r?  )r   r_  r   is_ambiguous_mix_of_enums%refine_identity_comparison_expressionr>  refine_away_none_in_comparisonrq  )r,  r  r  rf  r  r[  r  is_valid_targetcoerce_only_in_literal_contextshould_narrow_by_identityr  r  
expr_typesr   r  s       `          r  r  z*TypeChecker.equality_type_narrowing_helper  su   4 '''6GO-2*(,%%C C C CN N N N
 6O-1*AAAALAAAJ(++Z88) ) )</
;;; & $ 	#II05577.   FH R<<HNN#BB-7W7\7\7^7^   FH R<<HNN#::4NNFHxr  	new_typesc                    |dS i }|                                 D ]D\  }}|||<   |                     ||          }|                                 D ]\  }}||v r
|||<   E|S )a  Attempts refining parent expressions of any MemberExpr or IndexExprs in new_types.

        Specifically, this function accepts two mappings of expression to original types:
        the original mapping (existing_types), and a new mapping (new_types) intended to
        update the original.

        This function iterates through new_types and attempts to use the information to try
        refining any parent types that happen to be unions.

        For example, suppose there are two types "A = Tuple[int, int]" and "B = Tuple[str, str]".
        Next, suppose that 'new_types' specifies the expression 'foo[0]' has a refined type
        of 'int' and that 'foo' was previously deduced to be of type Union[A, B].

        Then, this function will observe that since A[0] is an int and B[0] is not, the type of
        'foo' can be further refined from Union[A, B] into just B.

        We perform this kind of "parent narrowing" for member lookup expressions and indexing
        expressions into tuples, namedtuples, and typeddicts. We repeat this narrowing
        recursively if the parent is also a "lookup expression". So for example, if we have
        the expression "foo['bar'].baz[0]", we'd potentially end up refining types for the
        expressions "foo", "foo['bar']", and "foo['bar'].baz".

        We return the newly refined map. This map is guaranteed to be a superset of 'new_types'.
        N)r  refine_parent_types)r,  r  
output_mapr  r  new_mappingparent_exprproposed_parent_types           r  r  z%TypeChecker.propagate_up_typemap_info  s    2 4
(00 	? 	?OD)(Jt 224CCK5@5F5F5H5H ? ?11 )++*>
;''? r  r  Mapping[Expression, Type]c                d   
 i }	 t          |t                    r@                     |j        |                                         }|j        d
 fd}nt          |t                    r                     |j        |                                         }                     |j        |                                |j                  }||S t          |          d
fd}nt          |          

d

fd	}n|S |S ||S t          |          }t          |t                    s|S g }t          |j                  D ]E} |t          |                    }	|	|c S t          |	|          r|                    |           F|s|S }t#          |          x}|<   )a  Checks if the given expr is a 'lookup operation' into a union and iteratively refines
        the parent types based on the 'expr_type'.

        For example, if 'expr' is an expression like 'a.b.c.d', we'll potentially return refined
        types for expressions 'a', 'a.b', and 'a.b.c'.

        For more details about what a 'lookup operation' is and how we use the expr_type to refine
        the parent types of lookup_expr, see the docstring in 'propagate_up_typemap_info'.
        Tnew_parent_typer   r(  r%  c                    j                                         5 }t          | ddd| d	  	        }d d d            n# 1 swxY w Y   |                                rd S |S )NF)	r  r*  r  r+  r,  r-  r.  r&  in_literal_context)r@  r  r'   r  )r  wmember_typemember_namer  r,  s      r  replay_lookupz6TypeChecker.refine_parent_types.<locals>.replay_lookupD  s    //11 Q&;!, /$/&+%*(-*9 $/4
' 
' 
'               '')) +#t**s   A  AANc                     t           t                    sd S 	 J  fdD             }n# t          $ r Y d S w xY wt          |          S )Nc                *    g | ]}j         |         S r  r  r  r  r  s     r  rq  zJTypeChecker.refine_parent_types.<locals>.replay_lookup.<locals>.<listcomp>i  s!    +_+_+_3O,A#,F+_+_+_r  )r  r   rg  r   )r  member_typesstr_literalss   ` r  r  z6TypeChecker.refine_parent_types.<locals>.replay_lookupd  sx    )/=II (#'4(#/#;#;#;+_+_+_+_R^+_+_+_LL' ( ( (#'44(4\BBB   . 
<<c                     t           t                    sd S 	 J  fdD             }n# t          $ r Y d S w xY wt          |          S )Nc                *    g | ]}j         |         S r  r  r  s     r  rq  zJTypeChecker.refine_parent_types.<locals>.replay_lookup.<locals>.<listcomp>w  s!    /c/c/cs0Ec0J/c/c/cr  )r  r   
IndexErrorr   )r  r  int_literalss   ` r  r  z6TypeChecker.refine_parent_types.<locals>.replay_lookupr  sx    #-oy#I#I ,'+t,'3'?'?'?/c/c/c/cVb/c/c/c#- , , ,'+tt,#8#F#FFr  )r  r   r(  r%  )r  r~   _propagate_walrus_assignmentsr  r  r  rx   r  r  r   r   r   r   r   r  r?   r1  r   )r,  r  r  outputparent_typer  r_  new_parent_typesr  r  r  r  r  r  s   `         @@@@r  r  zTypeChecker.refine_parent_types,  s_    *,h	V
 $
++ @"@@FSS"66{CC"i+ + + + + + + + +$ D),, )"@@FSS"66{CC224:vFFF!55djAA
%!MA*MM+C C C C C C C $Fj#Q#QL#/G G G G G G G  & " *+66Kk955   "-k.?@@ 2 2+mOD,A,ABB& "MMM'Y?? 2$++D111
 $ D.CDT.U.UUI{+Qh	Vr  c                    t          |t                    rgt          |j        t                    r|                     |j        |           |                     |j                  }t          |          }||||<   |S |S )zAdd assignments from walrus expressions to inferred types.

        Only considers nested assignment exprs, does not recurse into other types.
        This may be added later if necessary by implementing a dedicated visitor.
        )r  r]   r  r  r  r  )r,  r  r  assigned_typer  s        r  r  z)TypeChecker._propagate_walrus_assignments  s     dN++ 	$*n55 I224:xHHH 44TZ@@M)$//K((5%r  chain_indicesnarrowable_operand_indicesAbstractSet[int]r  Callable[[ProperType], bool]r  c                T   d}|r ddt          fd|D                       }d}g }	|D ]c}
|
         }|rt          |          } |t          |                    s4|rt          ||          sdi fc S |}|	                    |
           d|i i fS d	}|	D ]}
|
|vr|
}	|d	k    r|	d	         }d}t          |          }t          |t                    r?|                                st          |j        t                    r|j
        j        j        }t          |d
          g}g }|D ]m}
|
|k    r	|
|vr||
         }t          |
                   }|t          ||          }t          ||          }|                    t!          |g|R             nt#          |          S )aG  Produce conditional type maps refining expressions by an identity/equality comparison.

        The 'operands' and 'operand_types' lists should be the full list of operands used
        in the overall comparison expression. The 'chain_indices' list is the list of indices
        actually used within this identity comparison chain.

        So if we have the expression:

            a <= b is c is d <= e

        ...then 'operands' and 'operand_types' would be lists of length 5 and 'chain_indices'
        would be the list [1, 2, 3].

        The 'narrowable_operand_indices' parameter is the set of all indices we are allowed
        to refine the types of: that is, all operands that will potentially be a part of
        the output TypeMaps.

        Although this function could theoretically try setting the types of the operands
        in the chains to the meet, doing that causes too many issues in real-world code.
        Instead, we use 'is_valid_target' to identify which of the given chain types
        we could plausibly use as the refined type for the expressions in the chain.

        Similarly, 'coerce_only_in_literal_context' controls whether we should try coercing
        expressions in the chain to a Literal type. Performing this coercion is sometimes
        too aggressive of a narrowing, depending on context.
        Tr*  r   r(  r!  c                    t          |           } t          |           p t          | t                    o| j        j        S r+  )r   r   r  r   r  r  r*  s    r  should_coerce_innerzNTypeChecker.refine_identity_comparison_expression.<locals>.should_coerce_inner  s;    %c**+C00 sH--B#(2Br  c              3  :   K   | ]} |                   V  d S r+  r  )r  r  r  r  s     r  r  zDTypeChecker.refine_identity_comparison_expression.<locals>.<genexpr>  s4      ]]! 3 3M!4D E E]]]]]]r  Nr  Fr|  r*  r   r(  r!  )r@  r   r   r   r1  r  r   is_enum_literalr  r!  r  r  r  r"   r   conditional_typesr  r  )r,  rf  r  r  r  r  r  should_coercer  possible_target_indicesr  r  singleton_indexsum_type_nametarget_typer  r  r  r  s     `               @r  r  z1TypeChecker.refine_identity_comparison_expression  sY   F ) 	^     ]]]]]}]]]]]M""$ 	. 	.A%a(I 9-i88	"??9#=#=>>   l69==   RxF#**1---- >r6M
 ( 	$ 	$A222"#4 b  5b9O ((fk** 	:""$$	:(26<(F(F	: #O09M >>>? 	R 	RA O## 222A;D)-*:;;I(;I}UU	
 &i==E$$%B4%P%%P%P%PQQQQ&'8999r  c                  
 g }|D ].}||         }t          |          s|                    |           /i i }	}|r t          |          t          |          k    r|D ]M}||         
t          
          st          
fd|D                       rt	          
          |||         <   Nt          d |D                       r4|D ]1}||         
t          
          rt	          
          |	||         <   2||	fS )zProduces conditional type maps refining away None in an identity/equality chain.

        For more details about what the different arguments mean, see the
        docstring of 'refine_identity_comparison_expression' up above.
        c              3  8   K   | ]}t          |          V  d S r+  )r>   )r  r  r  s     r  r  z=TypeChecker.refine_away_none_in_comparison.<locals>.<genexpr>]  s.      ]]Q29a@@]]]]]]r  c              3  Z   K   | ]&}t          t          |          t                    V  'd S r+  )r  r   r   )r  ots     r  r  z=TypeChecker.refine_away_none_in_comparison.<locals>.<genexpr>c  s4      UU:ob118<<UUUUUUr  )r   r1  r  r@  r   )r,  rf  r  r  r  non_optional_typesr  r*  r   r  r  s             @r  r  z*TypeChecker.refine_away_none_in_comparison@  sT      	/ 	/A"C&s++ /"))#...r! 	Kc*<&=&=]ASAS&S&S 0 E E)!,	*955 ]]]]J\]]]]] E*9)*D*DF8A;'
 UU}UUUUU K3 K KA -a 0I*955 K0?	0J0J!-xr  c                ^   t          |t                    sdS t          |j        d          sdS t	          |j                  dk    rdS |j        d         }t          |          t          k    rdS |                     |          sdS | 	                    | 
                    |                    S )zIIs this expression a `len(x)` call where x is a tuple or union of tuples?Fzbuiltins.lenr~  r   )r  rb   r   r@  r  rt  r;   rX   r  r  r  )r,  r  s     r  is_len_of_tuplezTypeChecker.is_len_of_tuplek  s    $)) 	5!$+~>> 	5ty>>Q5y|4==L((5}}T"" 	5,,T-=-=d-C-CDDDr  c                    t          |d          rdS t          |          }t          |t                    r5t	          d |j        D                       r|j        j        j        dk    S dS t          |t                    r|j        
                    d          S t          |t                    r t	           fd|j        D                       S dS )zIs this a type that can benefit from length check type restrictions?

        Currently supported types are TupleTypes, Instances of builtins.tuple, and
        unions involving such types.
        rJ  Fc              3  @   K   | ]}t          |t                    V  d S r+  )r  r   r  s     r  r  z7TypeChecker.can_be_narrowed_with_len.<locals>.<genexpr>  s,      BB:a,,BBBBBBr  r2  Tc              3  B   K   | ]}                     |          V  d S r+  )r  rM  s     r  r  z7TypeChecker.can_be_narrowed_with_len.<locals>.<genexpr>  s1      MMAt44Q77MMMMMMr  )r   r   r  r   r@  r  ry  r  r  r   r  r   )r,  r*  p_typs   `  r  r  z$TypeChecker.can_be_narrowed_with_lenz  s     !i00 	5$$ eY'' 	BBekBBBBB P-2;?OOO4eX&& 	9:&&'7888eY'' 	NMMMMMMMMMMur  c                
   |                      |          sdS |                     |          }t          |          }t          |          }t	          |t
                    sdS t	          |j        t                    sdS |j        S )zIs this expression an int literal, or a reference to an int constant?

        If yes, return the corresponding int value, otherwise return None.
        N)r  r  r   r   r  r   r  rX  )r,  r  r  r  s       r  literal_int_exprzTypeChecker.literal_int_expr  s    
 }}T"" 	4$$T**	%i00	%i00+{33 	4++S11 	4  r  list[tuple[TypeMap, TypeMap]]c                    g }t                      }|                                D ]\  }}}t          |t                    r|j        }t          |t                    r|j        }|dv r+|                    |           |                    |           m|r2|                    dt          |          f           t                      }|dv r|                    |||gf           |r$|                    dt          |          f           g }|D ]L\  }}t           fd|D                       s"t           fd|D                       s>|dv r$t                      }	g }
|D ]{} 	                    |          }||	                    |           / 
                    |          r7t          |t                    sJ |
                    |j        d                    |t          |	          dk    rdi fgc S |	                                }|t          k    r|
D ]V}                                          |          ||          \  }}|dn||i}|dn||i}|                    ||f           Wg|\  }} 
                    |          r||}}t%          j        ||          } 	                    |          }|J |t          k    rt          |t                    sJ                                           |j        d                   ||          \  }}|dn|j        d         |i}|dn|j        d         |i}|                    ||f           N|S )	a  Top-level logic to find type restrictions from a length check on tuples.

        We try to detect `if` checks like the following:
            x: tuple[int, int] | tuple[int, int, int]
            y: tuple[int, int] | tuple[int, int, int]
            if len(x) == len(y) == 2:
                a, b = x  # OK
                c, d = y  # OK

            z: tuple[int, ...]
            if 1 < len(z) < 4:
                x = z  # OK
        and report corresponding type restrictions to the binder.
        )r  r  r  >   >=<r  r  <=r  c              3  F   K   | ]}                     |          d uV  d S r+  )r  r  s     r  r  z7TypeChecker.find_tuple_len_narrowing.<locals>.<genexpr>  s6      MMt,,R00<MMMMMMr  c              3  B   K   | ]}                     |          V  d S r+  )r  r  s     r  r  z7TypeChecker.find_tuple_len_narrowing.<locals>.<genexpr>  s1      @@Bt++B//@@@@@@r  Nr   r~  )ra  r  r  r]   r  r  r1  r  r@  r  r  rb   rt  r  r;  r	  r  r  r   r  )r,  r  chained
last_groupr  rt  ru  r  r  literal_valuestuplesr  r  sizetplr  r  yes_mapno_mapr_sizes   `                   r  r  z$TypeChecker.find_tuple_len_narrowing  s   ( UU
#}} 	8 	8OBe$// "z%00 $\!!t$$$u%%%% 'NND$z*:*:#;<<<!$J???NNBu#6777 	5NND$z"2"23444 	  1	4 1	4IBMMMMuMMMMM @@@@%@@@@@  \!!!$ 2 2B//33C&**3/// ++B// 2)"h77777bgaj111~&&** "2J<'''%))++000! 8 8C(,(<(<T=M=Mc=R=RTVX\(](]%Hg&.&6ddS(OG%,_TT3.F$$gv%67777	8 $e''.. ."'%D!b"--B..u55)))222!$11111$($8$8$$TYq\22B% %!' #+"2$$1x8P!(ty|W6M  '6!23333r  r  c                   t          |          }t          |t                    r|                     |||          S t          |t                    r|                     |||          S t          |t                    rg }g }g }|j        D ]u}|                     |          s|	                    |           -| 
                    |||          \  }}	||	                    |           |	|	                    |	           v||z  }||z  }|rt          |          }
nd}
|rt          |          }nd}|
|fS J d            )zIDispatch tuple type narrowing logic depending on the kind of type we got.NFz"Unsupported type for len narrowing)r   r  r   refine_tuple_type_with_lenr   refine_instance_type_with_lenr   r  r  r1  r  r   )r,  r*  r  r  	yes_typesno_typesother_typesr  ytntr  r  s               r  r  zTypeChecker.narrow_with_len  st   c""c9%% 	?223DAAAX&& 	?55c2tDDDY'' 	?IHKY ( (44Q77 &&q)))--aT::B>$$R(((>OOB'''$I#H  0;; /99W$$>>>>>r  c                   t          |j                  }|3t          |         } ||                                |          r|dfS d|fS |j        |         }t	          |t
                    sJ t          |j                  }t	          |t                    r|                                dz
  |j	        z   }|dv r||k    r||fS d|fS |dv r|dk    r|dz  }||k     r{|j        d|         }	|j        |dz   d         }
t          |
                    ||                                z
  dz                       }||
                    |	|gz   |
z             fS d|fS |                     |t          |         |          \  }}||fS t	          |t                    r|j        j        dk    sJ |                                dz
  }|j        d	         }|j        d|         }	|j        |dz   d         }
|dv r/||k    r%|
                    |	|g||z
  z  z   |
z             |fS d|fS |dv r|dk    r|dz  }||k     r|
                    |	|g||z
  z  z   |gz   |
z             }g }t!          ||z
            D ]5}|                    |
                    |	|g|z  z   |
z                        6t%          j        ||j        |j                  |fS d|fS |                     |t          |         |          \  }}||fS )
z-Narrow a TupleType using length restrictions.Nr~  r  r  r  r  r  )min_lenr  r2  r   )r   r  r   r  r  r   r   r  r   r  rR  r  r   r   r  rt  r  r1  r   r9  r  r  )r,  r*  r  r  unpack_indexr~  unpackr5  r  r  suffixr  r  r  	yes_itemsr  s                   r  r  z&TypeChecker.refine_tuple_type_with_len  s    +3955 &b)FvcjjllD)) !Dy 9<(&*-----"6;//h 011 	) jjllQ&)99G\!!d??8OSy {""::AIDT>> Y}}5F Y|a'7'9'9:F'(>(>tcjjllGZ]^G^(>(_(_``F 1 1&8IF8R 1 S SSSSy $($C$CCQSVZ$[$[!'(( (H--\(-2HL\2\2\2\2\**,,"mA=L=)<!+--.$((v8P/PSY/Y(ZZ\___9;Tzz	~~ ++ C5D7N#;;vhFO ,   	tg~.. [ [A$$S%6%6Vseai=ORX=X%6%Y%YZZZZ +IsxLLgUU9 $ ? ?WR[RV W WHgH$$r  c                   t          ||                     d                    }|j        d         }t          | j        j        v o|j        j        dk    }|dv rt          |g|z  |          |fS |dv r|dk    r|dz  }|r>t          | 
                    d|g                    }t          |g|z  |gz   |          }n|}|r]g }	t          |          D ]*}
|	                    t          |g|
z  |                     +t          j        |	|j        |j                  }n|}||fS |                     |t$          |         |          \  }}||fS )	z5Narrow a homogeneous tuple using length restrictions.r2  r   r  )r  r  r  r  r~  r  )r=   lookup_typeinfort  r   rQ  enable_incomplete_featurer  r  r   r   r  r  r1  r   r9  r  r  r  r   )r,  r*  r  r  r  r  allow_preciser!  r  r  r  r  s               r  r  z)TypeChecker.refine_instance_type_with_lenc  s    )d.B.BCS.T.TUUil  4<#II4h#33 	 C54<#>>>CC;Tzz	 #D$;$;<Lse$T$TUU'0ut|vh7NY\']']'] t E EALLC519s!C!C!CDDDD(1(<UCHcj(Y(YW$$ $ B B3PRUY Z ZHgH$$r  )r)  r  r  r  r  r  r  ErrorCode | Noner  c                   d S r+  r  )
r,  r  r  r  r@  r  r  r)  r  r  s
             r  r  zTypeChecker.check_subtype  s	     sr  )r)  r  c                   d S r+  r  )	r,  r  r  r  r@  r  r  r)  r  s	            r  r  zTypeChecker.check_subtype  s	     sr  str | ErrorMessagec                  t          ||| j                  rdS t          |t                    rt	          ||          }| j                                        r|                     ||           dS |}
t          |          }|}t          |          }| j        	                    ||||||          rdS g }d}|pg }||t          |
|| j                  \  }}||                    |dz   |z              ||                    |dz   |z              t          |	p||||          }t          |t                    r&t          |t                    rt          |||          }t          |t                    r,t          |t                    rt!          |||| j                  }|r.|                    dd	                    |          z   d
z             }|                     ||          }|D ]$}| j                            |||j                   %|r|                     |||j                   | j                            ||||j                   t          |t                    rX|j        j        rLt          |t0          t          t2          t4          t6          f          r| j                            ||||           t          |t0                    rMt          |t                    r8t;          d||d          }|r#| j                            ||||j                   t          |t0          t>          f          rt          |t                    rk|j        j        r_d|j        j         v rQt;          d||d          }|J t          ||| j                  s#| j                            ||||j                   | !                    ||||j                   dS )zBGenerate an error if the subtype is not compatible with supertype.r  Tr  F N z (z, r  )parent_errorr)  ry  )"r   rQ  r  r\  rA   r@  prefer_simple_messagesr  r   &try_report_long_tuple_assignment_errorrH   r1  rI   r   rD   r   rE   r  r   r  r  maybe_note_concatenate_pos_argsr  r  r   r   r   r   report_protocol_problemsr   	note_callr   protocol_memberscheck_possible_missing_await)r,  r  r  r  r@  r  r  r)  r  r  orig_subtypeorig_supertype
extra_infonote_msgsubtype_strsupertype_strerrorr  r  s                      r  r  zTypeChecker.check_subtype  s*    gy$,??? 	4c3 	/s...C8**,, 	IIc7###5!'**"#I..	8::Ym_
 
 	 5 "
$(C)?ndl* * *&K (!!-#"5"CDDD*!!/C"7-"GHHH.('9m H '8,, KIx1P1P K/w	JJ'9-- S*Y	2R2R S)%)T\RR 	N))$:1F1F*F*LMMC		#w'' 	8 	8DHMM$chM7777 	8IIhchI77700)WSVS[0\\\y(++	_*	_ 7\8YW_$`aa	_
 H--gy'X]-^^^i.. 	J:gx3P3P 	Jz7GNNND J""7D'"IIIgj9:: 	Pz)U]?^?^ 	P~) PjIN<[.[.[":y'tTTT'''!'4FFF PH&&y$ch&OOO))'9gCH)UUUur  r  r4   c                J   t          t          |          t                    rdS 	 | j                            |t                      dd          }n# t          $ r Y dS w xY w|                                rdS t          t          |          t          t          f          rdS |S )zIf type implements Awaitable[X] with non-Any X, return X.

        In all other cases return None. This method must be called in context
        of local_errors.
        Nr.  T)ignore_binder)
r  r   r   rx  rl  re   rg  r  r   r   )r,  r*  r  aw_types       r  get_precise_awaitable_typez&TypeChecker.get_precise_awaitable_type  s     oc**K88 	4	'<<WYY$ =  GG  	 	 	44	 &&(( 	4og..+0FGG 	4s   *A 
AAc              #  H   K   d| _         	 d V  d| _         d S # d| _         w xY wr  )rl  rw  s    r  checking_await_setzTypeChecker.checking_await_set  s>      &*#	0EEE*/D'''%D'////s    	!c                   | j         rdS |                                 5  | j                                        5 }|                     ||          }|	 ddd           ddd           dS |                     |||t          j                  s	 ddd           ddd           dS 	 ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   | j                            ||           dS )z7Check if the given type becomes a subtype when awaited.N)r@  )	rl  rD  r@  r  rB  r  r   INCOMPATIBLE_TYPESpossible_missing_await)r,  r  r  r  r  r  rA  s          r  r7  z(TypeChecker.check_possible_missing_await  s    & 	F$$&& 	 	(>(>(@(@ 	L55g|LLG	 	 	 	 	 	 	 	 	 	 	 	 	 	 %%G1A1T &    	 	 	 	 	 	 	 	 	 	 	 	 	 			 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	''66666sF   C
B3C
*$B3C
'C
3B7	7C
:B7	;C

CCc                   |dk    r(| j         |                     |          | _         | j         S |dk    r(| j        |                     |          | _        | j        S |dk    r(| j        |                     |          | _        | j        S |dk    r(| j        |                     |          | _        | j        S |dk    r(| j        |                     |          | _        | j        S |                     |          S )zReturn an instance type with given name and implicit Any type args.

        For example, named_type('builtins.object') produces the 'object' type.
        r  Nr  zbuiltins.intr  r  )rq  _named_typerr  rs  rt  ru  r  s     r  r  zTypeChecker.named_type!  s   
 >!!~%!%!1!1$!7!7>!&&&"*&*&6&6t&<&<#&&>!!~%!%!1!1$!7!7>!?""&"&"2"24"8"8?"$$$ ($($4$4T$:$:!$$%%%r  c                z   |                      |          }|j        }t          |t                    r(t          |j        t
                    sJ |j        j        }t          |t                    s
J |            t          t          j
                  }t          ||gt          |j        j                  z            S r+  )lookup_qualifiedr  r  r   r  r   r  r   r   r   from_omitted_genericsr  r  rL  )r,  r  rQ  r  r  s        r  rI  zTypeChecker._named_type<  s    ##D))xdI&& 	$dk844444;#D$))//4///9:;;xj3ty/B+C+CCDDDr  rt  c                d    |                      |          }d |D             }t          ||          S )zReturn an instance with the given name and type arguments.

        Assume that the number of arguments is correct.  Assume that
        the name refers to a compatible generic type.
        c                ,    g | ]}t          |          S r  )r-   )r  r  s     r  rq  z2TypeChecker.named_generic_type.<locals>.<listcomp>N  s!    GGG31#66GGGr  )r&  r   )r,  r  rt  r  s       r  r  zTypeChecker.named_generic_typeG  s:     ##D))GG$GGGd###r  r  c                |    |                      |          }|j        }t          |t                    s
J |            |S r+  )rK  r  r  r   )r,  r  rQ  r  s       r  r&  zTypeChecker.lookup_typeinfoR  s?    ##H--x$))//4///r  c                ,    |                      d          S )zReturn instance type 'type'.r8  r  rw  s    r  rO  zTypeChecker.type_typeY  s    ///r  c                ,    |                      d          S )zReturn instance type 'str'.r  rQ  rw  s    r  r  zTypeChecker.str_type]  s    ~...r  c                &    || j         d         |<   dS )z)Store the type of a node in the type map.r  N)r0  )r,  r  r*  s      r  r  zTypeChecker.store_typea  s    $'D!!!r  c                ^    t          fdt          | j                  D                       S )Nc              3      K   | ]}|v V  	d S r+  r  )r  r  r  s     r  r  z'TypeChecker.has_type.<locals>.<genexpr>f  s'      @@419@@@@@@r  )r@  r#  r0  r  s    `r  r  zTypeChecker.has_typee  s0    @@@@ht&?&?@@@@@@r  c                P    t          | j                  D ]}||v r
||         c S d S r+  )r#  r0  )r,  r  r  s      r  r  zTypeChecker.lookup_type_or_noneh  s;    $/** 	 	Aqyyw tr  c                    t          | j                  D ]}|                    |          }||c S t          |          r+  )r#  r0  r  rg  )r,  r  r  r  s       r  r  zTypeChecker.lookup_typen  sI    $/** 	 	AdA} tnnr  r  c                F    | j         d                             |           d S r  )r0  r  )r,  r  s     r  r  zTypeChecker.store_typesu  s#    ""1%%%%%r  c                F    | j         j        p| j         p| j        d          S )zShould we type-check the current function?

        - Yes if --check-untyped-defs is set.
        - Yes outside functions.
        - Yes in annotated functions.
        - No otherwise.
        r  )rQ  r  rI  rw  s    r  r  zTypeChecker.in_checked_functionx  s-     L+c43E/EcTM_`bMcIc	
r  c                    || j         v r| j         |         S | j                             dd          }|r4t          |j        t                    sJ |j        j        }||v r||         S t          d|           )z?Look up a definition from the symbol table with the given name.__builtins__NzFailed lookup: )rM  r  r  r  r   r`  rg  )r,  r  r\  tables       r  lookupzTypeChecker.lookup  s    4<<%%  66A '!!&(333335== ;&3T33444r  c                   d|vr|                      |          S |                    d          }| j        |d                  }t          dt	          |          dz
            D ]Q}|j                            ||                   }|
J d            t          |j        t                    sJ |j        }R|d         }||j        v r|j        |         S t	          |          dk    ru|d         dv rkd
                    |          }|t          v r(d                    |d         t          |                   }nd	}t          d
                    ||                    d}	t          |	                    ||                    )Nr  r   r~  z0Internal error: attempted lookup of unknown namer  r  )builtinsrT  z*, e.g. add '[{} fixtures/{}]' to your testr.  zmCould not find builtin symbol '{}' (If you are running a test case, use a fixture that defines this symbol{})z0Failed qualified lookup: '{}' (fullname = '{}').)r]  splitrO  r  r  r`  r  r  r  r   r   rB   r  rg  )
r,  r  partsr  r  rQ  lastr  
suggestionr@  s
             r  rK  zTypeChecker.lookup_qualified  sw   d??;;t$$$JJsOOEU1X&A1c%jj1n--  gkk%(++(Z!#(H55555H9Dqwwt}$UqU1X1G%G%G88E??666!M!T!Ta"9("C" "JJ "$J--3VD*-E-E   Iszz$55666r  )r"  r  r"  c             #  :  K   | j         r| j         d         j        p|}| j                             t          i ||                     dV  | j        j        r| p| j        j        o| j        o| j        d         }| j                                         \  }}}| j	        s|
                                D ]\  }}| j        j         p|p|o|                     |          }	|	r<t          |j        t                    r"|j        j        |st!                      |_        i|| j        vrB|s@| j                            ||| j        j                   | j                            |           |j        r+t-          |j                  }
|
|j        k    |_        |
|_        dS dS )zEnter a new scope for collecting partial types.

        Also report errors for (some) variables which still have partial
        types, i.e. we couldn't infer a complete type.
        r  N)rJ  r#  r1  r  rQ  allow_untyped_globalsr  rI  r;  rc  r  local_partial_typesis_defined_in_base_classr  r  r   r   rK  r@  r  r  r  r   r  )r,  r"  r  r#  
permissiverJ  r  r  r  
allow_nonefixeds              r  r  zTypeChecker.enter_partial_types  s      &J4+=b+A+JZ{!!"22{H"M"MNNN
 l8I\ 
L+]0B]tGYZ\G] 	 #04466q!) "	) - 3 3 5 5 !) !)W 88 I"I GT%B%B3%G%G  )"38[99) -& .  (zzCHH$"777
788gt|Gbccc-11#666x ) 238 < <38CH3D0#(E"	) "	)!) !)r  r   r+  c                   |                      |          \  }}}|j        |r|st                      S |S |{| j        st|rW||         }|s| j        j        s@| j                            ||| j        j                   | j	        
                    |           n|                     |j        |           t          |          S )zjHandle a reference to a partial type through a var.

        (Used by checkexpr and checkmember.)
        ) find_partial_types_in_all_scopesr  r   rc  rQ  re  r@  r  r  rK  r  r  r  r   )r,  r*  r+  r  r  in_scoper#  rJ  s           r  handle_partial_var_typez#TypeChecker.handle_partial_var_type  s     -1,Q,QRV,W,W)(M8  zz!
(1K( 	J+D1G 8t|'I 888 '4<+F   -11$777 55diIII%c***r  c                    j         sdS j         j        p,t          fdj         j        dd          D                       S )NFc              3  P   K   | ] }|                     j                  d uV  !d S r+  )r  r  )r  r  r  s     r  r  z7TypeChecker.is_defined_in_base_class.<locals>.<genexpr>	  sG       /
 /
/3DHHSXd*/
 /
 /
 /
 /
 /
r  r~  )r  r  r@  r  )r,  r  s    `r  rg  z$TypeChecker.is_defined_in_base_class  sc    x 	5x' 
3 /
 /
 /
 /
7:x|ABB7G/
 /
 /
 ,
 ,
 	
r  dict[Var, Context] | Nonec                @    |                      |          \  }}}|r|S dS )a  Look for an active partial type scope containing variable.

        A scope is active if assignments in the current context can refine a partial
        type originally defined in the scope. This is affected by the local_partial_types
        configuration option.
        N)rl  )r,  r  rm  r  rJ  s        r  r  zTypeChecker.find_partial_types  s1     &*%J%J3%O%O"!] 	!  tr  ,tuple[bool, bool, dict[Var, Context] | None]c                   t          | j                  D ]u}||j        v rj| j        j        }t          |j        t                    r|j        j        	|j        rd}| p|j	        | j        d         j	        k    }||j	        |j        fc S vdS )zLook for partial type scope containing variable.

        Return tuple (is the scope active, is the scope a local scope, scope).
        NTr  )FFN)
r#  rJ  r   rQ  rf  r  r  r   r  r#  )r,  r  rF  disallow_other_scopesscope_actives        r  rl  z,TypeChecker.find_partial_types_in_all_scopes  s     d011 	? 	?Eei )-(H%ch44 19RWZW_9R -1) .-b4CUVXCYCb1b  $U^UY>>>>   "!r  r   c                $    t          ||          S )z3Create a temporary node with the given, fixed type.r  r:  )r,  r  r  s      r  r%  zTypeChecker.temp_node2  s    7++++r  r  r2   c                   t          |t                    r'| j                            |j        ||j                  S | j                            |||          S )zProduce an error message.r  )r  rA   r@  r  r  r  )r,  r@  r  r  s       r  r  zTypeChecker.fail6  sO     c<(( 	D8==G#(=CCCx}}S'}555r  offsetc                   t          |t                    r)| j                            |j        ||j                   dS | j                            ||||           dS )zProduce a note.r  N)ry  r  )r  rA   r@  r  r  r  )r,  r@  r  ry  r  s        r  r  zTypeChecker.note>  s[     c<(( 	HMM#)W38M<<<Fc76=====r  r  /Instance | CallableType | TypeType | Overloadedc                   t          |t                    rTt          ||                     d                    }|j        d         }t          t          |          t                    s|S |                     ||          d         S )Nr  r   r~  )r  r   r=   r&  rt  r   r   rs  )r,  r  r  ro  r  s        r  rA  zTypeChecker.iterable_item_typeL  s}     b(## 	!0T5I5IJ[5\5\]]H a(Ioi88'BB ! ! AA"gNNqQQr  c                H    t          ||                     d                    S )Nr  )r   r  )r,  r  s     r  r   zTypeChecker.function_typeY  s    T4??3F#G#GHHHr  r  r  c                   || j                                          d S |                                D ]"\  }}| j                             |||           #d S )Nr  )rA  r  r  r  )r,  r  r  r  r  s        r  r  zTypeChecker.push_type_map\  sj    K##%%%%%&nn.. M M
ddOLLLLM Mr  rb   c                
   |                      |          }|                     |j        d                   }t          |t                    r|j        }t          |          }t          |t                    r^g }t          |j	                  D ]7}t          |t                    r|                    |j                   2i i fc S t          |          }net          |t                    r|j        }nHt          |t                    r/|j                                        r|                     d          }ni i fS |                     |||          \  }}t%          |||          \  }	}
t'          t(          |	|
f          \  }	}
|	|
fS )z=Infer type restrictions for an expression in issubclass call.r~  r  )r  rg  rt  r  r   r/  r   r   r   r  r   r1  r  r   r  rN  r  rh  r  r   convert_to_typetype)r,  r  r  r  r  
union_listr  r  r  r  r  s              r  r  z!TypeChecker.infer_issubclass_mapsc  s   ""4((''	!55g{++ 	*)G!'**gy)) 	J%gm44 " "a** "%%af---- r6MMM
++GG** 	lGG** 	w|/H/H/J/J 	oo&788GG r6M DDWdTXYY'7hPP1GV3DEEr  r~  type_rangeslist[TypeRange] | Noner&  r  c                   d S r+  r  r,  r  r  r&  r&  r  s         r  rh  z/TypeChecker.conditional_types_with_intersection  s	     +.#r  c                   d S r+  r  r  s         r  rh  z/TypeChecker.conditional_types_with_intersection  s	      Cr  c                  t          ||||          }|d         }|d         }t          t          |          t                    r|||fS t          |          }	t          |	t                    r"t          |	                                          }
n|	g}
g }|D ]G}t          |j                  }t          |t          t          f          r|
                    |           H|s||fS g }g }|
D ]}t          |t                    s||fc S |D ]m}t          |t                    r&|
                    d|j        j         ddf           =|                     ||f|          }|X|
                    |           n|sH|                                 r$|D ]!\  }}| j                            |||           "t                      |fS t#          |          }||fS )Nr~  r   r~  r  z" and "NoneType"z"NoneType" is final)r  r  r   r   r   r   r`  r  r   r   r1  r  r  r  r  r@  impossible_intersectionr   )r,  r  r  r&  r&  r  initial_typesr  r  r  possible_expr_typespossible_target_typesr  r  outr?  r  r  intersectionr  reasonnew_yes_types                         r  rh  z/TypeChecker.conditional_types_with_intersection  sK    *(C	
 
 
 !.a 0,Q//(33_EE 	%I\W$$ &i00k9-- 	0"2;3M3M3O3O"P"P#.- " 	3 	3B"27++D$8 455 3%,,T222$ 	%W$$(*$ 
	) 
	)Aa** )((((* ) )a** MM#Dqv{#D#D#DF["\]]]#77AGG'

<(((()  	04466 I%+ I IME6H44UFCHHHH"$$i//,S11Y&&r  c                    t          |t                    r|j        r	|j        sdS dS t          |t                    r7|j        r0|j        d         }t          |t                    sJ |j        j        S dS )z!Check if an attribute is writableFTr   )r  r   r  r   r   r  rg   r  )r,  r  
first_items      r  r  z!TypeChecker.is_writable_attribute  s    dC   	7 (A u4/00 	7T5E 	7AJj)44444>66ur  c                   t          |t                    r|j        dk    r|                     |j                  }|2t          |j                  rt          t                      d          g}|                     |j                  }|2t          |j                  rt          t                      d          g}||d S ||z   S t          t          |                     |                              }g }|D ]}t          |t                    r|                                rmt          |                                          }t          |t                     rt#          |          }n|}|                    t          |d                     t          |t&                    rHd}	t          |j        t                    rd}	|                    t          |j        |	                     t          |t*                    rV|j        j        dk    rFt+          |j        j        d         g           }
|                    t          |
d                     at          |t*                    rO|j        j        dk    r?|j        r8|                    t          t5          |j                  d                     t          |t6                    r&|                    t          |d                       d S |sd S |S )Nr  Fr|  Tr8  r  ztypes.UnionType)r  r   r  rg  rt  r  r"   r   ru  r   flatten_typesr  r   rv  r   rw  r   r,   r1  r   r  r   r  r  r  rt  r   r   )r,  r  rt  ru  rQ  r  r*  any_parameterizederased_typer}  ra  s              r  rg  zTypeChecker.get_isinstance_type  s   dF## 		 3++DI66D|	 : :|!(**UCCCD,,TZ88E}!<!<}"8::eDDDE|u}t%<$]43C3CD3I3I%J%JKK	!# 	 	C#|,, 1B1B $:3??;L;L$M$M!/;; 4"01B"C"CKK"3KY{5IIIJJJJC**  "&ch11 +%*NYsxOOOPPPPC** sx/@O/S/S&sx|B'7<<Y{4HHHIIIIC** sx/@DU/U/UZ]Zb/UYy':':5QQQRRRRC)) Ys5AAABBBBtt 	 4r  c                   t          |t                    rt          |j        t                    sdS |                     |j                  }|                     |          }||dS t          |          }t          t          |                    }t          |t                    rt          |t                    sdS |	                                sdS |
                                o!|j        j        |                                k    S )a  Returns true if this expression (with the given type context) is an Enum literal.

        For example, if we had an enum:

            class Foo(Enum):
                A = 1
                B = 2

        ...and if the expression 'Foo' referred to that enum within the current type context,
        then the expression 'Foo.A' would be a literal enum. However, if we did 'a = Foo.A',
        then the variable 'a' would *not* be a literal enum.

        We occasionally special-case expressions like 'Foo.A' and treat them as a single primitive
        unit for the same reasons we sometimes treat 'True', 'False', or 'None' as a single
        primitive unit.
        F)r  r~   r  r   r  r   r   r   r   rv  r  r  r  rw  )r,  r  r  r  s       r  r  zTypeChecker.is_literal_enum  s   " !Z(( 	
1680L0L 	5..qv66..q11+"55%k22%&7&D&DEE+|44 	J{T_<`<` 	5&&(( 	5 '')) G$)[-D-D-F-FF	
r  c                    |}t          |          }t          t          j                  }t	          |t
                    r-|                    |          }|j        J d|j        _        |S t	          |t                    r1|j
                            |          }|                    |          S t	          |t                    r1|j                            |          }|                    |          S t	          |t                    rGt	          |j        t
                    r-t          j                             |j                            S t	          |t$                    rB|                                         |j                   fd|j        D                       S t	          |t*                    r8                     |          \  }}t/          | fd|D             z             S |S )z8Inject an extra attribute with Any type using fallbacks.Nr%  c                <    g | ]}                     |          S r  add_any_attribute_to_type)r  r  r  r,  s     r  rq  z9TypeChecker.add_any_attribute_to_type.<locals>.<listcomp>O  s)    TTTA66q$??TTTr  )r/  r  c                <    g | ]}                     |          S r  r  )r  r*  r  r,  s     r  rq  z9TypeChecker.add_any_attribute_to_type.<locals>.<listcomp>T  s)    ___3T;;CFF___r  )r   r   r   r9  r  r   copy_with_extra_attrr  mod_namer   ry  rR  r   r  r   r  r  r  r   r/  r  r   partition_union_by_attrr   )	r,  r*  r  r  r  r  r  	with_attrwithout_attrs	   ` `      r  r  z%TypeChecker.add_any_attribute_to_type7  s   c""9011c8$$ 	--dH==F %111*.F'Mc9%% 	8+@@xPPH$$h$777c<(( 	8|88xHHH$$h$777c8$$ 	\CHh)G)G 	\+D,J,J38UY,Z,Z[[[c;'' 	$$ ::3?DQQTTTTTTTT %    c9%% 	&*&B&B3&M&M#I|(_____R^____   r  source_typec                V   |                      ||          r||ii fS t          |          }t          |t                    rD|                     ||          \  }}||                     ||          i}||t          |          ifS |                     ||          }||k    r||ii fS i i fS )af  Simple support for hasattr() checks.

        Essentially the logic is following:
            * In the if branch, keep types that already has a valid attribute as is,
              for other inject an attribute with `Any` type.
            * In the else branch, remove types that already have a valid attribute,
              while keeping the rest.
        )has_valid_attributer   r  r   r  r  r   )r,  r  r  r  r  r  r  type_with_attrs           r  r  zTypeChecker.hasattr_type_mapsX  s     ##K66 	++&**%k22k9-- 	H"::;MMOA|T;;KNNOGT#8#F#FGGG77TJJ[((.)2--2vr  c                    g }g }|j         D ]C}|                     ||          r|                    |           .|                    |           D||fS r+  )r  r  r1  )r,  r  r  r  r  r  s         r  r  z#TypeChecker.partition_union_by_attrq  sq     	% 	* 	*D''d33 *  &&&&##D)))),&&r  c                   t          |          }t          |t                    rdS t          |t                    r |j        r|j        j        r|j        j        }nd }| j        	                                5 }t          ||t          t          t          j                            ddd|| d|
  
         d d d            n# 1 swxY w Y   |                                 S )NFT)r+  r,  r-  r.  r&  no_deferralmodule_symbol_table)r   r  r   r   r  r  r  r`  r@  r  r'   r   r   r  r  )r,  r*  r  r  r  watchers         r  r  zTypeChecker.has_valid_attribute}  s(   $$eW%% 	5eX&& 	'5+< 	'ARA[ 	'"'*"2"&X##%% 	!!78899!! $7   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ))++++s   7>CCCr|  c                :    | j                             ||          S )Nr  )rx  r  )r,  r  r|  s      r  get_expression_typezTypeChecker.get_expression_type  s     ''<'HHHr  c               :    | j         |j        j                 j        S r+  )rO  r  r  rd  )r,  r*  s     r  is_defined_in_stubzTypeChecker.is_defined_in_stub  s    |CH0199r  c                T   t          t                    rj        t          t          t          t
          f          rfj        a| j        j        D ]:}t          |t                    r#t          fd|j        D                       r dS ;|                     |           dS dS dS )zEWarn if deprecated and not directly imported with a `from` statement.Nc              3  :   K   | ]}j         |d          k    V  dS )r   Nr  )r  r  r  s     r  r  z/TypeChecker.check_deprecated.<locals>.<genexpr>  s.      6\6\QtyAaD7H6\6\6\6\6\6\r  )r  rg   r  rp   r   r   
deprecatedrZ  importsrw   r@  r`  r  )r,  r  r  imps    `  r  check_deprecatedzTypeChecker.check_deprecated  s    dI&& 	9DdW&7BCC 	4O'y( 4 4c:.. 36\6\6\6\RUR[6\6\6\3\3\ EE$$T733333	4 	4''r  c                v   t          t                    rj        t          t          t          t
          f          rsj        x}l| j        sgt          fd| j	        j
        D                       sD| j	        j        r| j        j        n| j        j        } |||t          j                   dS dS dS dS dS )zWarn if deprecated.Nc              3  h   K   | ],}j         |k    pj                             | d           V  -dS )r  N)r  r+  )r  r  r  s     r  r  z.TypeChecker.warn_deprecated.<locals>.<genexpr>  sY         "Gdm&>&>!www&G&G     r  r  )r  rg   r  rp   r   r   r  rf  r@  rQ  deprecated_calls_excludereport_deprecated_as_noter@  r  r  r  
DEPRECATED)r,  r  r  r  warns    `   r  r  zTypeChecker.warn_deprecated  s    dI&& 	9Dtg'8(CDD
	=#.;) <    >     < %)L$J]48==PTPXP]DDW5+;<<<<<<
	= 
	=;;;;;;r  	namespacec                @    d| d| j          }| xj         dz  c_         |S )zNGenerate a name that is guaranteed to be unique for this TypeChecker instance.zdummy--r~  )rY  )r,  r  r  s      r  r  z!TypeChecker.new_unique_dummy_name  s.    5	55DO551r  r   c                   d S r+  r  r  s     r  visit_pass_stmtzTypeChecker.visit_pass_stmt      tr  r   c                   d S r+  r  r  s     r  visit_nonlocal_declzTypeChecker.visit_nonlocal_decl  r  r  rr   c                   d S r+  r  r  s     r  visit_global_declzTypeChecker.visit_global_decl  r  r  )r?  r3   rO  rN  rQ  r   rZ  r   r[  r\  rW  r   r]  r^  r(  r)  )r(  rB  )r(  rz  r(  r)  r+  )r  r  rg  r!  r(  r!  )r  r  r(  r)  )r  r   r(  r)  )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  r   r(  r)  )r  r   r(  r"  )r$  r%  r&  re   r(  r'  )r*  r   r]  r!  r(  r!  r  )rj  r   r]  r!  r(  r   )rj  r   r(  r   )r  rp   r(  r)  )NNF)
r  rq   r  r'  r  r  r  r!  r(  r)  )r  rp   r  r   r(  r)  )r(  r"  F)
r  rq   r*  r   r  r  r  r!  r(  r)  )r  r   r  rp   r(  r!  )r  r   r  rX  r(  r!  )r*  r   r(  r)  )r  rq   r  r!  r(  r)  )r/  r\  r(  r!  )r  rq   r(  r)  )r  rp   r*  r   r(  r)  )
r  rq   rT  r   rU  r\  r  re   r(  r)  )rT  r   rU  r\  rk  r   rj  r   rf  r\  ri  r   r  re   r(  r)  )rp  r   ri  r   rT  r   r(  r!  )r  ro   r(  r)  )r*  r   r  re   r  r\  r(  r)  )r*  r   r  re   r(  r)  )r  r   r*  r   r  re   r(  r)  )r  rq   r*  r   r(  r  )r  r  r!  r  r  r  r(  r)  )r  r  r(  r  )r  r  r  r   r  r!  r(  r  )r  r   r  r   r(  r)  )r  r  r  r\  r  r   r(  r!  )r  r   r(  r%  )r  r   r  r   r  r\  r  r\  r  r\  r  r!  r  r!  r  re   r(  r!  )r  rq   r(  r)  )r  rc   r(  r)  )r*  r   r(  r)  )r  rB  r(  r)  )r  rc   r  r   r(  r)  )rQ  r   r(  r!  )
r  r\  rq  r   rp  r   r&  r   r(  r)  )r  rw   r(  r)  )r  ru   r(  r)  )r  rt   r(  r)  )r  rv   r(  r)  )r\  r_   r(  r)  )r(  r!  )r  r   r(  r!  r  r^   r(  r)  )TF)
r  r|   r  rk   r  r!  r  r!  r(  r)  )r  r   r  rk   r(  r%  )r  r|   r  rk   r  r\  r(  r)  )r  r   r  rk   r(  r)  )r  r   r  rk   r  r   r  r   r  r   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  r\  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/  r0  r(  r0  T)
r  r7  r  rk   r  re   r  r!  r(  r)  )
r  r7  rY  rX  r  re   rZ  r[  r(  r!  )TNF)r  r7  r  rk   r  re   r  r!  rh  r%  ri  r!  r(  r)  )r  r0  r  rk   r  r   r  re   r  r!  r(  r)  )r  r0  r(  r0  )r  r7  r  rk   r  r   r  re   ri  r!  r  r!  r(  r)  )r  r7  r  r   r(  r   )r  r  rP  rX  r  rX  r(  r  )r  r   r(  r!  )
r  r7  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  re   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  rk   r(  r!  )r  r%  r  rk   r  re   r@  rA   r'  r\  r(  r\  r)  r  r  r  r  r  r(  r  )r  r   r(  r!  )r  r~   r  r   r  r   r  rk   r  re   r(  r  )r  rx   r  rk   r  re   r(  r)  )r  r   r  r   rJ  r  r(  r)  )r  rx   r  rk   r(  r)  )r*  r   r(  r  )r  rl   r(  r)  )r  r   r(  r)  )r  rk   r   r   r  r!  r(  r   )r  rs   r(  r)  )r  r   r(  r)  )r  r   r(  r)  )r  r\   r(  r)  )r  r   r(  r)  )r^  rk   r  r   r3  r!  r(  r)  )r  r   r(  r)  )r  r   r=  r!  r(  r)  )r  rk   rG  r!  r(  r   )rG  r!  r(  r   )r  rW  r(  r   )r*  r   r  rk   r(  rG  r  rn   r(  r)  )r  rk   r(  rg  )r  r   r  re   r(  rg  )r  rk   r(  r%  )r*  r   r(  r%  )
r  rk   r  r   r  r!  r  re   r(  r)  )r  rh   r(  r)  )r^  rg   r(  r)  FF)r^  rg   r  r!  r  r!  r(  r)  )r  rp   r  r   r  rk   r(  r)  r  r   r(  r)  )r*  r   r  rp   r(  r)  )r  rk   r  r  r  r!  r(  r   )r  r`   r(  r)  )r  rf   r(  r)  )r  r}   r(  r)  )r  r}   r  rk   r(  rk   )r  rk   r*  r   r(  r.  )r  r  r(  r  )r  r  r  r  r(  r)  )r  r   r(  r)  )
r  r\  r  r\  r  r\  r  r  r(  r  )r   r  r?  r  r(  r  )r*  r   r   r   r(  r   )r*  r   r(  r   )r*  r   r-  r!  r(  r.  )r  rk   r9  r%  r(  r:  )r  r   r;  r   r(  r?  )r  r   r  rk   r(  r)  )r  rd   r[  r\  r(  r:  )r  rk   rs  r!  r(  r:  )r  rd   r(  r:  )r  rd   r  r\  rf  r0  r  rG  r[  r\  r  r  r(  r:  )r  r  r(  r  )r  rk   r  r   r(  r  )r  rk   r  r.  r(  rk   )rf  r0  r  rG  r  r\  r  r  r  r  r  r!  r(  r:  )
rf  r0  r  rG  r  r\  r  r  r(  r:  )r  rk   r(  r!  )r  rk   r(  r[  )r  rd   r(  r  )r*  r   r  r\  r  rX  r(  r?  )r*  r   r  r\  r  rX  r(  r?  )r*  r   r  r\  r  rX  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  r   r  re   r@  rA   r  r  r  r  r)  r  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  r4   r(  r%  )
r  r   r  r   r  re   r  r)  r(  r)  )r  r\  r(  r   )r  r\  rt  rG  r(  r   )r  r\  r(  r   )r(  r   )r  rk   r*  r   r(  r)  )r  rk   r(  r!  )r  rk   r(  r%  )r  rk   r(  r   )r  r.  r(  r)  )r  r\  r(  r   )r"  r!  r  r!  r(  r"  )
r*  r   r+  r!  r  r   r  re   r(  r   )r  r   r(  r!  )r  r   r(  rq  )r  r   r(  rs  )r  r   r  r  r(  r   )r@  r,  r  re   r  r)  r(  r2   r  )
r@  r,  r  re   ry  rX  r  r)  r(  r)  )r  r{  r  re   r(  r   )r  ro   r(  r   )r  r  r  r!  r(  r)  )r  rb   r  rk   r(  r:  )r  r   r  r  r&  re   r&  r)  r  r!  r(  r?  )r  r   r  r  r&  re   r&  r   r  r!  r(  rg  )r  r   r  r  r&  re   r&  r%  r  r!  r(  r?  )r  r   r(  r!  )r  rk   r(  r  r  rk   r(  r!  )r*  r   r  r\  r(  r   )r  rk   r  r   r  r\  r(  r:  )r  r   r  r\  r(  r.  )r*  r   r  r\  r(  r!  )r  rk   r|  r%  r(  r   )r*  r   r(  r!  )r  r	  r  re   r(  r)  )r  r\  r(  r\  )r  r   r(  r)  )r  r   r(  r)  )r  rr   r(  r)  )r  r  r  r=  rd  r  rb  r  r  rc  rf  rR  rS  r-  propertyrx  r|  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  rd  ri  ro  rw  r{  r~  r  r  r	  r  r  r  r  r  r  r  r3  r  r  r  r  rd  rm  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r2  r!  r  r  r)  rM  rT  rO  rP  r(  r  rn  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r&  r6  r  rD  rH  rl  r  rk  r  rE  r@  rn  r  r  r  r  r  r  r  r  r  r   r  r-  r  r  r  r  r  r  r  r  r
  r  r!  r$  r+  r1  r6  r4  r@  r>  rF  rN  rP  rL  rf  ra  rb  rs  rt  r  r^  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r(  r,  r1  r>  rG  rL  rZ  rq  r  ru  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  rB  rD  r7  r  rI  r  r&  rO  r  r  r  r  r  r  r  r]  rK  r  rn  rg  r  rl  r%  r  r  rA  r   r  r  rh  r  rg  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r'  r'  :  s          GNNN -,,, "!!!3333####MMM))))       '&&&H!I " 8<;;;;"""""  )((( NNN OOON N N N` " " " X" / / / X/- - - -$* * * *\ IM& )-	& & & & & &P" " " ". . . .H H H H: : : : _ _ _ _ '+;'
 -137;' ;' ;' ;' ;' ;'B2 2 2 2c5 c5 c5 c5J : : : ^:5 5 5 5nAR AR AR AR\^ ^ ^ ^&$ $ $ $ 3  3  3  3D! ! ! !F# # # #   >' ' ' '9 9 9 9( .2!!J !J !J !J !JF) ) ) )V 2 2 2 ^2 X]n% n% n% n% n%`	= = = =~   *   (! ! ! !F; ; ; ;> > > >)M )M )M )MV! ! ! !FV
 V
 V
 V
p>N >N >N >N@2
 2
 2
 2
hM M M M4N N N N:W W W W"
 
 
 
    ! ! ! !8 #'	    .!) !) !) !)F'! '! '! '!RY Y Y Yq q q qfI I I I b b b bH3 3 3 32J) J) J) J)XS S S S. . . .`U U U U" " " ":X X X X; ; ; ;0   8   8#V #V #V #VJE E E E,VR VR VR VRpB B B B0                        ,5 5 5 5&
 
 
 
   83A 3A 3A 3Aj3 3 3 3 #' tD tD tD tD tDn *@AV(WWWWW' ' ' 'R.' .' .' .'`] ] ] ]~! ! ! !R ")-:) :) :) :) :) :)x      := = = =(" " " " ) ) ) ^)4Q 4Q 4Q 4Ql 
  
  
  
D   &   H #'RU RU RU RU RUr %)" " " " "R #'#!&4 4 4 4 4lA& A& A& A&F	 	 	 	$ #'[ [ [ [ [z$M $M $M $ML! ! ! ! 
 
 
 
 #'= = = = =4 ;?-3 -3 -3 -3 -3^    (F (F (F (FT* * * *X   2%E %E %E %EN6 6 6 6( ( ( (   0 -M%'k, #'$(#k, k, k, k, k, k,Z
 
 
 
#Z #Z #Z #ZJ& & & &4; ; ; ;%P %P %P %PN   "
0 
0 
0 
0" " " "
" " " "HlI lI lI lI\- - - -2F F F F   0% % % %" " " "    :'= '= '= '=R,) ,) ,) ,)\'0 '0 '0 '0R   4 4 4 4   "
 
 
 
"	# 	# 	# 	#" " " "& & & &&   6   ,\ \ \ \   $& & & & PUH6 H6 H6 H6 H6T	K 	K 	K 	K[ [ [ [#  #  #  # J; ; ; ;
 
 
 
&   # # # #   ] ] ] ]~! ! ! !$       , , , ,\+ + + +. . . .   ,dd dd dd ddL? ? ? ?8D D D DT  T  T  T l   8%
 %
 %
 %
N
 
 
 
 4Z 4Z 4Z 4ZlN  N  N  N b ?C( ( ( ( ( (: ?Cv  v  v  v  v  v pq_ q_ q_ q_fE  E  E  E N) ) ) )VvV vV vV vVp   $H: H: H: H:T)  )  )  ) VE E E E   ,! ! ! ! [ [ [ [z ?  ?  ?  ?DB% B% B% B%H% % % %H  %)&* #'!%(,     X  %)&* #'(,     X& %)&*L #'!%(,L L L L L L\   , 0 0 0 ^07 7 7 7"& & & &6	E 	E 	E 	E	$ 	$ 	$ 	$   0 0 0 0/ / / /( ( ( (A A A A      & & & &

 

 

 

5 5 5 57 7 7 7> %*U6) 6) 6) 6) 6) ^6)p+ + + +:
 
 
 

 
 
 
" " " "2, , , , ,
 VZ6 6 6 6 6 6 	> "&> > > > > >R R R RI I I I KO M M M M M M   <  . -1. . . . . X.  -1          X   $=' -1=' =' =' =' =' ='~
 
 
 
- - - -^$
 $
 $
 $
L   B   2
' 
' 
' 
', , , ,2I I I I I: : : :4 4 4 4= = = =               r  r'  c                  "    e Zd ZdZd	dZd
dZdS )r  z0Collects the non-nested argument types in a set.r(  r)  c                ,    t                      | _        d S r+  )ra  r  rw  s    r  r-  zCollectArgTypeVarTypes.__init__  s    +.55r  r  r   c                :    | j                             |           d S r+  )r  r  rN  s     r  visit_type_varz%CollectArgTypeVarTypes.visit_type_var  s    1r  Nr  )r  r   r(  r)  )r  r  r  r=  r-  r  r  r  r  r  r    sB        ::1 1 1 1     r  r  Tr~  r9  r   proposed_type_rangesr  r&  r)  r  r!  r(  r?  c                   d S r+  r  r9  r  r&  r  s       r  r  r    s	     '*cr  rg  c                   d S r+  r  r  s       r  r  r    s	     r  r%  c                  |rXt          |          dk    r|d         j        }t          |          }t          |t                    rO|                                st          |j        t                    r!|j        j	        j
        }t          | |          } d |D             }t          |          }t          |t                    r||fS t          d |D                       s"t          | |d          r|t!                      fS t#          | |d          st!                      |fS t%          j        d |D                       }t)          | ||          }	||	fS | |fS )	a  Takes in the current type and a proposed type of an expression.

    Returns a 2-tuple: The first element is the proposed type, if the expression
    can be the proposed type. The second element is the type it would hold
    if it was not the proposed type, if any. UninhabitedType means unreachable.
    None means no new information can be inferred. If default is set it is returned
    instead.r~  r   c                    g | ]	}|j         
S r  r  r  
type_ranges     r  rq  z%conditional_types.<locals>.<listcomp>    s    QQQj*/QQQr  c              3  $   K   | ]}|j         V  d S r+  r|  r  s     r  r  z$conditional_types.<locals>.<genexpr>   s6       
 
*4J%
 
 
 
 
 
r  Tr  c                *    g | ]}|j         	|j        S r  )r}  r  r  s     r  rq  z%conditional_types.<locals>.<listcomp>   s3       "%4O  r  r~  )r  r  r   r  r   r  r  r!  r  r  r  r   r   r   r@  r   r   r?   r   r9  r   )
r9  r  r&  r  r  	enum_nameproposed_itemsproposed_typeproposed_precise_typeremaining_types
             r  r  r    s     )%#$$)))!,1F$V,,F&+.. X&&((X,6v|T,J,JX #O09	>|YWWQQ<PQQQ-n==mW-- 	1 !')) 
 
8L
 
 
 
 
 	1mtTTT	1 O----%lMUYZZZ 	1"$$g-- %.$8 &:  % %! 3%,G  N
 !.00 W$$r  r  rk   r  r  r:  c                t   t          |           } g }||fD ]o}t          |          }t          |t                    r|                    d            <||                    i            T|J |                    | |i           pt          t          t          t          f         t          |                    S r+  )r  r   r  r   r1  r   rs  r  )r  r  r  mapsr*  r  s         r  r  r  #   s     4  DD'" % %%c**k?33 	%KK KKOOOO???KKs$$$$gw&'t555r  r  r\  r\  r   c                    | |vr| S d}| t          |          z   |v r|dz  }| t          |          z   |v | t          |          z   S )zKGenerate a name that does not appear in table by appending numbers to base.r~  )r\  )r  r\  r  s      r  r"  r"  5   s\    5	A
Q-5
 
 	Q Q-5
 
 #a&&=r  r  c                b    t          | d          pt          | t                    o
| j        dk    S )z>Returns true if this expression is the 'True' literal/keyword.zbuiltins.Truer   r   r  ry   r  r  s    r  r  r  ?   s0    a11\Z75K5K5\PQPW[\P\\r  c                b    t          | d          pt          | t                    o
| j        dk    S )z?Returns true if this expression is the 'False' literal/keyword.r  r   r  r  s    r  r  r  D   s1    a!122]jG6L6L6]QRQX\]Q]]r  c                B    t          | t                    o
| j        dk    S )z>Returns true if this expression is the 'None' literal/keyword.r$  r  r   r  r  s    r  r  r  I   s    a""Dqz_'DDr  c                B    t          | t                    o
| j        dk    S )Nzbuiltins.NotImplementedr  r  s    r  r  r  N   s    a""Nqz5N'NNr  r  rq   c                `   | j         j         }t          |          dk    ot          |d         x}t                    or|j        du pt          |j                  oUt          |d         x}t                    o8t          |j        x}t                    o|j        du pt          |j                  S )z
    Checks whether a function's body is 'return; yield' (the yield being added only
    to promote the function into a generator function).
    r  r   Nr~  )r  r  r  r   r  r  rl   r   )r  r  ret_stmt	expr_stmt
yield_exprs        r  r  r  R   s    
 9>DD		Q 	J47*xJ77	J]d"Dohm&D&D	J DG+y^<<	J Y^3zY??		J
 _$H
(H(Hr  r  c                   t          |           } t          | t                    rS| j        j        dv rC| j        sdS t          t          | j        d                   t                    s| j        d         S nft          | t                    rg }| j        D ]}t          |t                    rt          |j                  }t          |t                    rt          |j                  }t          |t                    r|j        j        dk    sJ |                    |j        d                    |                    |           t          d t          |          D                       rt          |          S n`t          | t                     rK| j        j        j        D ]/}|j        dk    r"t'          | j        |          j        d         c S 0J d            dS )	a  Get the item type of a builtin container.

    If 'tp' is not one of the built containers (these includes NamedTuple and TypedDict)
    or if the container is not parameterized (like List or List[Any])
    return None. This function is used to narrow optional types in situations like this:

        x: Optional[int]
        if x in (1, 2, 3):
            x + 42  # OK

    Note: this is only OK for built-in containers, where we know the behavior
    of __contains__.
    )r  r2  r  r  zbuiltins.frozensetz_collections_abc.dict_keysztyping.KeysViewNr   r2  c              3  B   K   | ]}t          |t                     V  d S r+  )r  r   r  s     r  r  z$builtin_item_type.<locals>.<genexpr>   s/      XXr:b'***XXXXXXr  ztyping.MappingFz2No Mapping base class found for TypedDict fallback)r   r  r   r  r  rt  r   r   r  r   r   r/  r1  r_  r   r   r   r  r  r=   )r  normalized_itemsr  r5  r  s        r  r  r  b   s    
		B"h %K7  
 
 
 7 tobgaj997CC "wqz!	B		"	" K( 	, 	,B"j)) 	,*2733h(899 E.x/CDDHx227?}7MQa7a7a7a7a ''a(89999 ''++++XX5EFV5W5WXXXXX 	;()9:::	;	B	&	& K K$( 	L 	LD} 0000dCCHKKKK 1JJJJJ4r  Fm1m2r  c                z   | |dS |                                 }d |D             }| D ]F}t          |          |vs(t          t          | |                   t                    r| |         ||<   G|rI| D ]F}|D ]A}t          |          t          |          k    rt          | |         ||                   ||<   BG|S )zCalculate what information we can learn from the truth of (e1 and e2)
    in terms of the information that we can learn from the truth of e1 and
    the truth of e2.
    Nc                ,    h | ]}t          |          S r  )r<   )r  n2s     r  r  z'and_conditional_maps.<locals>.<setcomp>   s     ---B|B---r  )copyr<   r  r   r   r@   )r  r  r  r  m2_keysn1r  s          r  r  r     s     
zRZt WWYYF--"---G    7**jB9P9PRY.Z.Z*BF2J <  	< 	<B < <##|B'7'777!+BrFBrF!;!;F2J< Mr  r  c                   | |S || S i }| D ]}}|D ]x}t          |          t          |          k    rV|r4t          t          | |                   t                    r| |         ||<   Xt	          | |         ||         g          ||<   y~|S )zCalculate what information we can learn from the truth of (e1 or e2)
    in terms of the information that we can learn from the truth of e1 and
    the truth of e2. If coalesce_any is True, consider Any a supertype when
    joining restrictions.
    )r<   r  r   r   r   )r  r  r  r  r  r  s         r  r  r     s     
z		z	
 &(F I I 	I 	IBB<#3#333 IJr"v/F/F$P$P I!#BF2JJ!6227G!H!HF2J	I Mr  r  r  c                    t          |           dk    ri i fS t          |           dk    r| d         S | d         \  }}| dd         D ]'\  }}t          |||          }t          ||          }(||fS )a  Reduces a list containing pairs of if/else TypeMaps into a single pair.

    We "and" together all of the if TypeMaps and "or" together the else TypeMaps. So
    for example, if we had the input:

        [
            ({x: TypeIfX, shared: TypeIfShared1}, {x: TypeElseX, shared: TypeElseShared1}),
            ({y: TypeIfY, shared: TypeIfShared2}, {y: TypeElseY, shared: TypeElseShared2}),
        ]

    ...we'd return the output:

        (
            {x: TypeIfX,   y: TypeIfY,   shared: PseudoIntersection[TypeIfShared1, TypeIfShared2]},
            {shared: Union[TypeElseShared1, TypeElseShared2]},
        )

    ...where "PseudoIntersection[X, Y] == Y" because mypy actually doesn't understand intersections
    yet, so we settle for just arbitrarily picking the right expr's type.

    We only retain the shared expression in the 'else' case because we don't actually know
    whether x was refined or y was refined -- only just that one of the two was refined.
    r   r~  Nr  )r  r  r  )r  r  final_if_mapfinal_else_mapr   r  s         r  r  r     s    4 9~~2v	Y1		|'0|$n )!"" 	K 	KFH/fxXXXL0JJNN^++r  r  c                   i }| d S |                                  D ]m\  }}|}t          |t                    r|j        }t          t	          |          t
          t          t          f          si c S t          j	        |          ||<   n|S r+  )
r  r  r   r/  r   r   r   r   r   r  )r  converted_type_mapr  r*  r  s        r  r  r     s    13t^^%% A A	ca%% 	A/!,,y(H.MNN 	III#+#;C#@#@4  r  r  r0  c                    t          | t          t          f          rd | j        D             S t          | t                    rt          | j                  S | gS )zAFlatten a nested sequence of tuples/lists into one list of nodes.c                6    g | ]}t          |          D ]}|S r  )r  r  ar\  s      r  rq  zflatten.<locals>.<listcomp>!  s+    777aGAJJ77q7777r  )r  r   r{   r  r   r  r  r:  s    r  r  r  
!  sV    !i*++ 77177777	Ax	 	  qvs
r  rG  c                    t          |           } t          | t                    rd | j        D             S t	          | d          r| j        d         gS | gS )z;Flatten a nested sequence of tuples into one list of nodes.c                6    g | ]}t          |          D ]}|S r  )r  r	  s      r  rq  z!flatten_types.<locals>.<listcomp>!  s-    ===aM!,<,<==q====r  r2  r   )r   r  r   r  r   rt  r:  s    r  r  r  !  s_    A!Y ==17====	1.	/	/ q	{s
r  r  r   dict[TypeVarId, Type]c                |    t          |          }|                    |           }t          |t                    sJ |S r+  )TypeTransformVisitorr  r  rq   )r  r   visitorr  s       r  r  r  !  s;    "3''G
,,t

Cc8$$$$$Jr  c                  (     e Zd Zd	 fdZd
dZ xZS )r		  r   r	  r(  r)  c                V    t                                                       || _        d S r+  )superr-  r   )r,  r   	__class__s     r  r-  zTypeTransformVisitor.__init__'!  s$    r  r  r   c                ,    t          || j                  S r+  )r8   r   r  s     r  r  zTypeTransformVisitor.type+!  s    4***r  )r   r	  r(  r)  r  )r  r  r  r-  r  __classcell__r	  s   @r  r		  r		  &!  sQ             + + + + + + + +r  r		  r   r  c                    t          | j        |j                  }t          |                                 |                                          }||k    S )zOCan a single call match both t and s, based just on positional argument counts?)maxr  minmax_possible_positional_args)r  r  r  max_argss       r  rH  rH  /!  sG    1:qz**H11133Q5S5S5U5UVVHxr  r  list[CallableType]c                   | j         D ]\}|j                                        rAt          | |j        |j        i                              d | j         D                       }  n]|                                 s| gS g }| j         D ]T}t          |t                    r"|j	        r|
                    |j	                   9|
                    |j        g           Ug }t          j        | D ]X}d t          | j         |          D             }|
                    t          | |                              g                      Y|S )zRExpand a generic callable using all combinations of type variables' values/bounds.c                D    g | ]}|j                                         |S r  )r  r$  r  s     r  rq  z,expand_callable_variants.<locals>.<listcomp>=!  s'    HHHH1HHHr  r  c                $    i | ]\  }}|j         |S r  r  )r  rE  r  s      r  
<dictcomp>z,expand_callable_variants.<locals>.<dictcomp>N!  s     RRR[b%BE5RRRr  )rO  r  r$  r8   r/  rR  
is_genericr  r   r  r1  r  r  r  )r  rE  tvar_valuesr  variantscombinationtvar_maps          r  expand_callable_variantsr!	  6!  sf   k   5==?? 	Ar~677EEHHakHHH F  A E		 <<>> s
K 3 3dK(( 	3T[ 	3t{++++ 012222H (+6 N NRRC[4Q4QRRRAx00>>>LLMMMMOr  r  r  class_type_varslist[TypeVarLikeType]rr  c                x   t          | |          } t          ||          }t          |           D ]}t          |          D ]w}t          |j        |j                  rt	          ||t
          ddd d          st	          ||t
          ddd d          sV|rt	          ||t          dddd          s  dS xdS )aS  Check if two overloaded signatures are unsafely overlapping or partially overlapping.

    We consider two functions 's' and 't' to be unsafely overlapping if three
    conditions hold:

    1.  s's parameters are partially overlapping with t's. i.e. there are calls that are
        valid for both signatures.
    2.  for these common calls, some of t's parameters types are wider that s's.
    3.  s's return type is NOT a subset of t's.

    Note that we use subset rather than subtype relationship in these checks because:
    * Overload selection happens at runtime, not statically.
    * This results in more lenient behavior.
    This can cause false negatives (e.g. if overloaded function returns an externally
    visible attribute with invariant type), but such situations are rare. In general,
    overloads in Python are generally unsafe, so we intentionally try to avoid giving
    non-actionable errors (see more details in comments below).

    Assumes that 'signature' appears earlier in the list of overload
    alternatives then 'other' and that their argument counts are overlapping.
    Fc                $    t          | |           S r+  is_subset_no_promoter<  s     r  r?  z;is_unsafe_overlapping_overload_signatures.<locals>.<lambda>!      6J1a6P6P2P r  T)r@  check_args_covariantlyr   rA  allow_partial_overlapc                $    t          ||            S r+  r&	  r<  s     r  r?  z;is_unsafe_overlapping_overload_signatures.<locals>.<lambda>!  r(	  r  )r@  r)	  r   rB  r*	  )detach_callabler!	  r'	  r  r   !is_overlapping_types_for_overload)r  r  r"	  rr  sig_variantother_variants         r  rM  rM  S!  s'   <  	?;;IE?33E
 0	:: ' '5e<< &	 &	M $K$8-:PQQ &!?+0&+%P%P*.   *!?+/&+%P%P*.  (    	'=.'+"'"&*( ( ( 	 ttt	;&	N 5r  r*  c                `    |s| S |                      t          | j                  |z             S )aw  Ensures that the callable's type variables are 'detached' and independent of the context.

    A callable normally keeps track of the type variables it uses within its 'variables' field.
    However, if the callable is from a method and that method is using a class type variable,
    the callable will not keep track of that type variable since it belongs to the class.
    r  )rR  r  rO  )r*  r"	  s     r  r,	  r,	  !  s7      
tCM':':_'LMMMr  c                r    t          | d | j        D                       }t          ||t          dd          S )zCheck if the 'other' method can never be matched due to 'signature'.

    This can happen if signature's parameters are all strictly broader then
    other's parameters.

    Assumes that both signatures have overlapping argument counts.
    c                8    i | ]}|j         t          |          S r  )r  r   )r  r  s     r  r	  z,overload_can_never_match.<locals>.<dictcomp>!  s%    ___4DG8>>___r  TrD  )r8   rO  r   r   )r  r  exp_signatures      r  rI  rI  !  sO      __9K^___ M "u4_c   r  r   c                   t          | t                    r/t          |t                    rt          | |t          dd          S nt          | t                    rpt          |t                    r[t          | j                  t          |j                  k    r1t          d t          | j        |j                  D                       S dS )z#Does t have wider arguments than s?TrD  c              3  <   K   | ]\  }}t          ||          V  d S r+  )is_same_arg_prefix)r  r  itemts      r  r  z-is_more_general_arg_prefix.<locals>.<genexpr>!  sB        9E&ue44     r  F)	r  r   r   r   r   r  r  r_  r  r  r  s     r  r|  r|  !  s     !\"" 
a&& 	)1 1TY]   	 
A|	$	$ a&& 	17||s17||++  ILQWVWV]I^I^      5r  c           	     8    t          | |t          dddd          S )NT)r@  r   rB  r)	  r  )r   r   r8	  s     r  r6	  r6	  !  s.    !		#!   r  r  tuple[bool, str]c                    t          |           } t          j        |         }d}t          | t                    rt          | ||          }n+t          | t                    rt          | j        ||          }|d|fS d|fS )zDetermine if operator assignment on given value type is in-place, and the method name.

    For example, if operator is '+', return (True, '__iadd__') or (False, '__add__')
    depending on which method is supported by the type.
    NTF)r   r   
op_methodsr  r   _find_inplace_methodr   r  )r*  r  r~  existing_methods       r  r'  r'  !  s     #

C!(+FO#x   O.sFHEE	C	'	' O.s|VXNN"_$$&=r  r(  r   r~  r  c                t    |t           j        v r)d|dd          z   }| j                            |          r|S d S )N__ir  )r   ops_with_inplace_methodr  r]  )r(  r~  r  inplace_methods       r  r=	  r=	  !  sE    9444+9((88 	"!!4r  rQ  r   r  r  c                    t          |           }t          |t                    r|p	| o|j        S t          |t                    rdS |                     t                                 S )a  Is an inferred type valid and needs no further refinement?

    Examples of invalid types include the None type (when we are not assigning
    None to a final lvalue) or List[<uninhabited>].

    When not doing strict Optional checking, all types containing None are
    invalid.  When doing strict Optional checking, only None and types that are
    incompletely defined (i.e. contain UninhabitedType) are invalid.
    F)r   r  r   r  r   r  InvalidInferredTypes)r*  rQ  r  r  r  s        r  r  r  !  so     "#&&K+x(( 
 ['7#7#ZG<Z[	K	1	1 uzz.001111r  c                  D     e Zd ZdZd fdZddZdd
ZddZddZ xZ	S )rD	  zFind type components that are not valid for an inferred type.

    These include <Erased> type, and any uninhabited types resulting from failed
    (ambiguous) type inference.
    r(  r)  c                T    t                                          t                     d S r+  )r	  r-  r   )r,  r	  s    r  r-  zInvalidInferredTypes.__init__!"  s!    &&&&&r  r  r   r!  c                    |j         S r+  )r  rN  s     r  visit_uninhabited_typez+InvalidInferredTypes.visit_uninhabited_type$"  s
    {r  r   c                    dS r  r  rN  s     r  visit_erased_typez&InvalidInferredTypes.visit_erased_type'"  s    tr  r   c                4    |j                                         S r+  )r  is_meta_varrN  s     r  r  z#InvalidInferredTypes.visit_type_var+"  s     t!!!r  r   c               6    |                      |j                  S r+  )query_typesr  rN  s     r  visit_tuple_typez%InvalidInferredTypes.visit_tuple_type0"  s    (((r  r  )r  r   r(  r!  )r  r   r(  r!  )r  r   r(  r!  )r  r   r(  r!  )
r  r  r  r=  r-  rH	  rJ	  r  rO	  r	  r	  s   @r  rD	  rD	  "  s         ' ' ' ' ' '      " " " "
) ) ) ) ) ) ) )r  rD	  c                  "    e Zd ZdZd
dZddZd	S )r  zRReplace all ambiguous Uninhabited types with Any (to avoid spurious extra errors).r  r   r(  r   c                F    |j         rt          t          j                  S |S r+  )r  r   r   rs  rN  s     r  rH	  z&SetNothingToAny.visit_uninhabited_type8"  s"    ; 	19/000r  r   c                R     |                      fd|j        D                       S )Nc                :    g | ]}|                               S r  )r  )r  r	  r,  s     r  rq  z9SetNothingToAny.visit_type_alias_type.<locals>.<listcomp>@"  s#    $D$D$DQXXd^^$D$D$Dr  )rt  )rR  rt  rN  s   ` r  visit_type_alias_typez%SetNothingToAny.visit_type_alias_type="  s0     $D$D$D$DQV$D$D$DEEEr  N)r  r   r(  r   )r  r   r(  r   )r  r  r  r=  rH	  rT	  r  r  r  r  r  5"  sH        \\   
F F F F F Fr  r  r  SymbolNode | Noner  c                    t          | t                    r| j        } t          | t                    r| j        S t          | t
                    r| j        S dS )z+Find out if a node describes a classmethod.N)r  rg   r  rp   r  r   rL  r  s    r  r  r  C"  sU    $	"" y$   }$ #""4r  c                    t          | t                    r| j        } t          | t                    r| j        S t          | t
                    r| j        S dS )z6Find out if a node describes a static function method.N)r  rg   r  rp   r  r   r  rW	  s    r  r  r  N"  sU    $	"" y$   ~$ $##4r  TKeyTValuec                  :    e Zd ZdZddZdd	ZddZddZddZdS )DisjointDictai  An variation of the union-find algorithm/data structure where instead of keeping
    track of just disjoint sets, we keep track of disjoint dicts -- keep track of multiple
    Set[Key] -> Set[Value] mappings, where each mapping's keys are guaranteed to be disjoint.

    This data structure is currently used exclusively by 'group_comparison_operands' below
    to merge chains of '==' and 'is' comparisons when two or more chains use the same expression
    in best-case O(n), where n is the number of operands.

    Specifically, the `add_mapping()` function and `items()` functions will take on average
    O(k + v) and O(n) respectively, where k and v are the number of keys and values we're adding
    for a given chain. Note that k <= n and v <= n.

    We hit these average/best-case scenarios for most user code: e.g. when the user has just
    a single chain like 'a == b == c == d == ...' or multiple disjoint chains like
    'a==b < c==d < e==f < ...'. (Note that a naive iterative merging would be O(n^2) for
    the latter case).

    In comparison, this data structure will make 'group_comparison_operands' have a worst-case
    runtime of O(n*log(n)): 'add_mapping()' and 'items()' are worst-case O(k*log(n) + v) and
    O(k*log(n)) respectively. This happens only in the rare case where the user keeps repeatedly
    making disjoint mappings before merging them in a way that persistently dodges the path
    compression optimization in '_lookup_root_id', which would end up constructing a single
    tree of height log_2(n). This makes root lookups no longer amoritized constant time when we
    finally call 'items()'.
    r(  r)  c                0    i | _         i | _        i | _        d S r+  )
_key_to_id_id_to_parent_id_root_id_to_valuesrw  s    r  r-  zDisjointDict.__init__x"  s#    +-
 13 ;=r  r>  	set[TKey]r  set[TValue]c                (    |sdS  fd|D             }|d         } j         |         }|                    |           |dd         D ]I}||k    s	| j         vr| j        |<   |                     j                             |                     JdS )a  Adds a 'Set[TKey] -> Set[TValue]' mapping. If there already exists a mapping
        containing one or more of the given keys, we merge the input mapping with the old one.

        Note that the given set of keys must be non-empty -- otherwise, nothing happens.
        Nc                :    g | ]}                     |          S r  )_lookup_or_make_root_id)r  r  r,  s     r  rq  z,DisjointDict.add_mapping.<locals>.<listcomp>"  s'    KKKs55c::KKKr  r   r~  )r`	  r  r_	  r;  )r,  r>  r  subtree_rootsnew_rootroot_valuessubtree_roots   `      r  add_mappingzDisjointDict.add_mapping"  s      	FKKKKdKKK #-h76""")!""- 	J 	JLx''<t?V+V+V2:D!,/t6::<HHIIII		J 	Jr  #list[tuple[set[TKey], set[TValue]]]c                $   i }| j         D ]G}|                     |          }||vrt                      ||<   ||                             |           Hg }|                                D ]'\  }}|                    || j        |         f           (|S )z1Returns all disjoint mappings in key-value pairs.)r^	  _lookup_root_idra  r  r  r1  r`	  )r,  root_id_to_keysr  root_idr  r>  s         r  r  zDisjointDict.items"  s    02? 	. 	.C**3//Go--+.55(G$((----,2244 	D 	DMGTMM4!8!ABCCCCr  r  rY	  rX  c                    || j         v r|                     |          S t          | j                   }|| j         |<   || j        |<   t	                      | j        |<   |S r+  )r^	  rm	  r  r_	  ra  r`	  )r,  r  new_ids      r  re	  z$DisjointDict._lookup_or_make_root_id"  sa    $/!!'',,,))F#)DOC ,2D!&).1eeD#F+Mr  c                    | j         |         }|| j        |         k    r5| j        | j        |                  }|| j        |<   |}|| j        |         k    5|S r+  )r^	  r_	  )r,  r  r  
new_parents       r  rm	  zDisjointDict._lookup_root_id"  sf    OC 4(+++ .t/DQ/GHJ'1D!!$A 4(+++ r  Nr  )r>  ra	  r  rb	  r(  r)  )r(  rk	  )r  rY	  r(  rX  )	r  r  r  r=  r-  rj	  r  re	  rm	  r  r  r  r\	  r\	  ]"  s         4
= 
= 
= 
=J J J J(           r  r\	  pairwise_comparisons,Iterable[tuple[str, Expression, Expression]]operand_to_literal_hashMapping[int, Key]operators_to_grouprT  list[tuple[str, list[int]]]c                   d |D             }g }d}t                      }t                      }t          |           D ]\  }\  }	}
}||	}|rk|	|k    s|	|vra|s%|                    |t          |          f           n||                             ||           |	}t                      }t                      }|                    |           |                    |dz              |	|v r[|                    |          }||                    |           |                    |dz             }||                    |           	|C|s%|                    |t          |          f           n||                             ||           |                                D ]C\  }	}|                                D ])\  }}|                    |	t          |          f           *D|                    d            |S )a  Group a series of comparison operands together chained by any operand
    in the 'operators_to_group' set. All other pairwise operands are kept in
    groups of size 2.

    For example, suppose we have the input comparison expression:

        x0 == x1 == x2 < x3 < x4 is x5 is x6 is not x7 is not x8

    If we get these expressions in a pairwise way (e.g. by calling ComparisonExpr's
    'pairwise()' method), we get the following as input:

        [('==', x0, x1), ('==', x1, x2), ('<', x2, x3), ('<', x3, x4),
         ('is', x4, x5), ('is', x5, x6), ('is not', x6, x7), ('is not', x7, x8)]

    If `operators_to_group` is the set {'==', 'is'}, this function will produce
    the following "simplified operator list":

       [("==", [0, 1, 2]), ("<", [2, 3]), ("<", [3, 4]),
        ("is", [4, 5, 6]), ("is not", [6, 7]), ("is not", [7, 8])]

    Note that (a) we yield *indices* to the operands rather then the operand
    expressions themselves and that (b) operands used in a consecutive chain
    of '==' or 'is' are grouped together.

    If two of these chains happen to contain operands with the same underlying
    literal hash (e.g. are assignable and correspond to the same expression),
    we combine those chains together. For example, if we had:

        same == x < y == same

    ...and if 'operand_to_literal_hash' contained the same values for the indices
    0 and 3, we'd produce the following output:

        [("==", [0, 1, 2, 3]), ("<", [1, 2])]

    But if the 'operand_to_literal_hash' did *not* contain an entry, we'd instead
    default to returning:

        [("==", [0, 1]), ("<", [1, 2]), ("==", [2, 3])]

    This function is currently only used to assist with type-narrowing refinements
    and is extracted out to a helper function so we can unit test it.
    c                ,    i | ]}|t                      S r  )r\	  )r  r  s     r  r	  z-group_comparison_operands.<locals>.<dictcomp>"  s    0a0a0a\^^0a0a0ar  Nr~  c                    | d         d         S r  r  r  s    r  r?  z+group_comparison_operands.<locals>.<lambda>#  s    471: r  )r  )	ra  r  r1  r  rj	  r  r  r  sort)rt	  rv	  rx	  groupsr  last_operatorcurrent_indicescurrent_hashesr  r  	left_expr
right_expr	left_hash
right_hashdisjoint_dictr>  indicess                    r  r  r  "  sY   ` 1b0aN`0a0a0aF<> $M #O"uuN09:N0O0O / /,,Hi $M 		#M 9 9XM_=_=_ " S(//@W@W0XYYYY}%11./RRR$M!eeO UUN 	AAE""" )))/33A66I$""9---044QU;;J%"":...  	O$++]F?<S<S,TUUUU=!--noNNN $*<<>> I I-*0022 	I 	IMD'$++Xvg,GHHHH	I !!&=&=!>>>##r  c                    t          |           } | rt          | t                    sdS t          d t	          | j        | j        gz             D                        S )NFc              3  j   K   | ].}t          |t                    o|j        t          j        k    V  /d S r+  )r  r   r8  r   r9  r  s     r  r  z$is_typed_callable.<locals>.<genexpr>$#  sO         	1gI1=I4I#I     r  )r   r  r   r_  r   r  r  )r  s    r  r  r   #  ss    A Jq,// u  !!+"<==      r  c                t   t          |           } | sdS t          | t                    rt          |            S t          | t                    r| j                            d          }|rt          |t                    r2t          |j	        j                  pt          |j
        j                  S t          |j        t                    r#t          d |j        j        D                       S t          |j                   S dS t          | t                    rt          d | j        D                       S dS )NTr)  c              3  4   K   | ]}t          |          V  d S r+  r  r  s     r  r  z'is_untyped_decorator.<locals>.<genexpr>9#  s+      TT$/55TTTTTTr  Fc              3  4   K   | ]}t          |          V  d S r+  r	  r  s     r  r  z'is_untyped_decorator.<locals>.<genexpr>?#  s+      DD$'--DDDDDDr  )r   r  r   r  r   r  r2  rg   r  r  r  r   r@  r  )r*  r~  s     r  r  r  *#  s:   
#

C Et	C	&	& E$S))))	C	"	" E$$Z00 	&),, +FK,<== AUJOB B  &+z22 :TT&+BSTTTTTT,V[99995	C	$	$ EDD#)DDDDDD4r  FuncBase | Decoratorc                    t          | t                    rt          | j                  S t          | t                    r| j        S J dt          |                        )NFzUnexpected func type: )r  rg   r  r  ro   r  )r  s    r  r  r  C#  s[    $	"" ###	D(	#	# ~774::77777r  r   c                &   t          | t                    r| j        S t          | t                    r| j        j        S t          | t
                    r>| j        r7t          | j        d         t                    r| j        d         j        j        S dS Nr   F)r  rp   r  rg   r  r   r  r  s    r  r  r  K#  s    $    $	"" %y$$$)** 2: 	2*TZ]I>> 	2:a=%115r  TypeGuard[OverloadedFuncDef]c                    t          | t                    r>| j        r7t          | j        d         t                    r| j        d         j        j        S dS r	  )r  r   r  rg   r  r  r	  s    r  r   r   V#  sM    $)** 2: 	2*TZ]I>> 	2:a=%115r  c                   | dS t          |           sdS | j        d         }t          |t                    sJ |j        j         sdS |j        }|j        !|j        t          |j        t                    rdS |j        j        d         }t          t          |          t                    rdS t          t          t          |j                            |           S )zCheck if a node is a settable property with a non-trivial setter type.

    By non-trivial here we mean that it is known (i.e. definition was already type
    checked), it is not Any, and it is different from the property getter type.
    NFr   r~  )r   r  r  rg   r  r  r  r   r  r   r   r   get_property_type)r  r  r  r  s       r  r  r  ]#  s     |u%% uAJj),,,,,>. u
.C
x3?2j;6W6W2u/+A.K/+..88 u-och.G.GHH+VVVVr  r   c                    t          | t                    rt          | j                  S t          | t                    rt          | j        d         j                  S | S )Nr   )r  r   r   r  r   r  r:  s    r  r	  r	  u#  sR    !\"" +qz***!Z   4qwqz2333Hr  rt  ru  c                (    t          | |dd          S )NT)r  always_covariantr;  rs  s     r  r'	  r'	  }#  s    dETDQQQQr  c                *    t          | |ddd          S )NT)r  prohibit_none_typevar_overlapoverlap_for_overloads)r?   rs  s     r  r-	  r-	  #  s*      &*"   r  	node_namec                X    |                      d          o|                     d           S )z-Check if node is private to class definition.rz  )r+  endswith)r	  s    r  r  r  #  s,    %%Fi.@.@.F.F*FFr  c                N    t          |           }|d uot          |          dk    S )Nr~  )r   r  )r*  strss     r  r  r  #  s)    -c22Dt.D		Q.r  c                    t          | d          rdS t          | t                    rt          d | j        D                       S dS )z<Return True if type is 'bool' or a union with a 'bool' item.r  Tc              3  6   K   | ]}t          |d           V  dS )r  N)r   r  s     r  r  z has_bool_item.<locals>.<genexpr>#  s-      RR$T?;;RRRRRRr  F)r   r  r   r@  r  r  s    r  r  r  #  sP    o.. t#y!! SRR	RRRRRR5r  r^  c                >    t          | t                    r| j        S | S )zIf an expression is an AssignmentExpr, pull out the assignment target.

    We don't make any attempt to pull out all the targets in code like `x := (y := z)`.
    We could support narrowing those if that sort of code turns out to be common.
    )r  r]   r  )r^  s    r  r  r  #  s"     !^$$ xHr  r   r  r   rX  c                X    t          |          }|                     |           |j        S )zFind the highest line number of a potential assignment to variable within node.

    This supports local and global variables.

    Return -1 if no assignment was found.
    )VarAssignVisitorr  	last_line)r  r  r
	  s      r  r  r  #  s,     q!!GHHWr  c                  l     e Zd ZddZddZddZd fdZd fdZd dZd!dZ	d"dZ
d#dZd$dZ xZS )%r	  r  r   r(  r)  c                0    d| _         d| _        || _        d S )Nr  F)r	  r  var_node)r,  r  s     r  r-  zVarAssignVisitor.__init__#  s    r  r  r^   c                `    d| _         |j        D ]}|                    |            d| _         d S r  )r  r  r  r,  r  r  s      r  r  z&VarAssignVisitor.visit_assignment_stmt#  s6    ) 	 	BIIdOOOOr  r^  r   c                v    | j         r/|j        | j        u r#t          | j        |j                  | _        d S d S d S r+  )r  r  r	  r	  r	  r  r,  r^  s     r  visit_name_exprz VarAssignVisitor.visit_name_expr#  sC    ; 	916T]22 88DNNN	9 	922r  r~   c                t    | j         }d| _         t                                          |           || _         d S r:  )r  r	  r&  r,  r^  
old_lvaluer	  s      r  r&  z"VarAssignVisitor.visit_member_expr#  s4    [
!!!$$$ r  rx   c                t    | j         }d| _         t                                          |           || _         d S r:  )r  r	  visit_index_exprr	  s      r  r	  z!VarAssignVisitor.visit_index_expr#  s4    [
  ### r  r   c                    d| _         |j        D ]}||                    |            d| _         |j                            |            d S r  )r  r  r  r  r	  s      r  r  z VarAssignVisitor.visit_with_stmt#  sP    ( 	  	 B~		$	dr  rn   c                    d| _         |j                            |            d| _         |j                            |            |j        r|j                            |            d S d S r  )r  r  r  r  r  r  s     r  rf  zVarAssignVisitor.visit_for_stmt#  sh    	t	d; 	%Kt$$$$$	% 	%r  r]   c                    d| _         |j                            |            d| _         |j                            |            d S r  )r  r  r  r  r	  s     r  visit_assignment_exprz&VarAssignVisitor.visit_assignment_expr#  s>    		tr  r  r   c                    |j         |j                             |            |j        *d| _        |j                            |            d| _        d S d S r  )r  r  r  r  r,  r  s     r  visit_as_patternz!VarAssignVisitor.visit_as_pattern#  sV    9 IT"""6DKFMM$DKKK r  r   c                h    |j         *d| _        |j                             |            d| _        d S d S r  )capturer  r  r	  s     r  visit_starred_patternz&VarAssignVisitor.visit_starred_pattern#  s:    9 DKIT"""DKKK ! r  )r  r   r(  r)  r  )r^  r   r(  r)  )r^  r~   r(  r)  )r^  rx   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  rf  r	  r	  r	  r	  r	  s   @r  r	  r	  #  s           
   9 9 9 9! ! ! ! ! !! ! ! ! ! !   % % % %                         r  r	  r  c                B    t          t          |                     dk    S )ar  Do types have IntEnum/StrEnum types that are potentially overlapping with other types?

    If True, we shouldn't attempt type narrowing based on enum values, as it gets
    too ambiguous.

    For example, return True if there's an 'int' type together with an IntEnum literal.
    However, IntEnum together with a literal of the same IntEnum type is not ambiguous.
    r~  )r  _ambiguous_enum_variants)r  s    r  r  r  #  s      '..//!33r  c                   t                      }| D ]q}t          |          }t          |t                    r(|                    t          |j                             Ot          |t                    r|j        r)|                    t          |j        g                     |j	        j
        rCt          d |j	        j        D                       r |                    |j	        j                   |j	        j
        s|                    d           t          |t                    r*|                    t          |j        g                     Et          |t"                    r\|                    d           s|S )Nc              3  (   K   | ]}|j         d v V  dS ))zenum.IntEnumzenum.StrEnumN)r  r  s     r  r  z+_ambiguous_enum_variants.<locals>.<genexpr>$  s;       ( (FJ!AA( ( ( ( ( (r  z<other>)ra  r   r  r   r  r	  r  r   last_known_valuer  r  r@  r  r  r  r   r  r   )r  r  r  s      r  r	  r	  $  sv   UUF " "Aa## 	"MM217;;<<<<8$$ 	"! 	&68J7KLLMMMM &C ( (NOfj( ( ( % % & 

16?++++V^ & 

9%%%;'' 	"MM2AJ<@@AAAA8$$ 	"JJy!!!!Mr  r  c                R    | dS t          |           }t          |t                    S r:  )r   r  r   )r  lvalue_propers     r  r  r  )$  s*    u#K00Mm]333r  c                    t          | t                    r| j         S t          | t                    r| j        j         S t          | t
                    S r+  )r  r   r  rg   r  rp   rW	  s    r  r  r  0$  sQ    $)** $###$	"" (8'''dG$$$r  r+  )
r9  r   r  r  r&  r)  r  r!  r(  r?  )
r9  r   r  r  r&  r   r  r!  r(  rg  )
r9  r   r  r  r&  r%  r  r!  r(  r?  )r  rk   r  r%  r  r%  r(  r:  )r  r\  r\  r   r(  r\  r  )r  rq   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  rk   r(  r0  )r  r   r(  rG  )r  rq   r   r	  r(  rq   )r  r   r  r   r(  r!  )r  r   r(  r	  r  )
r  r   r  r   r"	  r#	  rr  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   rQ  r   r  r!  r  r!  r(  r!  )r  rU	  r(  r  )rt	  ru	  rv	  rw	  rx	  rT  r(  ry	  )r  r%  r(  r!  )r*  r%  r(  r!  )r  r	  r(  r!  )r  r   r(  r!  )r  rU	  r(  r	  )r  rU	  r(  r!  )r  r   r(  r   )rt  r   ru  r   r(  r!  )r	  r\  r(  r!  r  )r*  r   r(  r!  )r^  rk   r(  rk   )r  r   r  r   r(  rX  )r  rG  r(  r!  )r  rG  r(  rT  )r  r%  r(  r!  )r  rU	  r(  r!  (z  r=  
__future__r   r  collectionsr   collections.abcr   r   r   r   r	   AbstractSet
contextlibr
   r   rT  r   r   r   r   r   r   r   r   r   r   typing_extensionsr   r
  r   mypy.checkexprrn  r   r  r   r   r   r   mypy.binderr   r   r   mypy.checker_sharedr    r!   r"   mypy.checker_stater#   mypy.checkmemberr$   r%   r&   r'   r(   mypy.checkpatternr)   mypy.constraintsr*   mypy.erasetyper+   r,   r-   mypy.errorcodesr.   r/   r0   r1   mypy.errorsr2   r3   r4   r5   r6   r7   mypy.expandtyper8   mypy.literalsr9   r:   r;   r<   mypy.maptyper=   	mypy.meetr>   r?   r@   mypy.message_registryrA   mypy.messagesrB   rC   rD   rE   rF   rG   rH   rI   rJ   mypy.mrorK   rL   
mypy.nodesrM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   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.operatorsr   r   r   mypy.optionsr   r   mypy.patternsr   r   mypy.pluginr   mypy.pluginsr   r  
mypy.scoper   mypy.semanalr   r   r   mypy.semanal_enumr   r   mypy.sharedparser   
mypy.stater   mypy.subtypesr   r   r   r   r   r   r   r   r   r   mypy.traverserr   r   r   mypy.treetransformr   mypy.typeanalr   r   r   mypy.typeopsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
mypy.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mypy.types_utilsr   r   r   r   mypy.typetraverserr   mypy.typevarsr   r   r  	mypy.utilr  r  mypy.visitorr  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		  rH  r!	  rM  r,	  rI  r|  r6	  r'  r=	  r  rD	  r  r  r  rY	  rZ	  r\	  r  r  r  r  r  r   r  r	  r'	  r-	  r  r  r  r  r  r	  r  r	  r  r  r  r  r  <module>r	     sh      " " " " " "     # # # # # # U U U U U U U U U U U U U U 0 0 0 0 0 0 0 0                        A @ @ @ @ @ @ @     N N N N N N N N N N N N N N E E E E E E E E E E M M M M M M M M M M , , , , , ,              - , , , , , ) ) ) ) ) ) X X X X X X X X X X S S S S S S S S S S S S                ( ' ' ' ' ' S S S S S S S S S S S S 2 2 2 2 2 2 S S S S S S S S S S . . . . . .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 - , , , , , , ,T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T Tj ? > > > > > > > > > 5 5 5 5 5 5 5 5 3 3 3 3 3 3 3 3       : : : : : :       O O O O O O O O O O < < < < < < < < 1 1 1 1 1 1                              Y X X X X X X X X X / / / / / / b b b b b b b b b b                                           ,& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &N c b b b b b b b b b b b 3 3 3 3 3 3 P P P P P P P P P P * * * * * * * * $ $ $ $ $ $GCLL      !"  ! ! ! !$W.?%JK  K K K K*/CT0T*U  U U U U% % % % %: % % %% % % % %j % % %$ tJ$456 6 6 6 6    z          (Nz Nz Nz Nz Nz+d#%9 Nz Nz Nzbt    1    
 *
 )-* * * * * 
* 
 )-     
  7%
 )-7% 7% 7% 7% 7% 7%t6 6 6 6$   ] ] ] ]
^ ^ ^ ^
E E E E
O O O O    6 6 6 6r    <    6 @E$, $, $, $, $,N             + + + + ++ + + +          B 	L L L L L^
N 
N 
N 
N   .   $	 	 	 	   &    Z_2 2 2 2 26) ) ) ) )= ) ) )6F F F F Fn F F F       wv			\ \ \ \ \74<( \ \ \~a$ a$ a$ a$H      28 8 8 8      W W W W0   R R R R   "G G G G
/ / / /
      	 	 	 	>  >  >  >  > ' >  >  > B4 4 4 4$   44 4 4 4% % % % % %r  