
    hiJ                       d dl mZ d dlmZ d dlm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 d dl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,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< dFdZ=dFdZ>dGdZ?dHdZ@dIdZAdIdZBdJdZCdKdZDdKd ZEdLd%ZF	 	 	 	 dMdNd,ZGd&d-dOd.ZHdPd2ZIdQd3ZJdRd8ZKdSd;ZLdTd<ZM G d= d>e2e'                   ZNdUd@ZOdVdBZPdWdCZQdXdEZRd'S )Y    )annotations)Callable)join)
erase_type)map_instance_to_supertype)state)are_parameters_compatiblefind_memberis_callable_compatibleis_equivalentis_proper_subtypeis_same_type
is_subtype)is_recursive_pairmake_simplified_uniontuple_fallback)$MYPYC_NATIVE_INT_NAMESTUPLE_LIKE_INSTANCE_NAMESAnyTypeCallableTypeDeletedType
ErasedTypeFunctionLikeInstanceLiteralTypeNoneType
Overloaded
ParametersParamSpecTypePartialType
ProperType	TupleTypeTypeTypeAliasTypeTypedDictTypeTypeGuardedType	TypeOfAnyTypeTypeTypeVarLikeTypeTypeVarTupleTypeTypeVarTypeTypeVisitorUnboundTypeUninhabitedType	UnionType
UnpackTypefind_unpack_in_listget_proper_typeget_proper_typeshas_type_varsis_named_instancesplit_with_prefix_and_suffixsr#   treturnr!   c                    t          | |          rt          |           S t          ||           rt          |          S t          j        rt	                      S t                      S )zRReturn one of types (expanded) if it is a subtype of other, otherwise bottom type.)r   r2   r   strict_optionalr.   r   r7   r8   s     Y/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/mypy/meet.pytrivial_meetr>   =   sc    !Q q!!!	Aq		 q!!!  	"$$$::    c                   t          | |          rt          | |          S t          |           } t          |          }t          | t                    rt          |t                    r| j        |j        k    ro| j        s|j        rat          | |          rQ| j        r?|j        r8t          | j        j	                  t          |j        j	                  k    r| S |S | j        r| S |S t          | t                    s=t          |t                    s(t          | |d          r| S t          || d          r|S t          | t                    r| S t          | t                    r|S t          | t                    rt          |t                    s|| }} t          j        | |          \  } }|                    t%          |                     S )z-Return the greatest lower bound of two types.Tignore_promotions)r   r>   r2   
isinstancer   typeextra_attrsr   lenattrsr-   r   r   r   r/   r   normalize_callablesacceptTypeMeetVisitorr<   s     r=   
meet_typesrK   J   s   A " Aq!!!AA!X :a#:#: qv?O?O M 	Q] 	Q0B0B 	}  q}*++c!-2E.F.FFFH} Ha%% jK.H.H QT::: 	HQT::: 	H!Z   !W !Y 
1i(@(@ !1 #Aq))DAq88OA&&'''r?   declarednarrowedc                    t          |t                    r t           |j        d          r S |j        S  }|}t	                      t	          |          } |k    r|S t           t
                    r\                                 }t          |t
                    r|                                n|gt          fd|D                       S t           |          rDt          |t
                    sJ t           fd|                                D                       S t           t                    r:t          |          s+t          | j                  r                     |          S t           |d          s(t          j        rt#                      S t%                      S t          |t
                    r-t           fd|                                D                       S t          |t&                    r|S t          |t                    rt          |j                   r|S t           t(                    rAt          |t(                    r,t)          j        t-           j        |j                            S t           t(                    r0t          |t0                    r|j                                        r|S t           t0                    rY j        j        r|S t          |t0                    r&|j        j        r|j        j        j         j        u r|S t9          ||          S t           t:          t(          t<          f          rt9          ||          S t           t>                    rbt          |t0                    rM|j        j         dk    r-tC          d	 tE          |j#                  D                       r|S t9          ||          S |S )
z7Return the declared type narrowed down to another type.TrA   c                    g | ];}D ]6}t          ||d           st          ||d          &t          ||          7<S )TrA   F)is_overlapping_typesr   narrow_declared_type).0dnnarrowed_itemss      r=   
<listcomp>z(narrow_declared_type.<locals>.<listcomp>   sz       '   )AFFF "!Q%@@@$Q**   r?   c                0    g | ]}t          |          S  rQ   rR   xrL   s     r=   rV   z(narrow_declared_type.<locals>.<listcomp>   $    RRR1!(A..RRRr?   upper_bound)prohibit_none_typevar_overlapc                0    g | ]}t          |          S rX   rY   rZ   s     r=   rV   z(narrow_declared_type.<locals>.<listcomp>   r\   r?   zbuiltins.dictc              3  @   K   | ]}t          |t                    V  d S N)rC   r   )rR   r8   s     r=   	<genexpr>z'narrow_declared_type.<locals>.<genexpr>   s=       =
 =
'(Jq'""=
 =
 =
 =
 =
 =
r?   )$rC   r&   r   
type_guardr2   r/   relevant_itemsr   is_enum_overlapping_unionr+   r4   r   r^   copy_modifiedrP   r   r;   r.   r   r   r(   make_normalizedrQ   itemr   rD   is_metaclassalt_promoterK   r"   r   r%   fullnameallr3   args)rL   rM   original_declaredoriginal_narroweddeclared_itemsrU   s   `    @r=   rQ   rQ   t   s=    (O,, #Xx':dSSS 	O""  x((Hx((H8  (I&& 
!0022h	** 	(%4466NN&ZN$   '  
 
 	
( !844 :@ (I.....$RRRR8O8O8Q8QRRR
 
 	
 	8[))3@/003@ ((*>??3@ %%2C%DDD!(HTXYYY +@  	"$$$::	Hi	(	( &@$RRRR8O8O8Q8QRRR
 
 	
 
Hg	&	& "@  	Hk	*	*  @z(:NPX/Y/Y  @	Hh	'	' @Jx,J,J @'(<X]HM(Z(Z[[[8X&&@x**@ M&&((@ ! 	Hh	'	' @=$ 	%$$x**	%)	% ).(-?? %$+->???	Hy(K@	A	A @+->???	Hm	,	, @Hh1O1O @=!_44 =
 =
,<X],K,K=
 =
 =
 :
 :
4 %$+->???r?   typ
list[Type]c                n   t          |           } t          | t                    r't          | j                  dk    r| j        S | j        gS t          | t                    rdt          | j                  }t          |t                    r!t          |j        j	        d         g           gS t          t          j                  gS t          | t                    r| j        gS t          | t                    rt          | j                  S t          | t"                    rt          | j                  S | gS )a  This function takes any "Union-like" type and returns a list of the available "options".

    Specifically, there are currently exactly three different types that can have
    "variants" or are "union-like":

    - Unions
    - TypeVars with value restrictions
    - Overloads

    This function will return a list of each "option" present in those types.

    If this function receives any other type, we return a list containing just that
    original type. (E.g. pretend the type was contained within a singleton union).

    The only current exceptions are regular TypeVars and ParamSpecs. For these "TypeVarLike"s,
    we return a list containing that TypeVarLike's upper bound.

    This function is useful primarily when checking to see if two types are overlapping:
    the algorithm to check if two unions are overlapping is fundamentally the same as
    the algorithm for checking if two overloads are overlapping.

    Normalizing both kinds of types in the same way lets us reuse the same algorithm
    for both.
    r   )r2   rC   r+   rF   valuesr^   r   r   rD   mror   r'   implementation_artifactr*   r/   listitemsr   )rr   r^   s     r=   get_possible_variantsr{      s   2 #

C#{## sz??Q:O$$	C	'	' %co66k8,, 	<[-1"5r::;;	9::;;	C)	*	* 	  	C	#	# CI	C	$	$  CIur?   r[   yboolc                     t           t                    oN j        j        oBt          |t                    o-t           fd|                                D                       S )zOReturn True if x is an Enum, and y is an Union with at least one Literal from xc              3     K   | ]=}t          t          |          xt                    oj        j        j        k    V  >d S rb   )rC   r2   r   rD   fallback)rR   zpr[   s     r=   rc   z,is_enum_overlapping_union.<locals>.<genexpr>  s^       
 
 OA...q<<Z1:?AZ
 
 
 
 
 
r?   )rC   r   rD   is_enumr/   anyre   )r[   r|   r   s   ` @r=   rf   rf     s     	1h 	
FN	
q)$$	
  
 
 
 
 
%%''
 
 
 
 
	r?   c                     t           t                    o4t          |t                    ot           fd|j        D                       S )z?Return True if x is a Literal and y is an Union that includes xc              3  >   K   | ]}t          |          k    V  d S rb   )r2   )rR   r   r[   s     r=   rc   z&is_literal_in_union.<locals>.<genexpr>!  s0      99A_Q'''999999r?   )rC   r   r/   r   rz   )r[   r|   s   ` r=   is_literal_in_unionr     sP     	1k"" 	:q)$$	:999999999r?   c                L    t          | t                    o| j        j        dk    S Nzbuiltins.object)rC   r   rD   rl   )r8   s    r=   	is_objectr   %  s!    a""Kqv:K'KKr?   t1t2c                V    t          | t                    ot          |t                    S rb   )rC   r   r)   r   r   s     r=   is_none_typevarlike_overlapr   )  s!    b(##G
2(G(GGr?   c                v    t          | t                    o$t          |t                    o|j        j        dk    S r   )rC   r   r   rD   rl   r   s     r=   is_none_object_overlapr   -  s9    2x   	2r8$$	2G 11r?   leftrightproper_subtyperB   c                   |r$t          | ||          pt          || |          S t          | ||          pt          || |          S )NrA   )r   r   )r   r   r   rB   s       r=   are_related_typesr   5  s      
 %+<
 
 
 Qud>OPPP	Q $9JKKK 
z4+<P
 P
 P
 	
r?   FNr_   overlap_for_overloads
seen_typesset[tuple[Type, Type]] | Nonec                   t          | t                    st          |t                    rdS t                      n| |fv rdS t          | t                    r,t          |t                    r                    | |f           t          | |f          \  } }t          | t                    st          |t                    r
J d            t          t          t          f}t          | |          st          ||          rdS t          j        st          | t                    r&t          j        |                                           } t          |t                    r&t          j        |                                          }t          | |f          \  } }t          | t                    st          |t                    r! pt!          |           pt!          |          S t#          | |          s0t#          ||           s t%          | |          st%          ||           rdS r"t'          | |          st'          ||           rdS t)          | |          rdS t+          |           }t+          |          }r"t-          | |          st-          ||           rdS dfdt/          |          dk    s=t/          |          dk    s*t          | t0                    st          |t0                    r|D ]}	|D ]}
 |	|
          r  dS dS t          j        r.t          | t2                    t          |t2                    k    rdS t          | t4                    r&t          |t4                    rt7          | |          S t9          | |          rt;          | |          S t          | t4                    r| j        } nt          |t4                    r|j        }t?          |           r t?          |          rtA          | |          S t          | tB                    rtE          |           } n$t          |tB                    rtE          |          }t          | tF                    r+t          |tF                    r | j$        |j$                  S t          | tF                    st          |tF                    rdfd} || |          p |||           S t          | tJ                    r+t          |tJ                    rtM          | |d d          S t          | tJ                    st          |tJ                    rdS t          | tN                    r+t          |tN                    rtQ          | |d d          S d}d}t          | tN                    r*t          |tR                    rtU          d||d          }| }t          |tN                    r*t          | tR                    rtU          d| | d          }|}t          tW          |          tX                    r||J  ||          S t          | tN                    r| j        } t          |tN                    r|j        }t          | tZ                    r6t          |tZ                    r!| j.        |j.        k    r| j        } |j        }n;dS t          | tZ                    r| j        } nt          |tZ                    r|j        }t          | tR                    rt          |tR                    rt)          | |          rdS |j/        j0        dk    r| j/        j0        tb          v rdS | j/        2                    |j/        j0                  rtg          | |j/                  } n<|j/        2                    | j/        j0                  rtg          || j/                  }ndS |j/        j4        r|j/        j5        J |j/        j6        J |j/        j5        }|j/        j6        }|j/        j7        j8        |         }t          |tr                    sJ |j"        }tu          | j;        ||          \  }}}tu          |j;        ||          \  }}}|tC          ty          |          |          fz   |z   }|tC          ty          |          |          fz   |z   }n| j;        }|j;        }t/          |          t/          |          k    r+t{          fdt}          ||          D                       rdS dS t_          |           t_          |          k    s)J t_          |            dt_          |                       dS )aE  Can a value of type 'left' also be of type 'right' or vice-versa?

    If 'ignore_promotions' is True, we ignore promotions while checking for overlaps.
    If 'prohibit_none_typevar_overlap' is True, we disallow None from overlapping with
    TypeVars (in both strict-optional and non-strict-optional mode).
    If 'overlap_for_overloads' is True, we check for overlaps more strictly (to avoid false
    positives), for example: None only overlaps with explicitly optional types, Any
    doesn't overlap with anything except object, we don't ignore positional argument names.
    TNFz%Unexpectedly encountered partial type)r   rB   r   r#   r   r9   r}   c           	     R    t          | |                                          S )zEncode the kind of overlapping check to perform.

        This function mostly exists, so we don't have to repeat keyword arguments everywhere.
        )rB   r_   r   r   )rP   copy)r   r   rB   r   r_   r   s     r=   _is_overlapping_typesz3is_overlapping_types.<locals>._is_overlapping_types  s8    
 $/*G"7!((
 
 
 	
r?      )overlappingc                   t          | |f          \  } }t          | t                    r+t          |t                    r | j        |j                  S t          | t                    rt          |t                    rt          | j        t                    r9| j        j        j        }| ||          S |j        	                    d          S t          | j        t                    r|j        	                    d          S dS )z-Special cases for type object types overlaps.Nbuiltins.typeF)r3   rC   r(   r   ri   ret_typer   rD   metaclass_typehas_baser   )r   r   	left_metar   s      r=   _type_object_overlapz2is_overlapping_types.<locals>._type_object_overlap  s     +D%=99KD%$)) Hj.M.M H,,TYGGG$)) @j.I.I @di22 @ $	 =I ,44YFFF :..???	733 @ :..???5r?   )	is_compatr   ignore_pos_arg_namesallow_partial_overlap__call__)is_operatorzbuiltins.intc              3  6   K   | ]\  }} ||          V  d S rb   rX   )rR   left_arg	right_argr   s      r=   rc   z'is_overlapping_types.<locals>.<genexpr>t  sH        'Hi &%h	::     r?   z vs r   r#   r   r#   r9   r}   )?rC   r&   setr$   addr3   r    r-   r   r   r   r;   r/   
make_unionre   r   r   rf   r   r   r   r{   r   rF   r)   r   r%   are_typed_dicts_overlappingtyped_dict_mapping_pairtyped_dict_mapping_overlapr   is_tupleare_tuples_overlappingr"   r   r(   ri   r   r	   r   r   r   r
   r2   r   r   valuerD   rl   r   r   r   has_type_var_tuple_typetype_var_tuple_prefixtype_var_tuple_suffixdefn	type_varsr*   r6   rn   ry   rm   zip)r   r   rB   r_   r   r   illegal_typesleft_possibleright_possiblelrr   callotherprefixsuffixtvtr   left_prefixleft_middleleft_suffixright_prefixright_middleright_suffix	left_args
right_argsr   s     ````                    @r=   rP   rP   B  sO
   " $(( Juo,N,N tUU


*	$	$t$&& &:e]+K+K &e}%%%"D%=11KD% $$$ >
5+(F(F >===== !*k:M$&& *UM*J*J t
   6dI&& 	?'(;(;(=(=>>DeY'' 	A()=)=)?)?@@E&e}55e $   PJug$>$> P((OIdOOOy?O?OO 	"$..$UD11 tU++ ud++	 t !$.. 	2HPT2U2U 	5e$9M^    t
 *$//M*511N % &tU33 	7RSXZ^7_7_ 	5
 
 
 
 
 
 
 
 
 	MQ~""dO,, #e_-- #  	  	 A#    ((A..  444   u  D(!;!;z%QY?Z?Z!Z!Zu $&& :e]+K+K *48MNNN	 u	-	- )$CXYYYY	D-	(	( }	E=	)	) ~~ &(5// &%dE3HIII	D)	$	$ &d##	E9	%	% &u%% $!! <j&A&A <$$TY
;;;$!! VZx%@%@ V	 	 	 	 	 	( $#D%00U4H4HPT4U4UU$
## 

5*(E(E 
(+#%:!:"&
 
 
 	
 $
## z%'D'D u$%% 
*UL*I*I 
%+#%:!:"&
 
 
 	
 DE$%% *UH*E*E :ueFFF%&& :dH+E+E :tTtDDD/$''66 2E$5$5$5$$T5111$%% }%&& $$$ E;)G)G :$$ =DNEE5	D+	&	& }	E;	'	'  $!! <j&A&A < %(=Qb
 
 
 	 4:.00TY5GKa5a5a4 9ej122 	,T5:>>DDZ  !344 	-eTY??EE5:- 	$:3???:3???Z5FZ5F*/+F3Cc#344444)H4P	665 51Kk 8T
FF8 84L, $yk1B1BH'M'M&OOR]]I%43E3Ex)P)P(RRUaaJJ	IJy>>S__,,     +.y*+E+E      tu ::e$$$d&F&Fe&F&F$$$5r?   rA   c               \    t          t          |           t          |          |d          S )zMThe same as 'is_overlapping_erased_types', except the types are erased first.T)rB   r_   )rP   r   )r   r   rB   s      r=   is_overlapping_erased_typesr     s7      45+&*	   r?   r%   is_overlappingCallable[[Type, Type], bool]c                    | j         D ]3}||j        vr dS  || j        |         |j        |                   s dS 4|j         D ]3}|| j        vr dS  || j        |         |j        |                   s dS 4dS )z?Returns 'true' if left and right are overlapping TypeDictTypes.FT)required_keysrz   )r   r   r   keys       r=   r   r     s    
 !  ek!!55~djou{3/?@@ 	55	 "  dj  55~djou{3/?@@ 	55	 4r?   c                &   t          | |f          \  } }t          | |          p| } t          ||           p|}t          | t                    sJ d|  d            t          |t                    sJ d| d            t	          | j                  }t	          |j                  }|"t          | t          |j                            } |"t          |t          | j                            }t          | j                  t          |j                  k    rdS t          fdt          | j        |j                  D                       sdS t          |j        d          st          | j        d          rdS  | j        |j                  S )z6Returns true if left and right are overlapping tuples.zType z is not a tupleNFc              3  6   K   | ]\  }} ||          V  d S rb   rX   )rR   r   r   r   s      r=   rc   z)are_tuples_overlapping.<locals>.<genexpr>  s3      MM1~~a##MMMMMMr?   builtins.tupleT)r3   adjust_tuplerC   r"   r1   rz   expand_tuple_if_possiblerF   rm   r   r5   partial_fallback)r   r   r   left_unpackright_unpacks     `  r=   r   r     s    #D%=11KD%e$$,D%%.EdI&&EE(E(E(E(EEEEeY''GG)G)G)G)GGGG &dj11K&u{33L'c%+.>.>??(DJ@@
4:#ek****uMMMMDJ0L0LMMMMM u /1ABB MFW/G G M t~d3U5KLLLr?   tupr"   targetintc                
   t          | j                  |dz   k    r| S |dz   t          | j                  z
  }g }| j        D ]}t          |t                    s|                    |           -t          |j                  }t          |t                    r|j        }nt          |t                    sJ |}|j        j
        dk    sJ |                    |j        d         g|z             |                     |          S )Nr   r   r   rz   )rF   rz   rC   r0   appendr2   rD   r*   r   r   rl   extendrn   rg   )r   r   extra	new_itemsitunpackedinstances          r=   r   r     s   
39~~
""
QJSY'EIi 5 5"j)) 	R   "27++h 011 	 .HH h11111H}%)99999(-*+e344449---r?   r   TupleType | Nonec                    t          | t                    rZ| j        j        dk    rJt          |t                    r|                                nd}t	          | j        d         g|z  |           S dS )zGFind out if `left` is a Tuple[A, ...], and adjust its length to `right`r   r   r   N)rC   r   rD   rl   r"   lengthrn   )r   r   rT   s      r=   r   r     sf    $!! 3di&8<L&L&L$Q	229AHHJJJ$)A,!+T2224r?   c                    t          |           } t          | t                    p$t          | t                    o| j        j        dk    S )Nr   )r2   rC   r"   r   rD   rl   )rr   s    r=   r   r     sC    
#

Cc9%% 3!!Kch&7;K&Kr?   c                      e Zd Zd8dZd9dZd:d
Zd;dZd<dZd=dZd>dZ	d?dZ
d@dZdAdZdBdZdCdZdDdZdEd ZdFd"ZdGd$ZdHd'ZdId(ZdJd*ZdKd,ZdLd.ZdMd0ZdNd2ZdOd4ZdPd6Zd7S )QrJ   r7   r!   r9   Nonec                    || _         d S rb   r7   )selfr7   s     r=   __init__zTypeMeetVisitor.__init__  s    r?   r8   r-   c                    t          | j        t                    r!t          j        rt                      S | j        S t          | j        t
                    r| j        S t          t          j                  S rb   )	rC   r7   r   r   r;   r.   r   r'   special_formr   r8   s     r=   visit_unbound_typez"TypeMeetVisitor.visit_unbound_type  s`    dfh'' 	3$ &(((v00 	36M91222r?   r   c                    | j         S rb   r   r   s     r=   	visit_anyzTypeMeetVisitor.visit_any  	    vr?   r/   c                     t           j        t                    r?g }|j        D ]4} j        j        D ]%}|                    t          ||                     &5n fd|j        D             }t          |          S )Nc                :    g | ]}t          |j                  S rX   )rK   r7   )rR   r[   r   s     r=   rV   z4TypeMeetVisitor.visit_union_type.<locals>.<listcomp>  s%    <<<qZ46**<<<r?   )rC   r7   r/   rz   r   rK   r   )r   r8   meetsr[   r|   s   `    r=   visit_union_typez TypeMeetVisitor.visit_union_type  s    dfi(( 	= "EW 3 3 3 3ALLAq!1!1222233 =<<<AG<<<E$U+++r?   r   c                    t           j        rYt          | j        t                    s/t          | j        t
                    r| j        j        j        dk    r|S t                      S |S r   )	r   r;   rC   r7   r   r   rD   rl   r.   r   s     r=   visit_none_typezTypeMeetVisitor.visit_none_type  s^      	$&(++ )468,,)151EIZ1Z1Z&(((Hr?   r.   c                    |S rb   rX   r   s     r=   visit_uninhabited_typez&TypeMeetVisitor.visit_uninhabited_type  s    r?   r   c                    t          | j        t                    rt          j        r|S | j        S t          | j        t
                    r| j        S |S rb   )rC   r7   r   r   r;   r.   r   s     r=   visit_deleted_typez"TypeMeetVisitor.visit_deleted_type  sM    dfh'' 	$ v00 	6MHr?   r   c                    | j         S rb   r   r   s     r=   visit_erased_typez!TypeMeetVisitor.visit_erased_type'  r   r?   r+   c                H   t          | j        t                    ro| j        j        |j        k    rZ| j        j        |j        k    r| j        S | j                            |                     | j        j        |j                            S |                     | j                  S )Nr]   )rC   r7   r+   idr^   rg   meetdefaultr   s     r=   visit_type_varzTypeMeetVisitor.visit_type_var*  s    dfk** 	(tvyAD/@/@v!Q]22v6''DIIdf>PRSR_4`4`'aaa<<'''r?   r   c                Z    | j         |k    r| j         S |                     | j                   S rb   )r7   r  r   s     r=   visit_param_specz TypeMeetVisitor.visit_param_spec2  s(    6Q;;6M<<'''r?   r*   c                    t          | j        t                    r3| j        j        |j        k    r| j        j        |j        k    r| j        n|S |                     | j                  S rb   )rC   r7   r*   r
  min_lenr  r   s     r=   visit_type_var_tuplez$TypeMeetVisitor.visit_type_var_tuple8  sW    df.// 	(DFI4E4E!V^ai77466Q><<'''r?   r0   c                    t           rb   )NotImplementedErrorr   s     r=   visit_unpack_typez!TypeMeetVisitor.visit_unpack_type>  s    !!r?   r   c                   t          | j        t                    rt          |j                  t          | j        j                  k    r|                     | j                  S ddlm |                    fdt          | j        j        |j                  D                       S |                     | j                  S )Nr   )
join_typesc                .    g | ]\  }} ||          S rX   rX   )rR   s_at_ar  s      r=   rV   z4TypeMeetVisitor.visit_parameters.<locals>.<listcomp>H  s)    cccHC::c3//cccr?   )	arg_types)
rC   r7   r   rF   r  r  	mypy.joinr  rg   r   )r   r8   r  s     @r=   visit_parametersz TypeMeetVisitor.visit_parametersA  s    dfj)) 		(1;3tv'7#8#888||DF+++,,,,,,??ccccDFDTVWVa@b@bccc #    <<'''r?   r   c                	   t          | j        t                    r	|j        | j        j        k    rMt	          || j                  st	          | j        |          rg }|j        j        r| j        }|j        j        J |j        j        J |j        j        }|j        j        }|j        j        j	        |         }t          |t                    sJ |j        }t          |j        ||          \  }}	}
t          |j        ||          \  }}}|t          t          |	          |          fz   |
z   }|t          t          |          |          fz   |z   }n|j        }| j        j        }t!          |||j        j        j	                  D ]\  }}}|                     ||          }t          |t                    rpt          |t                    r|                    |j                   at          |t(                    sJ t+          |j                            |g                    }|                    |           t          |j        |          S t0          j        rt)                      S t5                      S |j        j        }|r|j        | j        j        u r|S | j        j        j        }|r|j        |j        u r| j        S t	          || j                  r|S t	          | j        |          r| j        S t0          j        rt)                      S t5                      S t          | j        t8                    r9|j        j        r-t=          j        |          }|rtA          || j                  S nCt          | j        t8                    rm| j        !                                rT|j        "                                r;t	          | j        j#        |          r| j        S | $                    | j                  S t          | j        tJ                    rtA          || j                  S t          | j        t                    rtA          || j                  S t          | j        tL                    rtA          || j                  S t          | j        tN                    rtA          || j                  S | $                    | j                  S )N)rn   )(rC   r7   r   rD   r   r   r   r   r   r   r*   r   r6   rn   r"   ry   r   r  r   rz   r.   r0   rg   r   r   r;   r   rk   r   is_protocolr   unpack_callback_protocolrK   is_type_objrj   r   r  r(   r   r%   )r   r8   rn   r7   r   r   r   r   s_prefixs_middles_suffixt_prefixt_middlet_suffixs_argst_argstasatvr  rk   r   s                         r=   visit_instancezTypeMeetVisitor.visit_instanceM  s~   dfh'' Q	)v$$a(( .*Jtvq,A,A .* (*D v5 - !F v;GGG v;GGG!"!=!"!=fk3F;)#/?@@@@@#&#57SFFF8 84(H 8TFFF8 84(H "*YtH~~x-P-P,R!RU]!]!)YtH~~x-P-P,R!RU]!]!"!%&)&&!&+:O&P&P * *
B#yyR00%b*:;; `  *$	:: ` $DJ 7 7 7 ('1$'H'H H H H'1"2C2Q2QX\W]2Q2^2^'_'_D))))#AFD111, *.000'zz)f0 ;#3tv{#B#BH"fk5 ";#3qv#=#=6Ma(( 	*H** *6M, *.000'zz)-- 	)!&2D 	)033D 0!$///0-- 	)$&2D2D2F2F 	)16K^K^K`K` 	)$&/1-- v<<''')) 	)a(((	** 	)a(((,, 	)a(((.. 	)a(((||DF###r?   r   c                   t          | j        t                    rt          j        || j                  rt          || j                  rt          j        || j                  S t          || j                  }|                                r|	                                j
        s>| j                                        r| j        	                                j
        sd|_        t          t          |j                  t                    r|                     | j                  S |S t          | j        t                     r|                                r}|                                sit%          | j        j        |j                  }t          |t(          t          f          st!          j        |          S |                     | j                  S t          | j        t,                    r<| j        j        j        r+t          j        | j                  }|rt%          ||          S |                     | j                  S )NT)rC   r7   r   r   is_similar_callablesr   combine_similar_callablesmeet_similar_callablesr!  type_objectis_abstractfrom_type_typer2   r   r.   r  r(   
is_genericrK   ri   r   rh   r   rD   r  r   )r   r8   resultresr   s        r=   visit_callable_typez#TypeMeetVisitor.visit_callable_type  s   dfl++ 	+0I!TV0T0T 	+Q'' A5a@@@+Atv66F -%&]]__%@-F&&((--1V-?-?-A-A-M- )-%/&/::OLL ,||DF+++M)) 		+ammoo 		+allnn 		+TV[!*55CcHo#>?? 5/444<<''')) 	+dfk.E 	+088D +!!T***||DF###r?   r   c                   | j         }t          |t                    rb|j        |j        k    rt	          |j                  S t          ||          r|S t          ||          r|S t          |j        |j                  S t          | j         t                    r<| j         j	        j
        r+t          j        | j                   }|rt          ||          S t          |j        |          S rb   )r7   rC   r   rz   r   r   rK   r   r   rD   r  r   r   )r   r8   r7   r   s       r=   visit_overloadedz TypeMeetVisitor.visit_overloaded  s     Fa&& 	+w!'!!!!'***Aq!! :Aq!! :!!*aj999)) 	+dfk.E 	+088D +!!T***!*a(((r?   r"   list[Type] | Nonec                n   t          |j                  }t          |j                  }|||                                |                                k    rgg }t          |                                          D ]A}|                    |                     |j        |         |j        |                              B|S dS |||                                |                                k    r||k    r|}|j        |         }t          |t                    sJ t          |j	                  }	|j        |         }
t          |
t                    sJ t          |
j	                  }t          |	t                    rt          |t                    sdS |                     |	|          }t          |t                    sdS g }t          |j        d|         |j        d|                   D ](\  }}|                    t          ||                     )g }t          |j        |dz   d         |j        |dz   d                   D ](\  }}|                    t          ||                     )|t          |          gz   |z   S dS ||}|}|}n
|J |}|}|}|j        |         }t          |t                    sJ t          |j	                  }t          |t                    sdS |                                |                                dz
  k     rdS |}|                                |z
  dz
  }t          t          |j                  ||          \  }}}g }t          ||j        d|                   D ].\  }}|                    |                     ||                     /|D ]6}|                    |                     ||j        d                              7|rMt          ||j        | d                   D ].\  }}|                    |                     ||                     /|S )a  Meet two tuple types while handling variadic entries.

        This is surprisingly tricky, and we don't handle some tricky corner cases.
        Most of the trickiness comes from the variadic tuple items like *tuple[X, ...]
        since they can have arbitrary partial overlaps (while *Ts can't be split). This
        function is roughly a mirror of join_tuples() w.r.t. to the fact that fixed
        tuples are subtypes of variadic ones but not vice versa.
        Nr   r   )r1   rz   r   ranger   r  rC   r0   r2   rD   r   r   rK   r6   tuplern   )r   r7   r8   s_unpack_indext_unpack_indexrz   iunpack_indexs_unpack
s_unpackedt_unpack
t_unpackedr  m_prefixsitim_suffixvariadicfixedunpackr   
prefix_len
suffix_lenr   middler   fivimis                                r=   meet_tupleszTypeMeetVisitor.meet_tuples  s;    -QW55,QW55!n&<xxzzQXXZZ''$&qxxzz** D DALL171:qwqz!B!BCCCC4%.*D xxzzQXXZZ''Nn,L,L-7<0!(J77777,X];;
7<0!(J77777,X];;
":x88  Z
T\=]=]  4yyZ88!$11  4')!!'-<-"8!'-<-:PQQ 8 8FBOOJr2$6$67777')!!',*:*<*<"=qw|VWGWGYGY?Z[[ 8 8FBOOJr2$6$67777:d#3#3"44x??4%H)LEE!---H)LE-&*-----"6;//(H-- 	4<<>>HOO--1114!
__&&3a7
!=%+
J"
 "
 &(.*"=>> 	, 	,FBLL2r**++++ 	: 	:BLL2x}Q'7889999 	0fhnj[\\&BCC 0 0BTYYr2..////r?   c                \    t           j        t                    rT                      j        |          }|                      j                  S t          |t          |                    S t           j        t                    r j        j        j        t          v r3 j        j
        r'|                     fd|j        D                       S t          | j                  r|S  j        j        j        rt          | j                  r|S                       j                  S )Nc                P    g | ]"}t          |j        j        d                    #S )r   )rK   r7   rn   )rR   r   r   s     r=   rV   z4TypeMeetVisitor.visit_tuple_type.<locals>.<listcomp>)  s,    -_-_-_QSjTV[^.L.L-_-_-_r?   r   )rC   r7   r"   rT  r  r   r   rD   rl   r   rn   rg   rz   r   r   r   )r   r8   rz   s   `  r=   visit_tuple_typez TypeMeetVisitor.visit_tuple_type  s   dfi(( 	$$TVQ//E}||DF+++UN1$5$5666)) 
	v{#'@@@TV[@-_-_-_-_WXW^-_-_-_```"1df-- 4 Atv9N9N  ||DF###r?   r%   c                   t          | j        t                    r | j                            |          D ]K\  }}}t	          ||          r||j        v || j        j        v k    r|                     | j                  c S Lg }| j                            |          D ];\  }}}||                    ||f            |J |                    ||f           <t          |          }	| j        
                                }
|j        | j        j        z  }|j        | j        j        z  }t          |	|||
          S t          | j        t                    rt          || j                  r|S |                     | j                  S rb   )rC   r7   r%   r   r   r   r  zipallr   dictcreate_anonymous_fallbackreadonly_keysr   r   )r   r8   namer   r   	item_list	item_names_item_typet_item_typerz   r   r   r\  s                r=   visit_typeddict_typez$TypeMeetVisitor.visit_typeddict_type3  s   dfm,, 	("fjjmm 0 0
a$Q** 0tq/FDF00/ /  <<////// 13I7;v}}Q7G7G ? ?3	;*$$i%=>>>> '222$$i%=>>>>OOEv7799HOdf.BBMOdf.BBM }hOOO)) 	(jDF.C.C 	(H<<'''r?   r   c                    t          | j        t                    r| j        |k    r|S t          | j        t                    rt	          |j        | j                  r|S |                     | j                  S rb   )rC   r7   r   r   r   r   r  r   s     r=   visit_literal_typez"TypeMeetVisitor.visit_literal_typeL  sg    dfk** 	(tv{{H)) 	(jTV.L.L 	(H<<'''r?   r    c                    J d            )NFzInternal errorrX   r   s     r=   visit_partial_typez"TypeMeetVisitor.visit_partial_typeT  s    &&&&&r?   r(   c                   t          | j        t                    rW|                     |j        | j        j                  }t          |t
                    st          j        ||j                  }|S t          | j        t                    r| j        j	        j
        dk    r|S t          | j        t                    r|                     || j                  S |                     | j                  S )N)liner   )rC   r7   r(   r  ri   r   rh   rh  r   rD   rl   r   r  )r   r8   rr   s      r=   visit_type_typezTypeMeetVisitor.visit_type_typeX  s    dfh'' 
	())AFDFK00Cc8,, A.s@@@J)) 	(dfk.Bo.U.UH-- 	(99Q'''<<'''r?   r$   c                    J d|             )NFz!This should be never called, got rX   r   s     r=   visit_type_alias_typez%TypeMeetVisitor.visit_type_alias_typee  s    ==!=====r?   r#   c                "    t          ||          S rb   )rK   )r   r7   r8   s      r=   r  zTypeMeetVisitor.meeth  s    !Qr?   rr   c                    t          |t                    rt          t          j                  S t
          j        rt                      S t                      S rb   )	rC   r-   r   r'   r   r   r;   r.   r   )r   rr   s     r=   r  zTypeMeetVisitor.defaultk  sF    c;'' 	"91222$ "&(((zz!r?   N)r7   r!   r9   r   )r8   r-   r9   r!   )r8   r   r9   r!   )r8   r/   r9   r!   )r8   r   r9   r!   )r8   r.   r9   r!   )r8   r   r9   r!   )r8   r   r9   r!   )r8   r+   r9   r!   )r8   r   r9   r!   )r8   r*   r9   r!   )r8   r0   r9   r!   )r8   r   r9   r!   )r8   r   r9   r!   )r8   r   r9   r!   )r8   r   r9   r!   )r7   r"   r8   r"   r9   r;  )r8   r"   r9   r!   )r8   r%   r9   r!   )r8   r   r9   r!   )r8   r    r9   r!   )r8   r(   r9   r!   )r8   r$   r9   r!   r7   r#   r8   r#   r9   r!   )rr   r#   r9   r!   )__name__
__module____qualname__r   r   r   r   r  r  r  r  r  r  r  r  r  r-  r8  r:  rT  rW  rb  rd  rf  ri  rk  r  r  rX   r?   r=   rJ   rJ     s          	3 	3 	3 	3   , , , ,	 	 	 	   	 	 	 	   ( ( ( (( ( ( (( ( ( (" " " "
( 
( 
( 
(S$ S$ S$ S$j$ $ $ $8) ) ) )&L L L L\$ $ $ $(( ( ( (2( ( ( (' ' ' '( ( ( (> > > >       " " " " " "r?   rJ   r   c                   ddl m}m}  || |          \  } }g }t          t	          | j                            D ]7}|                     || j        |         |j        |                              8| j        j        j	        dk    r| j        }n|j        }| 
                    |t          | j        |j                  |d           S )Nr   )match_generic_callables	safe_joinzbuiltins.function)r  r   r   r]  )r  rs  rt  r=  rF   r  r   r   rD   rl   rg   rK   r   )r8   r7   rs  rt  r  rA  r   s          r=   r1  r1  u  s    <<<<<<<<""1a((DAqI3q{##$$ D D1;q>1;q>BBCCCC 	z#666::??AJ
33	    r?   typesc                    | st          t          j                  S | d         }| dd          D ]}t          ||          }|S )Nr   r   )r   r'   rx   rK   )ru  metr8   s      r=   meet_type_listrx    sS     : y8999
(C122Y ! !a  Jr?   c                L   t          | |f          \  } }t          | t                    rt          |t                    rJ t          | t                    r| |}}nt          |t                    r|| }}ndS t          |t                    o|j                            d          S )a  Is this a pair where one type is a TypedDict and another one is an instance of Mapping?

    This case requires a precise/principled consideration because there are two use cases
    that push the boundary the opposite ways: we need to avoid spurious overlaps to avoid
    false positives for overloads, but we also need to avoid spuriously non-overlapping types
    to avoid false positives with --strict-equality.
    Ftyping.Mapping)r3   rC   r%   r   rD   r   )r   r   _r   s       r=   r   r     s     #D%=11KD%$..Vj6V6VVVV$&& 5	E=	)	) $5ueX&&P5:+>+>?O+P+PPr?   r   c                4  
 t          | |f          \  } }t          | t                    rt          |t                    rJ t          | t                    rt          |t                    sJ | |c
}n3t          | t                    sJ t          |t                    sJ || c
}t	          d |j        j        D             d          }|	
j        rdS t	          d |j        j        D                       }t          ||          }t          |j	                  \  }

                                j        }|j        j        d         j	        d         }t          |t                    rt          t                    r
j         S 
j        r0 ||          sdS t          
fd
j        D                       S  ||          sdS t!          
j                                                  
j        z
  }	t'          
fd|	D                       S )aS  Check if a TypedDict type is overlapping with a Mapping.

    The basic logic here consists of two rules:

    * A TypedDict with some required keys is overlapping with Mapping[str, <some type>]
      if and only if every key type is overlapping with <some type>. For example:

      - TypedDict(x=int, y=str) overlaps with Dict[str, Union[str, int]]
      - TypedDict(x=int, y=str) doesn't overlap with Dict[str, int]

      Note that any additional non-required keys can't change the above result.

    * A TypedDict with no required keys overlaps with Mapping[str, <some type>] if and
      only if at least one of key types overlaps with <some type>. For example:

      - TypedDict(x=str, y=str, total=False) overlaps with Dict[str, str]
      - TypedDict(x=str, y=str, total=False) doesn't overlap with Dict[str, int]
      - TypedDict(x=int, y=str, total=False) overlaps with Dict[str, str]

    * A TypedDict with at least one ReadOnly[] key does not overlap
      with Dict or MutableMapping, because they assume mutable data.

    As usual empty, dictionaries lie in a gray area. In general, List[str] and List[str]
    are considered non-overlapping despite empty list belongs to both. However, List[int]
    and List[Never] are considered overlapping.

    So here we follow the same logic: a TypedDict with no required keys is considered
    non-overlapping with Mapping[str, <some type>], but is considered overlapping with
    Mapping[Never, Never]. This way we avoid false positives for overloads, and also
    avoid false positives for comparisons like SomeTypedDict == {} under --strict-equality.
    c              3  0   K   | ]}|j         d k    |V  dS )ztyping.MutableMappingNrl   rR   bases     r=   rc   z-typed_dict_mapping_overlap.<locals>.<genexpr>  s/      UU$DM=T,T,T,T,T,T,TUUr?   NFc              3  0   K   | ]}|j         d k    |V  dS )rz  Nr~  r  s     r=   rc   z-typed_dict_mapping_overlap.<locals>.<genexpr>  s/      XXDdmGW6W6W46W6W6W6WXXr?   r   c              3  F   K   | ]} j         |                   V  d S rb   r   rR   kr   typed
value_types     r=   rc   z-typed_dict_mapping_overlap.<locals>.<genexpr>  s5      XXq;;u{1~z::XXXXXXr?   c              3  F   K   | ]} j         |                   V  d S rb   r   r  s     r=   rc   z-typed_dict_mapping_overlap.<locals>.<genexpr>  s5      QQq;;u{1~z::QQQQQQr?   )r3   rC   r%   r   nextrD   rw   r\  r   rn   as_anonymousr   basesr.   r   rm   r   rz   keysr   )r   r   r   r   mutable_mappingmappingkey_typer   str_typenon_requiredr  r  s     `       @@r=   r   r     sA   D #D%=11KD%$..Vj6V6VVVV$&& #%*****Uuu$)))))%/////duUU%*.UUUW[ O "u':"uXXEJNXXXXXG%eW55E+EJ77Hj !!##,H}"1%*1-H (O,, 'J1X1X '&&& R{8X.. 	5XXXXXXEDWXXXXXX{8X.. 	55;++--..1DDQQQQQQLQQQQQQr?   rn  )rL   r#   rM   r#   r9   r#   )rr   r#   r9   rs   )r[   r!   r|   r!   r9   r}   )r8   r!   r9   r}   )r   r!   r   r!   r9   r}   )
r   r#   r   r#   r   r}   rB   r}   r9   r}   )FFFN)r   r#   r   r#   rB   r}   r_   r}   r   r}   r   r   r9   r}   )r   r#   r   r#   rB   r}   r9   r}   )r   r%   r   r%   r   r   r9   r}   )r   r#   r   r#   r   r   r9   r}   )r   r"   r   r   r9   r"   )r   r!   r   r!   r9   r   )rr   r#   r9   r}   )r8   r   r7   r   r9   r   )ru  rs   r9   r#   r   )r   r#   r   r#   r   r   r9   r}   )S
__future__r   typingr   mypyr   mypy.erasetyper   mypy.maptyper   
mypy.stater   mypy.subtypesr	   r
   r   r   r   r   r   mypy.typeopsr   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/   r0   r1   r2   r3   r4   r5   r6   r>   rK   rQ   r{   rf   r   r   r   r   r   rP   r   r   r   r   r   r   rJ   r1  rx  r   r   rX   r?   r=   <module>r     s   " " " " " "             % % % % % % 2 2 2 2 2 2                        R Q Q Q Q Q Q Q Q Q% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %T
 
 
 
'( '( '( '(Tf f f fR/ / / /d
 
 
 
   L L L LH H H H   

 

 

 

  $*/"'04A A A A AJ
 ;@	 	 	 	 	 	   0!M !M !M !MH. . . .*      @" @" @" @" @"k*- @" @" @"F   ,   Q Q Q Q(GR GR GR GR GR GRr?   