
    %^g*                      U d Z ddlmZ ddlmZmZmZmZmZ ddl	Z
ddlZ
ddlmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZ 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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? dd
l@mAZA ddlBmCZC erddlDmEZE dZFdeGd<   dZHdeGd<    G d d      ZI	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/dZJ	 d0	 	 	 	 	 	 	 	 	 d1dZK	 	 	 	 	 	 	 	 	 	 d1dZL	 	 	 	 	 	 	 	 d2dZMd3dZNd4dZOd5dZPd6dZQd7dZRd8dZSd9dZTd8dZUd8dZVd:d ZWd;d!ZX G d" d#e/eY         ZZ G d$ d%e5eeI            Z[d<d&Z\d=d'Z]	 	 	 	 	 	 d>d(Z^d?d)Z_d@d*Z`	 	 	 	 	 	 	 	 dAd+ZadBd,Zb	 	 	 	 	 	 	 	 dCd-ZcdDd.Zdy)EzType inference constraints.    )annotations)TYPE_CHECKINGFinalIterableListSequenceN)ArgTypeExpander)erase_typevars)map_instance_to_supertype)ARG_OPTARG_POSARG_STAR	ARG_STAR2CONTRAVARIANT	COVARIANTArgKindTypeInfo)$TUPLE_LIKE_INSTANCE_NAMESAnyTypeCallableTypeDeletedType
ErasedTypeInstanceLiteralTypeNoneTypeNormalizedCallableType
Overloaded
ParametersParamSpecTypePartialType
ProperType	TupleTypeTypeTypeAliasTypeTypedDictType	TypeOfAny	TypeQueryTypeType	TypeVarIdTypeVarLikeTypeTypeVarTupleTypeTypeVarTypeTypeVisitorUnboundTypeUninhabitedType	UnionType
UnpackTypefind_unpack_in_listget_proper_typehas_recursive_typeshas_type_varsis_named_instancesplit_with_prefix_and_suffix)is_union_with_any)
type_state)ArgumentInferContextr   
SUBTYPE_OF   SUPERTYPE_OFc                  J    e Zd ZU dZded<   dZded<   ddZddZdd	Zdd
Z	y)
ConstraintzpA representation of a type constraint.

    It can be either T <: type or T :> type (T is a type variable).
    r)   type_varr   r#   targetc                ^    |j                   | _        || _        || _        || _        g | _        y N)idr@   oprA   origin_type_varextra_tvars)selfr@   rE   rA   s       0lib/python3.12/site-packages/mypy/constraints.py__init__zConstraint.__init__P   s/      ' 35    c                l    d}| j                   t        k(  rd}| j                   d| d| j                   S )Nz<:z:> )rE   r=   r@   rA   )rH   op_strs     rI   __repr__zConstraint.__repr__\   s7    77l"F--&4;;-88rK   c                Z    t        | j                  | j                  | j                  f      S rC   )hashr@   rE   rA   )rH   s    rI   __hash__zConstraint.__hash__b   s     T]]DGGT[[9::rK   c                    t        |t              sy| j                  | j                  | j                  f|j                  |j                  |j                  fk(  S NF)
isinstancer?   r@   rE   rA   )rH   others     rI   __eq__zConstraint.__eq__e   sC    %,tww4SXS_S_8```rK   N)r@   r*   rE   intrA   r#   returnNone)rY   str)rY   rX   )rV   objectrY   bool)
__name__
__module____qualname____doc____annotations__rE   rJ   rO   rR   rW    rK   rI   r?   r?   F   s.    
 	
BL
59;arK   r?   c                ~	   g }t        |      }| j                         g }g }	g }
d}t        |      D ].  \  }}|D ]$  }|| j                  |   t        t
        fv s"d} . 0 t        |      D ]  \  }}t        | j                  |   t              r| j                  |   }t        |t              sJ g }t        |j                        }t        |t              r|j                  }n$t        |t              r|j                  }nJ d       |D ]  }||   }||j                  |||   | j                   |   | j                  |   d      }||   t        k7  st        t        |      t              r|j#                  |       u|j#                  t        |j%                  |g                    t        |t              r6|j#                  t'        |t(        t        ||j                                     t        |t              rE|j*                  d   }t        |t              sJ t        |j                        }t-        |j*                        dz
  }t        |t              r9|j#                  t'        |t(        t        |d|  |j                                     nct        |t.              r|j                  j0                  d	k(  sJ |d|  D ]/  }|j3                  t5        |j6                  d   |t(                     1 |st9        |j*                  dd || d       D ]%  \  }}|j3                  t5        ||t(                     ' J d       |D ]  }||   }|r| j                  |   t        t
        fv ro|r+|j#                  |j                  |||   d||                ||   }|
j#                  |t        t
        fvrt:        n|       |	j#                  |r||   nd       |j                  |||   | j                   |   | j                  |         }t5        | j                  |   |t(              }|j3                  |         rCt=        fd
|D              s/|s-|j#                  t'        t(        t?        ||
|	d                   t=        d | j@                  D              rtC        |      }|S )zlInfer type variable constraints for a callable and actual arguments.

    Return a list of constraints.
    FNTz-mypy bug: unhandled constraint inference case)allow_unpack)argsr   r<   builtins.tuplec              3  P   K   | ]  }|j                   j                  k(    y wrC   )r@   rD   ).0c
param_specs     rI   	<genexpr>z1infer_constraints_for_callable.<locals>.<genexpr>   s     EAAJJ*--/s   #&	arg_types	arg_kinds	arg_namesimprecise_arg_kindsc              3  <   K   | ]  }t        |t                y wrC   )rU   r   )ri   vs     rI   rl   z1infer_constraints_for_callable.<locals>.<genexpr>  s     
B1AA:a'1A   )"r	   rk   	enumeratero   r   r   rU   rn   r1   r3   typer+   tuple_fallbackr"   partial_fallbackexpand_actual_typerp   appendcopy_modifiedr?   r=   itemslenr   fullnameextendinfer_constraintsrf   zipr   anyr   	variablesfilter_imprecise_kinds)calleern   ro   rp   formal_to_actualcontextconstraintsmapperparam_spec_arg_typesparam_spec_arg_namesparam_spec_arg_kindsincomplete_star_mappingiactualsactualunpack_typeactual_typesunpacked_typetuple_instanceactual_arg_typeexpanded_actualinner_unpackinner_unpacked_type
suffix_lenatttactual_kindactual_typerj   rk   s                                @rI   infer_constraints_for_callabler   k   s    %'KW%F""$J# 01
7F~&"2"21"5(I9N"N +/'  2   01
7f&&q):6 **1-Kk:666
 L+K,<,<=M-)9:!.!=!=M95!.!?!?MMMu!"+F"3"*"(";";#f%$$Q'$$Q'!% #< # V$0J#O4i5 !''8 !''">#?#?oEV#?#WX' ". -)9:""%$!,0L0LM M95  -2215!,
;;;&5l6G6G&H# !4!459
13CD&&"/(% ,\zk :<O<^<^ ##6A/44==AQQR +<ZK8#**-.A.F.Fq.I2|\ 9
 "%m&9&9!"&=|ZKL?Y"ZB#**+<R\+RS #[ NMMu!"+F"3"*&"2"21"5(I9N"N
 3,33"55 /61BD)TZJ[
 '0&7,33'28Y:O'OGU` -33If4EX\]"(";";'!&)((+((+	#K *&*:*:1*={LYA&&q); "k 2h 	EEE' 	222(,			
 
B1A1A
BB,[9rK   c                ~    t         fdt        t        j                        D              rg S t	               st        t               t              r\t               sg S t        j                  j                   f       t         ||      }t        j                  j                          |S t         ||      S )a  Infer type constraints.

    Match a template type, which may contain type variable references,
    recursively against a type which does not contain (the same) type
    variable references. The result is a list of type constrains of
    form 'T is a supertype/subtype of x', where T is a type variable
    present in the template and x is a type without reference to type
    variables present in the template.

    Assume T and S are type variables. Now the following results can be
    calculated (read as '(template, actual) --> result'):

      (T, X)            -->  T :> X
      (X[T], X[Y])      -->  T <: Y and T :> Y
      ((T, T), (X, Y))  -->  T :> X and T :> Y
      ((T, S), (X, Y))  -->  T :> X and S :> Y
      (X[T], Any)       -->  T <: Any and T :> Any

    The constraints are represented as Constraint objects. If skip_neg_op == True,
    then skip adding reverse (polymorphic) constraints (since this is already a call
    to infer such constraints).
    c              3     K   | ]7  \  }}t              t        |      k(  xr t              t        |      k(   9 y wrC   )r3   )ri   tar   templates      rI   rl   z$infer_constraints.<locals>.<genexpr>-  sJ       5FQ 	!_Q%77 	:F#q'99	:4s   =A )r   reversedr9   	inferringr4   rU   r3   r   r5   rz   _infer_constraintspop)r   r   	directionskip_neg_opress   ``   rI   r   r     s    2   z334 
 	8$
?83Lh(W X&I##Xv$67 69kJ  "
h	;GGrK   c           
        | }t        |       } t        |      }t        | t              r+t        j                  j                  | j                  d      } t        |t              r+t        j                  j                  |j                  d      }t        |t              r|j                  t        j                  k(  rg S t        | t              rt        | ||      gS t        |t              rd|j                  j                         sJ|t        k(  rAt        | t              rt!        d | j                  D              st        |j"                        }|t$        k(  rAt        | t              r1g }| j                  D ]  }|j'                  t)        |||               |S |t        k(  rAt        |t              r1g }|j                  D ]  }|j'                  t)        |||               |S |t$        k(  rKt        |t              r;t+        |j                        }t-        |D cg c]  }t/        | ||       c}d      S |t        k(  rit        | t              rYt-        | j                  D cg c]  }t/        |||       c}d      }	|	r|	S t1        |       rt1        |      st3        | ||      S g S | j5                  t7        |||            S c c}w c c}w )NT)keep_erasedc              3  <   K   | ]  }t        |t                y wrC   )rU   r,   )ri   r   s     rI   rl   z%_infer_constraints.<locals>.<genexpr>g  s      :
0>1Jq+&rt   eagerF)r3   rU   r0   mypytypeopsmake_simplified_unionr|   r   type_of_anyr&   suggestion_enginer,   r?   rD   is_meta_varr=   r   upper_boundr;   r   r   simplify_away_incomplete_typesany_constraintsinfer_constraints_if_possibler4   handle_recursive_unionacceptConstraintBuilderVisitor)
r   r   r   r   orig_templater   t_itema_itemr|   results
             rI   r   r   @  s}    Mx(HV$F
 (I&<<55hnnRV5W&)$33FLLd3S &'"v'9'9Y=X=X'X	 (K(8Y788 	6;'		%%'% (I.c :
08:
 7
 %V%7%78F
 J:h	#BnnFJJ(CD %
L Z	%BllFJJ(	JK #
 J:fi#@.v||< V[\V[F*8VYGV[\
 	
 L Z)%D ! 'nn,F .ffiH, 
 M *3Fv3N)(FIFF	 ??3FI{STT+ ]s   K$Kc                   |t         k(  r*t        j                  j                  t	        |       |      sy|t
        k(  r*t        j                  j                  |t	        |             sy|t
        k(  rDt        | t              r4t        j                  j                  |t	        | j                              syt        | ||      S )a2  Like infer_constraints, but return None if the input relation is
    known to be unsatisfiable, for example if template=List[T] and actual=int.
    (In this case infer_constraints would return [], just like it would for
    an automatically satisfied relation like template=List[T] and actual=object.)
    N)
r;   r   subtypes
is_subtyper
   r=   rU   r,   r   r   )r   r   r   s      rI   r   r     s     Jt}}'?'?x@XZ`'aL )A)Ax(* \!x-((@T@T1UV Xvy99rK   c                f    g }| D ])  }|t        d |D              s|j                  |       + |S )zDSelect only those lists where each item is a constraint against Any.c              3  b   K   | ]'  }t        t        |j                        t               ) y wrC   )rU   r3   rA   r   )ri   rj   s     rI   rl   z!select_trivial.<locals>.<genexpr>  s!     Nv!z/!((3W=vs   -/)allrz   )optionsr   options      rI   select_trivialr     s:    
C>NvNNJJv	 
 JrK   c           	         | j                   }t        |      r| S t        t        j                        }t        | j                  | j                  t        j                  ||g|j                  |j                              S )z?Transform a constraint target into a union with given Any type.)rA   r8   r   r&   implementation_artifactr?   rF   rE   r0   
make_unionlinecolumn)
constraintrA   any_types      rI   merge_with_anyr     sg    F y889H""fh/fmmL rK   c                B   | j                   D cg c]  }t        |t              r| }}| j                   D cg c]  }t        |t              s| }}t        t	        j
                  |      ||      xs  t        t	        j
                  |      ||      S c c}w c c}w rC   )r|   rU   r,   r   r0   r   )r   r   r   r   non_type_var_itemstype_var_itemss         rI   r   r     s     &.^^V^:a;U!^V!)NA:a3MaNN/0&) T	9//?	ST WNs   BBBBc                T  	 |r| D cg c]  }|s|	 c}	n| D cg c]  }||	 c}		sg S t        	      dk(  r	d   S t        	fd	dd D              r	d   S t        	fd	dd D              rut        	      }|rht        |      t        	      k  rQg }	D ]5  }||v r||D cg c]  }t        |       }}nd}|j	                  |       7 t        t        |      |      S | D cg c]  }t        |       }}|| k7  rt        ||      S g S c c}w c c}w c c}w c c}w )aE  Deduce what we can from a collection of constraint lists.

    It's a given that at least one of the lists must be satisfied. A
    None element in the list of options represents an unsatisfiable
    constraint and is ignored.  Ignore empty constraint lists if eager
    is true -- they are always trivially satisfiable.
    Nr<   r   c              3  <   K   | ]  }t        d    |        ywr   N)is_same_constraintsri   rj   valid_optionss     rI   rl   z"any_constraints.<locals>.<genexpr>  s!     
O=N}Q/3=N   c              3  <   K   | ]  }t        d    |        ywr   )is_similar_constraintsr   s     rI   rl   z"any_constraints.<locals>.<genexpr>  s!     
R@Q1!-"2A6@Qr   r   )r}   r   r   r   rz   r   listfilter_satisfiable)
r   r   r   trivial_optionsmerged_optionsrj   merged_optionofiltered_optionsr   s
            @rI   r   r     s_    .5@gFg@.5LgF9KgL	
=QQ

O]12=N
OOQ

Rab@Q
RR
 )7s?3c-6HHN'_,%Y_=`Y_TUnQ>OY_M=`$(M%%m4 ( #4#7?? 8??w!*1-w?7"/u== IQ AL0 >a @s    DDDD+D .D%c                   | s| S g }| D ]  t        j                  t              rQj                  j                  r;t	        fdj                  j                  D              s\|j                         nt        j                  j                  j                  j                  j                        s|j                          |sy|S )a  Keep only constraints that can possibly be satisfied.

    Currently, we filter out constraints where target is not a subtype of the upper bound.
    Since those can be never satisfied. We may add more cases in future if it improves type
    inference.
    c              3  r   K   | ].  }t         j                  j                  j                  |       0 y wrC   )r   r   r   rA   )ri   valuerj   s     rI   rl   z%filter_satisfiable.<locals>.<genexpr>  s+      G_e((59G_s   47N)rU   rF   r,   valuesr   rz   r   r   r   rA   r   )r   satisfiablerj   s     @rI   r   r     s     Ka''5!:K:K:R:R GHGXGXG_G_  ""1%]]%%ahh0A0A0M0MNq!  rK   c                z    | D ]  t        fd|D              r y |D ]  t        fd| D              r y y)Nc              3  6   K   | ]  }t        |        y wrC   is_same_constraintri   c2c1s     rI   rl   z&is_same_constraints.<locals>.<genexpr>*       :"%b"-   Fc              3  6   K   | ]  }t        |        y wrC   r   r   s     rI   rl   z&is_same_constraints.<locals>.<genexpr>-  r   r   T)r   )xyr   s     @rI   r   r   (  s@    :::  :::  rK   c                n   t        t        | j                        t              xr# t        t        |j                        t              }| j                  |j                  k(  xrS | j
                  |j
                  k(  xs |xr4 t        j                  j                  | j                  |j                        S rC   )	rU   r3   rA   r   r@   rE   r   r   is_same_type)r   r   skip_op_checks      rI   r   r   2  s    ryy97C 
		"GIM 	r{{" 	=UUbee^,}	=MM&&ryy"))<rK   c                6    t        | |      xr t        ||       S )a  Check that two lists of constraints have similar structure.

    This means that each list has same type variable plus direction pairs (i.e we
    ignore the target). Except for constraints where target is Any type, there
    we ignore direction as well.
    )_is_similar_constraints)r   r   s     rI   r   r   >  s     #1a(J-DQ-JJrK   c                .   | D ]  }d}|D ]  }t        t        |j                        t              xs# t        t        |j                        t              }|j                  |j                  k(  se|j
                  |j
                  k(  s|sd} n |r y y)zCheck that every constraint in the first list has a similar one in the second.

    See docstring above for definition of similarity.
    FT)rU   r3   rA   r   r@   rE   )r   r   r   has_similarr   r   s         rI   r   r   H  s    
 B&ryy'A7K z		*GPM {{bkk)ruu~"    rK   c                `    | D cg c]  }t        |      s| }}|r|S t        |       S c c}w rC   )is_complete_typer   )typestypcompletes      rI   r   r   \  s5    $>u(8(=uH>E{	 ?s   ++c                4    | j                  t                     S )zIs a type complete?

    A complete doesn't have uninhabited type components or (when not in strict
    optional mode) None components.
    )r   CompleteTypeVisitor)r   s    rI   r   r   d  s     ::)+,,rK   c                  (     e Zd Zd fdZddZ xZS )r  c                ,    t         |   t               y rC   )superrJ   r   )rH   	__class__s    rI   rJ   zCompleteTypeVisitor.__init__n  s    rK   c                     yrT   rc   )rH   r   s     rI   visit_uninhabited_typez*CompleteTypeVisitor.visit_uninhabited_typeq  s    rK   )rY   rZ   )r   r/   rY   r]   )r^   r_   r`   rJ   r	  __classcell__)r  s   @rI   r  r  m  s    rK   r  c                  
   e Zd ZU dZde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.dZd/dZ	 	 	 	 	 	 d0dZd1dZd2dZd3dZd4dZd5dZd6dZd7dZy)8r   z-Visitor class for inferring type constraints.r!   r   c                .    || _         || _        || _        y rC   )r   r   r   )rH   r   r   r   s       rI   rJ   z!ConstraintBuilderVisitor.__init__|  s    " 'rK   c                    g S rC   rc   rH   r   s     rI   visit_unbound_typez+ConstraintBuilderVisitor.visit_unbound_type      	rK   c                    g S rC   rc   r  s     rI   	visit_anyz"ConstraintBuilderVisitor.visit_any  r  rK   c                    g S rC   rc   r  s     rI   visit_none_typez(ConstraintBuilderVisitor.visit_none_type  r  rK   c                    g S rC   rc   r  s     rI   r	  z/ConstraintBuilderVisitor.visit_uninhabited_type  r  rK   c                    g S rC   rc   r  s     rI   visit_erased_typez*ConstraintBuilderVisitor.visit_erased_type  r  rK   c                    g S rC   rc   r  s     rI   visit_deleted_typez+ConstraintBuilderVisitor.visit_deleted_type  r  rK   c                    g S rC   rc   r  s     rI   visit_literal_typez+ConstraintBuilderVisitor.visit_literal_type  r  rK   c                    J d       )NzInternal errorrc   r  s     rI   visit_partial_typez+ConstraintBuilderVisitor.visit_partial_type  s    &&&urK   c                    J d       )NzbUnexpected TypeVarType in ConstraintBuilderVisitor (should have been handled in infer_constraints)rc   r  s     rI   visit_type_varz'ConstraintBuilderVisitor.visit_type_var      	
?	
urK   c                    g S rC   rc   r  s     rI   visit_param_specz)ConstraintBuilderVisitor.visit_param_spec  s    	rK   c                    t         rC   )NotImplementedErrorr  s     rI   visit_type_var_tuplez-ConstraintBuilderVisitor.visit_type_var_tuple  s    !!rK   c                    t        d      )Nz5Mypy bug: unpack should be handled at a higher level.)RuntimeErrorr  s     rI   visit_unpack_typez*ConstraintBuilderVisitor.visit_unpack_type  s    RSSrK   c                   t        | j                  t              r&| j                  |j                  | j                        S t
        j                  r;t        | j                  t              r!t        || j                  | j                        S t
        j                  rEt        | j                  t              r+t        || j                  j                  | j                        S g S rC   )rU   r   r   infer_against_anyrn   r9   infer_polymorphicr   $infer_callable_arguments_constraintsr   r   prefixr  s     rI   visit_parametersz)ConstraintBuilderVisitor.visit_parameters  s    dkk7+))(*<*<dkkJJ''Jt{{J,O 8$++t~~^^''Jt{{M,R7$++,,dnn  	rK   c                !  & | j                   x}}g }t        |t        t        f      rj                  j
                  rdj                  j                  v rt        fdj                  j                  D              sj                  j                  j                         t        j                  j                  d|d      }|J t        j                  j                  |t        |            r(t        ||| j                         }|j#                  |       j                  j                  j%                          t        |t              r|j&                  |j)                         rj                  j
                  rt+        |j,                        }t        |t.              rt        j0                  j3                  |      }t        |t4              r=| j                   t6        k(  r}n|}|j#                  | j9                  ||d             |j&                  }t        |t:              r#j                  j
                  rt        |j<                  t4              rQ| j                   t6        k(  r}n|j<                  }|j#                  | j9                  |j<                  |d             | j                   t>        k(  r|j<                  }	t        |	t@              rt+        |	jB                        }	t        |	t4              rM|	j                  jD                  r7|j#                  | j9                  |	j                  jD                  |             t        |t              r|j&                  |j&                  }t        |tF              r|jI                         j&                  }t        |tJ              r|j&                  }t        |t4              
r|&t              }
t        |
t4              sJ | j                   t6        k(  rbj                  jM                  &j                  jN                        r2tQ        &j                        }|j                  jR                  jT                  }&j                  jV                  r&j                  jX                  J &j                  jZ                  J &j                  jX                  }&j                  jZ                  }&j                  jR                  jT                  |   }t        |t\              sJ |j2                  }t_        &j`                  ||      \  }}}t_        |j`                  ||      \  }}}|t/        tc        |      |      fz   |z   }|t/        tc        |      |      fz   |z   }n|j`                  }&j`                  }te        |||      D ]  \  }}}t        |t@              r}|jf                  th        k7  r&|j#                  t        ||| j                                |jf                  tj        k7  se|j#                  t        ||tm        | j                                      t        |tn              rt        |tn              r|jp                  }t        |tr              r|ju                  |jv                  ty        |jv                        d  |jz                  ty        |jz                        d  |j|                  ty        |j|                        d        }|j                  t        |t6        |             |j                  t        |t>        |             t        |tn              s|ju                  ts        |jp                  jv                  ty        |jv                        d  |jp                  jz                  ty        |jz                        d  |jp                  j|                  ty        |j|                        d              }|j                  t        |t6        |             |j                  t        |t>        |             wt        |t\              s|j#                  t        ||| j                                 |S | j                   t>        k(  r|&j                  jM                  j                  jN                        rLtQ        &j                        }j                  jR                  jT                  }j                  jV                  rj                  jX                  J j                  jZ                  J j                  jX                  }j                  jZ                  }j                  jR                  jT                  |   }t        |t\              sJ |j2                  }t_        j`                  ||      \  }}} t_        |j`                  ||      \  }}}|t/        tc        |      |      fz   | z   }!|t/        tc        |      |      fz   |z   }n|j`                  }j`                  }!te        |||!      D ]  \  }}}"t        |t@              r}|jf                  th        k7  r&|j#                  t        |"|| j                                |jf                  tj        k7  se|j#                  t        |"|tm        | j                                      t        |tn              rt        |"tn              r|"jp                  }t        |tr              r|ju                  |jv                  ty        |jv                        d  |jz                  ty        |jz                        d  |j|                  ty        |j|                        d        }|j                  t        |"t6        |             |j                  t        |"t>        |             t        |tn              s|ju                  ts        |jp                  jv                  ty        |jv                        d  |jp                  jz                  ty        |jz                        d  |jp                  j|                  ty        |j|                        d              }|j                  t        |"t6        |             |j                  t        |"t>        |             wt        |t\              s|j#                  t        |"|t6                     |j#                  t        |"|t>                      |S j                  j
                  r| j                   t>        k(  rt        fdt        j                  j                        D              st        j                  j                  &|
dg      rnj                  j                  j                         |j#                  | j9                  &|             j                  j                  j%                          |S &j                  j
                  r| j                   t6        k(  rt        &fd	t        &j                  j                        D              st        j                  j                  |
&dg      rn&j                  j                  j                  &       |j#                  | j9                  &&             &j                  j                  j%                          |S |r|S t        |t              r| j                  j`                  |      S t        |t.              rt        t              r| j                   t>        k(  r|j                  D ]  }#t        |#t              r`t+        |#j                        }$t        |$t\              r9t        |$t4              r|$j                  jN                  d
k(  sJ |$j`                  d   }#t        j`                  d   |#t>              }%|j#                  |%        |S t        |t.              rG| j                   t>        k(  r4t        t        j0                  j3                  |      | j                         S t        |t@              rI|j                  s;|j                  j                         s!t        |jB                  | j                         S g S t        |tn              r!t        |jB                  | j                         S t        |t\              rt        g S )N__call__c              3  (   K   | ]	  }|k(    y wrC   rc   ri   r   r   s     rI   rl   z:ConstraintBuilderVisitor.visit_instance.<locals>.<genexpr>  s     J2IQ8q=2I   Tis_operator	class_objr-  c              3  (   K   | ]	  }|k(    y wrC   rc   r2  s     rI   rl   z:ConstraintBuilderVisitor.visit_instance.<locals>.<genexpr>       Q/P!A/Pr3  )skipc              3  (   K   | ]	  }|k(    y wrC   rc   )ri   r   instances     rI   rl   z:ConstraintBuilderVisitor.visit_instance.<locals>.<genexpr>  r:  r3  rg   r   )Lr   rU   r   r   rv   is_protocolprotocol_membersr   r   rz   r   r   find_memberr   r
   r   r   r   r   fallbackis_type_objr3   ret_typer"   r   rw   r   r;   'infer_constraints_from_protocol_membersr(   itemr=   r,   r   metaclass_typer%   as_anonymousr   has_baser~   r   defn	type_varshas_type_var_tuple_typetype_var_tuple_prefixtype_var_tuple_suffixr+   r7   rf   r   r   variancer   r   neg_opr   r-  r   r{   rn   r}   ro   rp   r?   r   is_protocol_implementationr   r*  r6   r   r|   r1   r   rD   r   r$  )'rH   r   original_actualr   r   callsubresrC  subtyper   erasedmappedtvars
prefix_lenr   tvtrA  i_prefixi_middlei_suffixm_prefixm_middlem_suffixinstance_argsmapped_argstvar
mapped_arginstance_argr-  suffixt_prefixt_middlet_suffixtemplate_argstemplate_argrE  unpackedcbr=  s'    `                                    @rI   visit_instancez'ConstraintBuilderVisitor.visit_instance  s   #';;.& "f|Z89hmm>W>WX]];;;J(--2I2IJJMM++228<==44"Hf$ 5 D  +++}}//t8LM!24!P

6*MM++//1fl+0K!!#(A(A*6??;h	2#||::8DHh1~~3"*"*JJDD$hT E 
 __Ffh'HMM,E,E&++x0>>Z/&G$kkG

@@XwD A 
 ~~-fk2,V-?-?@Ffh/FKK4N4NJJDD"KK66&( fj)foo.I__Ffm,((*33Ffk*__Ffh'H#H-Ffh/// ~~+0F0Fx}}G]G]0^28X]]K((22==88 $==>>JJJ#==>>JJJ!)!D!DJ!)!D!DJ"--,,66zBC%c+;<<<"11H3O z:40Hh 4PZ40Hh %-	$x.(0S/U$UX`$`M"*iX.Q-S"SV^"^K"(++K$,MMM 7:%m6\2D*l!$4  ==M9JJ'8\SWSaSa'bc==I5JJ 1*lFSWSaSaLb c $D-8Z
Ta=b!+!2!2%lJ? ,8+E+E , 6 6s6;K;K7L7N O , 6 6s6;K;K7L7N O , 6 6s6;K;K7L7N O,F
  JJz*j&'QRJJz*lF'ST'mD%1%?%?'1$0$7$7$A$A#fFVFVBWBY$Z$0$7$7$A$A#fFVFVBWBY$Z$0$7$7$A$A#fFVFVBWBY$Z(" &@ &F  JJz*j&'QRJJz*lF'ST#D*:;

#4Zt~~#^_G 7]J 
</HMM4J4J8==KaKa4b28X]]K **44==88 $==>>JJJ#==>>JJJ!)!D!DJ!)!D!DJ"--,,66zBC%c+;<<<"11H3O z:40Hh 4PZ40Hh %-	$x.(0S/U$UX`$`M"*iX.Q-S"SV^"^K"(++K$,MMM 7:%m6\2D*l!$4  ==M9JJ'8zSWSaSa'bc==I5JJ 1,
FSWSaSaLb c $D-8Z$m> ".!4!4%j*= &0%=%= * 4 4S9I9I5J5L M * 4 4S9I9I5J5L M * 4 4S9I9I5J5L M&F
  JJz,
F'STJJz,f'UV'
MB%/%=%='1$.$5$5$?$?FDTDT@U@W$X$.$5$5$?$?FDTDT@U@W$X$.$5$5$?$?FDTDT@U@W$X(" &> &F  JJz,
F'STJJz,f'UV#D*:;

#4\:z#Z[

#4\:|#\]M 7]N 
))NNl2 Qx8O8O/PQQMM<<XvU_T`<a''..x8

@@ (OX
 ''++-
))NNj0 Qx8O8O/PQQMM<<VXU_T`<a''..x8

@@ (Hh
 ''++-
Jfg&))(--@@vy)!(,EF,.dJ/.tyy9H!(,<= "8X6$MM226FFG $==+D&x}}Q'7|L

2 % J	*t~~/M$Xt||/J/J6/RTXTbTbcc,==)>)>)@(63E3Et~~VVI.$Xv/A/A4>>RR 01%%IrK   c           
        g }|j                   j                  D ]  }t        j                  j	                  ||||      }t        j                  j	                  |||      }	||	
|dk(  rQg c S |j                  t        |	|| j                               t        j                  j                  t        j                  j                  ||      v s|j                  t        |	|t        | j                                      |S )a]  Infer constraints for situations where either 'template' or 'instance' is a protocol.

        The 'protocol' is the one of two that is an instance of protocol type, 'subtype'
        is the type used to bind self during inference. Currently, we just infer constrains for
        every protocol member type (both ways for settable members).
        r6  r0  )rv   r?  r   r   r@  r   r   r   IS_SETTABLEget_member_flagsrO  )
rH   r=  r   rT  protocolr7  r   memberinsttemps
             rI   rD  z@ConstraintBuilderVisitor.infer_constraints_from_protocol_members  s     mm44F==,,VXwR[,\D==,,VXwGD|t|Z'	 JJ(tT^^DE}}((DMM,J,J6S[,\\

,T49OPQ 5 
rK   c           
     P   |j                         }d}t        | j                  t              rg }| j                  j                         }|j	                         }|j
                  |j
                  }}|j                  $|j                  |j                  }|j                  }|j                  $|j                  |j                  }|j                  }|j                  t        ||| j                               |Jt        j                  rg|j                  r[| j                  sOt        d |j                  D              s3|j                  t        ||t!        | j                        d             d}|j"                  s2t%        |j&                        }||j	                         sw|j&                  |   }	t        |	t(              sJ t+        |	      }
t-        ||
      }t-        ||
      }t/        ||t!        | j                              }|j                  |       n|j                  t1        ||| j                               nl|j2                  }t5        |j&                        }|j	                         }t        j                  rK|j                  r?| j                  s3|j                  t        ||t!        | j                        d             d}|j7                  |j&                  d | |j8                  d | |j:                  d |       }|j                  t1        ||| j                               d }|st5        |j8                  D cg c]  }|t<        t>        fv s| c}      }tA        ||      }tC        |j&                  |d  |j8                  |d  |j:                  |d  t        j                  s|j                  ng |jD                        }nt5        |j2                  j&                        t5        |j2                  j&                        k  rx|j7                  tC        |j2                  j&                  |d  |j2                  j8                  |d  |j2                  j:                  |d  |j2                  jD                              }|&|jG                  tI        || j                  |             |r&|D ]!  }|xjJ                  |j                  z  c_%        # |S t        | j                  tL              r|j	                         }tM        tN        jP                  | j                  	      }|'| jS                  |j&                  | j                        }n+tI        |tT        tC        ||gtV        tX        gd d g            g}|j                  t        |j
                  || j                               |S t        | j                  tZ              r| j]                  | j                  |      S t        | j                  t^              r5t        |j
                  | j                  j`                  | j                        S t        | j                  tb              rRtd        jf                  ji                  d
| j                  | j                  d      }|rt        ||| j                        S g S g S c c}w )NFc              3  P   K   | ]  }|j                   j                            y wrC   )rD   is_self)ri   tvs     rI   rl   z?ConstraintBuilderVisitor.visit_callable_type.<locals>.<genexpr>  s     L:KB:Ks   $&T)r   )rn   ro   rp   )rn   ro   rp   r   rq   rm   r8  )
source_anyr0  r4  )5with_unpacked_kwargsrU   r   r   rk   rC  
type_guardtype_isr   r   r   r9   r+  r   r   r   rO  is_ellipsis_argsr2   rn   r1   get_tuple_fallback_from_unpackrepack_callable_args#build_constraints_for_simple_unpackr,  r-  r}   r{   ro   rp   r   r   minr   rq   rz   r?   rG   r   r&   from_another_anyr*  r;   r   r   r   infer_against_overloadedr(   rE  r   r   r   r@  )rH   r   rG   r   cactualrk   template_ret_typecactual_ret_typeunpack_presentunpack
tuple_typetemplate_typesr   unpack_constraintsr-  rX  
cactual_pscactual_prefixparam_spec_targetkmax_prefix_lenrj   r   rR  s                           rI   visit_callable_typez,ConstraintBuilderVisitor.visit_callable_type  s    002dkk<0$&Ckk668G!,,.J2:2C2CWEUEU/"".73E3E3Q$,$7$7!#*#5#5 +0K$,$4$4!#*?? JJ():<Ldnn]^! 00)) ,,  L':K:KLL
 JJ)#Xvdnn/ESW
 #'K  00%89K9K%LN
 &1':L:L:N "*!3!3N!C)&*===%CF%K
)=h
)S';GZ'P-P*L&:P.* 

#56 

@7TXTbTbc $** !1!12
$//1
//G4E4EdN^N^JJ)#Xvdnn/ESW
 #'K ")!6!6%//<%//<%//< "7 "
 

8QUQ_Q_` 26!!%(W5F5F)b5F!PWY`OaJa!5F)b%cN!$Z!@J(2")"3"3JK"@")"3"3JK"@")"3"3JK"@;E;W;W'"3"3]_,3,G,G)% :,,6673z?P?P?Z?Z;[[,6,D,D#-*4*;*;*E*Ejk*R*4*;*;*E*Ejk*R*4*;*;*E*Ejk*R4>4E4E4Y4Y	$ -E -) %0JJz*dnnFWXYAMMW%6%66M JW-!,,.Jy99dkkRH!,,X-?-?M """Hh#7(I9NQUW[P\] JJ():):HdnnUVJZ000hGGX.$X%6%68H8H$..YYX. ==,,DKK$ - D (4HH	Iq *cs   	Z#Z#c                H    t        ||      }t        ||| j                        S rC   )find_matching_overload_itemr   r   )rH   
overloadedr   rE  s       rI   r  z1ConstraintBuilderVisitor.infer_against_overloaded  s#     +:x@ 4@@rK   c                   | j                   }t        |j                        }t        |t              xr |j
                  j                  dk(  }t        |t              s|rg }|c|r|j                  |   }t        |t              sJ t        |j
                        }t        |t              rt        || j                  |      g}nBt        |t              r|j
                  j                  dk(  sJ t        ||| j                        }t        |t              sJ t        |j                        D ]>  \  }}	||k(  r|j                  t        |	|j                   d   | j                               @ |S t        |t              sJ t#        |j                  |j                  | j                        }
d}d}|j                  |
       nt        |t              rt        |j                        }|K|j                  |   }t        |t              sJ t        |j
                        }t%        |j                        dz   t%        |j                        k  r|}t%        |j                        |z
  dz
  }t'        t)        |j                        ||      \  }}}t)        |j                  d |       }|r|t)        |j                  | d        z  }||z   }t        |t              r|j
                  j                  dk(  sJ |D ]5  }|j                  t        ||j                   d   | j                               7 n2d}d}n-t)        |j                        }t)        |j                        }n|S t        |t              sJ t%        |      t%        |      k(  r|j*                  j
                  j,                  rN|j*                  j
                  j,                  r.|t        |j*                  |j*                  | j                        z   S t/        t%        |            D ].  }|j                  t        ||   ||   | j                               0 |S t        |t0              r| j3                  |j                  |      S g S )Nrg   )r@   rE   rA   r   rc   r<   )r   r2   r|   rU   r   rv   r~   r"   r1   r3   r+   r?   r   r   ru   r   rf   r  r}   r7   tuplerx   is_named_tupleranger   r*  )rH   r   r   unpack_indexis_varlength_tupler   r   r   r   tir  actual_itemstemplate_itemsa_unpack_indexa_unpack
a_unpackeda_prefix_lena_suffix_lenrf  rg  rh  tms                         rI   visit_tuple_typez)ConstraintBuilderVisitor.visit_tuple_type  s   *8>>:vx(UV[[-A-AEU-U 	 fi(,>$&C'% #+..">K%k:>>>$3K4D4D$EM!-1AB&$..Y_`
 '}h? - 2 2 ; ;?O OP 0vt~~V%fh777!*8>>!:2,$

#4RQ#XY "; J%fi888)L dnn*& 68L79NJJ12FI.!4V\\!B!-  &||N;H%h
;;;!0!?J6<<(1,HNN0CC'5'*6<<'8>'IA'M7S!(..1<84(H (-V\\-<-H'I'(E&,,}~2N,OOL)1H)<%j(;#-??#;#;?O#OO#O&. #

$5b*//!:Ldnn$]!" '/
 (*)+#(#6L%*8>>%:N
 fi000< C$77++00?? 1166EE !2 1163J3JDNN"   s>23AJJ).*;\!_dnn] 4 J())(..&AAIrK   c                :   | j                   }t        |t              rDg }|j                  |      D ],  \  }}}|j	                  t        ||| j                               . |S t        |t              r*| j                  |j                  j                         |      S g S rC   )r   rU   r%   r   r   r   r   r   r*  r|   r   )rH   r   r   r   	item_nametemplate_item_typeactual_item_types          rI   visit_typeddict_typez-ConstraintBuilderVisitor.visit_typeddict_type  s    fm,$&C DL<<PVCW?	-/?

,-?AQSWSaSabc DXJ())(..*?*?*A6JJIrK   c                    J d       )Nz`Unexpected UnionType in ConstraintBuilderVisitor (should have been handled in infer_constraints)rc   r  s     rI   visit_union_typez)ConstraintBuilderVisitor.visit_union_type  r   rK   c                    J d|        )Nz!This should be never called, got rc   r  s     rI   visit_type_alias_typez.ConstraintBuilderVisitor.visit_type_alias_type  s    D9(DDurK   c                   g }|D ]  }t        |t              rt        |j                  t              r1|j	                  t        |j                  | j                  |             ^t        |j                        }t        |t              sJ |j                  t        ||| j                               |j                  t        ||| j                                |S rC   )rU   r1   rv   r+   rz   r?   r   r3   r   r   r   )rH   r   r   r   r   rk  s         rI   r*  z*ConstraintBuilderVisitor.infer_against_any  s     "A!Z(aff&67JJz!&&$..(KL.qvv6H%h999JJ08T^^TU
 

,Q$..IJ  
rK   c                    t        | j                  t              rt        || j                        }n|j                  }g }|D ]2  }|j                  t        || j                  | j                               4 |S rC   )rU   r   r   find_matching_overload_itemsr|   r   r   r   )rH   r   r|   r   r   s        rI   visit_overloadedz)ConstraintBuilderVisitor.visit_overloaded)  s[    dkk<004;;GENNE "AJJ(DKKHI 
rK   c                   t        | j                  t              r5t        |j                  | j                  j
                  | j                        S t        | j                  t              rBt        |j                  | j                  j                  d   j
                  | j                        S t        | j                  t              r5t        |j                  | j                  j                  | j                        S t        | j                  t              r+t        |j                  | j                  | j                        S g S )Nr   )rU   r   r   r   rE  rC  r   r   r|   r(   r   r  s     rI   visit_type_typez(ConstraintBuilderVisitor.visit_type_type3  s    dkk<0$X]]DKK4H4H$..YYZ0$X]]DKK4E4Ea4H4Q4QSWSaSabbX.$X]]DKK4D4DdnnUUW-$X]]DKKPPIrK   N)r   r!   r   rX   r   r]   rY   rZ   )r   r.   rY   list[Constraint])r   r   rY   r  )r   r   rY   r  )r   r/   rY   r  )r   r   rY   r  )r   r   rY   r  )r   r   rY   r  )r   r    rY   r  )r   r,   rY   r  )r   r   rY   r  )r   r+   rY   r  )r   r1   rY   r  )r   r   rY   r  )r   r   rY   r  F)r=  r   r   r   rT  r#   rq  r   r7  r]   rY   r  )r   r   rY   r  )r  r   r   r   rY   r  )r   r"   rY   r  )r   r%   rY   r  )r   r0   rY   r  )r   r$   rY   r  )r   Iterable[Type]r   r   rY   r  )r   r   rY   r  )r   r(   rY   r  )r^   r_   r`   ra   rb   rJ   r  r  r  r	  r  r  r  r  r  r"  r%  r(  r.  rm  rD  r  r  r  r  r  r  r*  r  r  rc   rK   rI   r   r   u  s    7 '
'
"T$Qr    	
   
<\|	A$	A0<	A		A_B
E"
rK   r   c                Z    | t         k(  rt        S | t        k(  rt         S t        d|        )z,Map SubtypeOf to SupertypeOf and vice versa.zInvalid operator )r;   r=   
ValueError)rE   s    rI   rO  rO  @  s3     
Z	|	,RD122rK   c                    | j                   }|D ]B  }t        j                  j                  ||t        j                  j                  dd      s@|c S  |d   S )z.Disambiguate overload item against a template.FT	is_compatis_proper_subtypeignore_returnr   )r|   r   r   is_callable_compatibler   )r  r   r|   rE  s       rI   r  r  K  s[    E ==//mm..# 0 
 K  8OrK   c                    | j                   }g }|D ]P  }t        j                  j                  ||t        j                  j                  dd      s@|j                  |       R |s|j                         }|S )zMLike find_matching_overload_item, but return all matches, not just the first.FTr  )r|   r   r   r  r   rz   copy)r  r   r|   r   rE  s        rI   r  r  ^  su     E
C ==//mm..# 0 
 JJt   jjlJrK   c                   t        | j                        }t        |t              r%|j                  j                  dk(  r|j                  S t        |t
              r|j                  j                  S t        |t              r8|j                  j                  j                  D ]  }|j                  dk(  s|c S  J d       )zMGet builtins.tuple type from available types to construct homogeneous tuples.rg   zInvalid unpack type)
r3   rv   rU   r   r~   r+   rw   r"   rx   mro)r  tpbases      rI   r~  r~  v  s    		%B"hBGG$4$48H$Hww"&'  %%%"i '',,00D}} 00 1 (''5rK   c                   t         | j                  vr| j                  S | j                  j                  t               }| j                  d| }| j                  |   }g }t	        |t
              st        t        ||g            }nbt        |j                        }t	        |t              r=t	        |j                  d   t
              sJ |j                  d   }|j                  dd }||gz   |z   S )ag  Present callable with star unpack in a normalized form.

    Since positional arguments cannot follow star argument, they are packed in a suffix,
    while prefix is represented as individual positional args. We want to put all in a single
    list with unpack in the middle, and prefix/suffix on the sides (as they would appear
    in e.g. a TupleType).
    Nr   r<   )r   ro   rn   indexrU   r1   r   r3   rv   r"   r|   )callabler  
star_indexrn   	star_typesuffix_typesr  s          rI   r  r    s     x)))!!!##))(3J"";J/I"":.ILi,x
YK@A	Y^^,b)$bhhqk:666I88AB<L	{"\11rK   c                V   t        |       }|J |}t        |       |z
  dz
  }d}g }t        |      }|| |   }||z   t        |      kD  rdt        |t              sJ t        |j                  t
              r6t        |j                  |t        g |j                  j                              gS g S |}	|}
n:|}t        |      |z
  dz
  }t        ||      }	t        ||      }
||k\  r
||k\  r| |   }t        t        |      |	|
      \  }}}t        | d|	 |      D ]!  \  }}|j                  t        |||             # |
r4t        | |
 d |      D ]!  \  }}|j                  t        |||             # |Tt        |t              sJ t        |j                        }t        |t               r|j                  j"                  dk(  r|D ]  }t        |t              s*|j                  t        |j$                  d   ||             =t        |j                        }t        |t               sc|j                  j"                  dk(  s}|j                  t        |j$                  d   |j$                  d   |              |S t        |t
              r9|j'                  t        ||t        t)        |      |j                                     |S |||   }t        |t              sJ t        |j                        }t        |t               r|j                  j"                  dk(  r| |   }t        |t              sJ t        |j                        }t        |t               rO|j                  j"                  dk(  r6|j                  t        |j$                  d   |j$                  d   |             |S )a  Infer constraints between two lists of types with variadic items.

    This function is only supposed to be called when a variadic item is present in templates.
    If there is no variadic item the actuals, we simply use split_with_prefix_and_suffix()
    and infer prefix <: prefix, suffix <: suffix, variadic <: middle. If there is a variadic
    item in the actuals we need to be more careful, only common prefix/suffix can generate
    constraints, also we can only infer constraints for variadic template item, if template
    prefix/suffix are shorter that actual ones, otherwise there may be partial overlap
    between variadic items, for example if template prefix is longer:

        templates: T1, T2, Ts, Ts, Ts, ...
        actuals:   A1, As, As, As, ...

    Note: this function can only be called for builtin variadic constructors: Tuple and Callable.
    For instances, you should first find correct type argument mapping.
    Nr<   rg   r   )r2   r}   rU   r1   rv   r+   r?   r"   rw   r  r7   r  r   r   r   r3   r   r~   rf   rz   r   )ri  actual_argsr   template_unpacktemplate_prefixtemplate_suffixt_unpackr   actual_unpackcommon_prefixcommon_suffixactual_prefixactual_suffixstartmiddleendr   r   r  a_tpactual_unpack_typer  s                         rI   r  r    sg   & *-8O&&&%O-(?:Q>OH
C'4M 1_,s;/??h
333(--)9:  y)B@\@\2]  	''%K(=81<O];O];O+0P %_5H 6kM=E63 M.=1591

$Q956 :}no6<DAqJJ(Ay9: = (J///X]]+b(#(8(8<L(L!!Z0JJ0Q	JK*1662D!$1dii6H6HL\6\

#4RWWQZ1y#YZ . J ,-JJz"i4<IZIZ1[\] J 
	" )7,j999$%7%<%<=
j(+
0H0HL\0\$_5Hh
333 /B"h'BGG,<,<@P,P

,RWWQZ9KYWXJrK   c                    t        | t        t        f      st        |t        t        f      rg S |t        k(  rt	        | |t        |            S t	        || t        |            S )zSInfer constraints between two arguments using direction between original callables.)rU   r   r1   r;   r   rO  )leftrightr   s      rI   infer_directed_arg_constraintsr    sY    $
34
z*9
 	J ufY.?@@ fY.?@@rK   c                   g }|t         k(  r| |}}n|| }}|j                         }|j                         }|j                         }|j                         }	|2|0|j                  t	        |j
                  |j
                  |             |2|	0|j                  t	        |j
                  |	j
                  |             |j                         D ]U  }
t        j                  j                  ||
      }|&|j                  t	        |j
                  |
j
                  |             W ||j                  d      }|J |j                  }|J |t        |j                        k  r|j                  |   j                         r|j                  |      }|J |j                  t	        |j
                  |j
                  |             |dz  }|t        |j                        k  r|j                  |   j                         r|	|j                   D ch c]  }||	 }}t#               }t%        |j                   |j                        D ]-  \  }}||j'                         s||v r|j)                  |       / |j+                  d      }|J |D ]G  }|j-                  |      }|J |j                  t	        |j
                  |j
                  |             I |S c c}w )a  Infer constraints between argument types of two callables.

    This function essentially extracts four steps from are_parameters_compatible() in
    subtypes.py that involve subtype checks between argument types. We keep the argument
    matching logic, but ignore various strictness flags present there, and checks that
    do not involve subtyping. Then in place of every subtype check we put an infer_constraints()
    call for the same types.
    Nr<   )r;   var_argkw_argr   r  r   formal_argumentsr   r   callable_corresponding_argument try_synthesizing_arg_from_varargposr}   ro   is_positionalargument_by_positionrp   setr   is_staraddtry_synthesizing_arg_from_kwargargument_by_name)r   r   r   r   r  r  	left_star
left_star2
right_starright_star2	right_argleft_argright_by_positionr   left_by_positionnameright_namesleft_only_nameskindright_by_nameleft_by_names                        rI   r,  r,    s    CJeheIJJ,,.K !7

1)--QZ[\+"9

1*..+//S\]^ ++-	<<??iP

1(,,	yYZ	 . !BB4H ,,,NN}}#dnn%%$..*;*I*I*K#88;#///JJ.$((*;*?*?
 FA #dnn%%$..*;*I*I*K (-L4;KtL%dnndnn=JD$|t||~1D% >
 ==dC(((#D006L+++JJ.|/?/?ARART]^ $ J Ms   KKc                4   t               }| D ]  }t        |j                  t              st        |j                  t              s2t        |j                  t
              sS|j                  j                  rj|j                  |j                          g }| D ]}  }t        |j                  t              r|j                  |vr|j                  |       t        |j                  t
              r|j                  j                  rm|j                  |        |S )zWFor each ParamSpec remove all imprecise constraints, if at least one precise available.)
r  rU   rF   r   rA   r   rq   r  r@   rz   )cshave_preciserj   new_css       rI   r   r   V  s    5L!++];qxx/!((J/HH00QZZ(  F!++];qzzQ]?]MM!!((J/qxx7S7SMM!	 
 MrK   )r   r   rn   zSequence[Type | None]ro   zlist[ArgKind]rp   zSequence[str | None] | Noner   zlist[list[int]]r   r:   rY   r  r  )
r   r#   r   r#   r   rX   r   r]   rY   r  )r   r#   r   r#   r   rX   rY   list[Constraint] | None)r   z!Sequence[list[Constraint] | None]rY   zlist[list[Constraint]])r   r?   rY   r?   )r   r0   r   r#   r   rX   rY   r  )r   zlist[list[Constraint] | None]r   r]   rY   r  )r   r  rY   r  )r   r  r   r  rY   r]   )r   r?   r   r?   rY   r]   )r   r  rY   
list[Type])r   r#   rY   r]   )rE   rX   rY   rX   )r  r   r   r   rY   r   )r  r   r   r   rY   zlist[CallableType])r  r1   rY   r   )r  r   r  r   rY   r   )ri  r   r  r   r   rX   rY   r  )r  r#   r  r#   r   rX   rY   r  )r   #NormalizedCallableType | Parametersr   r  r   rX   rY   r  )r  r  rY   r  )era   
__future__r   typingr   r   r   r   r   mypy.subtypesr   mypy.typeopsmypy.argmapr	   mypy.erasetyper
   mypy.maptyper   
mypy.nodesr   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/   r0   r1   r2   r3   r4   r5   r6   r7   mypy.types_utilsr8   mypy.typestater9   
mypy.inferr:   r;   rb   r=   r?   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r]   r  r   rO  r  r  r~  r  r  r  r,  r   rc   rK   rI   <module>r     st   ! " A A   ' ) 2	 	 	% % % % % % % % % %L / %/
E e "a "aJff$f f +	f
 &f "f fT GL)H)H )H-0)H?C)H)HXZUZU ZU-0ZU?CZUZUz:: :-0::2
T1h.	K(-)D/ H{4
+;< HV3&&20(24]],6]CF]]@AF1F/F F 	FRrK   