
    X-Ph                       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; d@dZ<d@dZ=dAdZ>dBdZ?dCdZ@dCdZAdDdZB	 	 	 	 dEdFd&ZCdd'dGd(ZDdHd,ZEdId-ZFdJd2ZGdKd5ZHdLd6ZI G d7 d8e2e'                   ZJdMd:ZKdNd<ZLdOd=ZMdPd?ZNdS )Q    )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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   r6   r7   s     I/var/www/html/test/jupyter/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_typesrJ   I   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j        S  }}t                      t                     k    r|S t           t                    r-t          fd                                 D                       S t                     rDt          t                    sJ t           fd                                D                       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          t*                    rj                                        r|S t           t*                    rY j        j        r|S t          t*                    r&j        j        rj        j        j         j        u r|S t3          ||          S t           t4          t"          t6          f          rt3          ||          S t           t8                    rbt          t*                    rMj        j        dk    r-t=          d t?          j                   D                       r|S t3          ||          S |S )z7Return the declared type narrowed down to another type.c                x    g | ]6}t          |d           st          |d          &t          |          7S )Tr@   F)is_overlapping_typesr   narrow_declared_type).0xrL   s     r<   
<listcomp>z(narrow_declared_type.<locals>.<listcomp>   sc        )HMMM "(AGGG$Q11  r>   c                0    g | ]}t          |          S  rP   rQ   rR   rK   s     r<   rS   z(narrow_declared_type.<locals>.<listcomp>   $    RRR1!(A..RRRr>   T)prohibit_none_typevar_overlapc                0    g | ]}t          |          S rU   rV   rW   s     r<   rS   z(narrow_declared_type.<locals>.<listcomp>   rX   r>   zbuiltins.dictc              3  @   K   | ]}t          |t                    V  d S N)rB   r   )rQ   r7   s     r<   	<genexpr>z'narrow_declared_type.<locals>.<genexpr>   s=       =
 =
'(Jq'""=
 =
 =
 =
 =
 =
r>   )!rB   r&   
type_guardr2   r/   r   relevant_itemsis_enum_overlapping_unionrO   r   r:   r.   r   r   r+   r   upper_boundr(   make_normalizedrP   itemr   rC   is_metaclassalt_promoterJ   r"   r   r%   fullnameallr3   args)rK   rL   original_declaredoriginal_narroweds   ``  r<   rP   rP   s   s    (O,, #""  x((Hx((H8  (I&& 
$   !0022  
 
 	
 !844 2@ (I.....$RRRR8O8O8Q8QRRR
 
 	
 "(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   rB   r+   rE   valuesra   r   r   rC   mror   r'   implementation_artifactr*   r/   listitemsr   )rk   ra   s     r<   get_possible_variantsrt      s   2 #

C#{## sz??Q:O$$	C	'	' %co66k8,, 	<[-1"5r::;;	9::;;	C)	*	* 	  	C	#	# CI	C	$	$  CIur>   rR   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 r\   )rB   r2   r   rC   fallback)rQ   zprR   s     r<   r]   z,is_enum_overlapping_union.<locals>.<genexpr>   s^       
 
 OA...q<<Z1:?AZ
 
 
 
 
 
r>   )rB   r   rC   is_enumr/   anyr_   )rR   ru   r{   s   ` @r<   r`   r`      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 r\   )r2   )rQ   rz   rR   s     r<   r]   z&is_literal_in_union.<locals>.<genexpr>  s0      99A_Q'''999999r>   )rB   r   r/   r}   rs   )rR   ru   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)rB   r   rC   rf   )r7   s    r<   	is_objectr     s!    a""Kqv:K'KKr>   FNleftrightrA   rY   overlap_for_overloads
seen_typesset[tuple[Type, Type]] | Nonec                   t          | t                    st          |t                    rdS t                      | |fv rdS t          | t                    r,t          |t                    r                    | |f           t          | |f          \  } }dfd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 dd}r || |          s |||           rd	S dfd} || |          s |||           rdS t'          |           }	t'          |          }
dd}r || |          s |||           rd	S t)          |	          dk    s=t)          |
          dk    s*t          | t*                    st          |t*                    r|	D ]}|
D ]} ||          r  dS d	S t          j        r.t          | t,                    t          |t,                    k    rd	S t          | t.                    r&t          |t.                    rt1          | |          S t3          | |          rt5          | |          S t          | t.                    r| j        } nt          |t.                    r|j        }t9          |           r t9          |          rt;          | |          S t          | t<                    rt?          |           } n$t          |t<                    rt?          |          }t          | t@                    r+t          |t@                    r | j!        |j!                  S dfd}t          | t@                    st          |t@                    r || |          p |||           S t          | tD                    r+t          |tD                    rtG          | |d	 d          S t          | tD                    st          |tD                    rd	S t          | tH                    r+t          |tH                    rtK          | |d	 d          S d}d}t          | tH                    r*t          |tL                    rtO          d||d          }| }t          |tH                    r*t          | tL                    rtO          d| | d          }|}t          tQ          |          tR                    r||J  ||          S t          | tH                    r| j        } t          |tH                    r|j        }t          | tT                    r6t          |tT                    r!| j+        |j+        k    r| j        } |j        }n;d	S t          | tT                    r| j        } nt          |tT                    r|j        }t          | tL                    rt          |tL                    r || |          s |||           rdS |j,        j-        dk    r| j,        j-        t\          v rdS | j,        /                    |j,        j-                  rta          | |j,                  } n<|j,        /                    | j,        j-                  rta          || j,                  }nd	S |j,        j1        r|j,        j2        J |j,        j3        J |j,        j2        }|j,        j3        }|j,        j4        j5        |         }t          |tl                    sJ |j        }to          | j8        ||          \  }}}to          |j8        ||          \  }}}|t=          ts          |          |          fz   |z   }|t=          ts          |          |          fz   |z   }n| j8        }|j8        }t)          |          t)          |          k    r+tu          fdtw          ||          D                       rdS d	S tY          |           tY          |          k    s)J tY          |            dtY          |                       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.
    TNr   r#   r   r8   rv   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.
        )rA   rY   r   r   )rO   copy)r   r   rA   r   rY   r   s     r<   _is_overlapping_typesz3is_overlapping_types.<locals>._is_overlapping_types3  s8    
 $/*G"7!((
 
 
 	
r>   Fz%Unexpectedly encountered partial typet1t2c                    t          | |f          \  } }t          | t                    o$t          |t                    o|j        j        dk    S r   )r3   rB   r   r   rC   rf   r   r   s     r<   is_none_object_overlapz4is_overlapping_types.<locals>.is_none_object_overlapn  sN    !2r(++Br8$$ 62x((6 $55	
r>   c                P    rt          | |          S t          | |          S )Nr@   )r   r   )r   r   rA   r   s     r<   _is_subtypez)is_overlapping_types.<locals>._is_subtypez  s8      	P$T5DUVVVVdE=NOOOOr>   c                ~    t          | |f          \  } }t          | t                    ot          |t                    S r\   )r3   rB   r   r)   r   s     r<   is_none_typevarlike_overlapz9is_overlapping_types.<locals>.is_none_typevarlike_overlap  s6    !2r(++B"h''KJr?,K,KKr>      )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   rB   r(   r   rc   ret_typer   rC   metaclass_typehas_baser   )r   r   	left_metar   s      r<   _type_object_overlapz2is_overlapping_types.<locals>._type_object_overlap  s     'e}55edH%% 	D*UL*I*I 	D((ENCCCdH%% 	<*UH*E*E 	<$)X.. < IN9	(00EBBBz**?;;;DIw// <z**?;;;ur>   )	is_compatr   ignore_pos_arg_namesallow_partial_overlap__call__)is_operatorzbuiltins.intc              3  6   K   | ]\  }} ||          V  d S r\   rU   )rQ   left_arg	right_argr   s      r<   r]   z'is_overlapping_types.<locals>.<genexpr>T  sH        'Hi &%h	::     r>   z vs r   r#   r   r#   r8   rv   )r   r#   r   r#   r8   rv   )<rB   r&   setr$   addr3   r    r-   r   r   r   r:   r/   
make_unionr_   r   r   r`   r   rt   rE   r)   r   r%   are_typed_dicts_overlappingtyped_dict_mapping_pairtyped_dict_mapping_overlapry   is_tupleare_tuples_overlappingr"   r   r(   rc   r   r	   r   r   r   r
   r2   r   r   valuerC   rf   r   r   r   has_type_var_tuple_typetype_var_tuple_prefixtype_var_tuple_suffixdefn	type_varsr*   r5   rh   rr   rg   zip)r   r   rA   rY   r   r   illegal_typesr   r   left_possibleright_possibler   lrr   callotherprefixsuffixtvtry   left_prefixleft_middleleft_suffixright_prefixright_middleright_suffix	left_args
right_argsr   s     ````                       @r<   rO   rO     s
   " $(( J- -  tUU
e}
""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
 
 
 
  !!$.. 	2H2HPT2U2U 	5P P P P P P P {4 ;;ud#;#; t
 *$//M*511NL L L L % &&tU33 	7R7RSXZ^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 : ;tU## 	{{5$'?'? 	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>   r@   c               \    t          t          |           t          |          |d          S )zMThe same as 'is_overlapping_erased_types', except the types are erased first.T)rA   rY   )rO   r   )r   r   rA   s      r<   is_overlapping_erased_typesr   f  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_keysrs   )r   r   r   keys       r<   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 r\   rU   )rQ   r   r   r   s      r<   r]   z)are_tuples_overlapping.<locals>.<genexpr>  s3      MM1~~a##MMMMMMr>   builtins.tupleT)r3   adjust_tuplerB   r"   r1   rs   expand_tuple_if_possiblerE   rg   r   r4   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   rs   )rE   rs   rB   r0   appendr2   rC   r*   r   r   rf   extendrh   copy_modified)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)rB   r   rC   rf   r"   lengthrh   )r   r   ns      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   rB   r"   r   rC   rf   )rk   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 )QrI   r6   r!   r8   Nonec                    || _         d S r\   r6   )selfr6   s     r<   __init__zTypeMeetVisitor.__init__  s    r>   r7   r-   c                    t          | j        t                    r!t          j        rt                      S | j        S t          | j        t
                    r| j        S t          t          j                  S r\   )	rB   r6   r   r   r:   r.   r   r'   special_formr   r7   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 r\   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 rU   )rJ   r6   )rQ   rR   r   s     r<   rS   z4TypeMeetVisitor.visit_union_type.<locals>.<listcomp>  s%    <<<qZ46**<<<r>   )rB   r6   r/   rs   r   rJ   r   )r   r7   meetsrR   ru   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:   rB   r6   r   r   rC   rf   r.   r   s     r<   visit_none_typezTypeMeetVisitor.visit_none_type  s^      	$&(++ )468,,)151EIZ1Z1Z&(((Hr>   r.   c                    |S r\   rU   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 r\   )rB   r6   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 r\   r   r   s     r<   visit_erased_typez!TypeMeetVisitor.visit_erased_type  r   r>   r+   c                    t          | j        t                    r| j        j        |j        k    r| j        S |                     | j                  S r\   )rB   r6   r+   iddefaultr   s     r<   visit_type_varzTypeMeetVisitor.visit_type_var
  sA    dfk** 	(tvyAD/@/@6M<<'''r>   r   c                Z    | j         |k    r| j         S |                     | j                   S r\   )r6   r  r   s     r<   visit_param_specz TypeMeetVisitor.visit_param_spec  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 r\   )rB   r6   r*   r  min_lenr  r   s     r<   visit_type_var_tuplez$TypeMeetVisitor.visit_type_var_tuple  sW    df.// 	(DFI4E4E!V^ai77466Q><<'''r>   r0   c                    t           r\   )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 rU   rU   )rQ   s_at_ar  s      r<   rS   z4TypeMeetVisitor.visit_parameters.<locals>.<listcomp>&  s)    cccHC::c3//cccr>   )	arg_types)
rB   r6   r   rE   r  r  	mypy.joinr  r   r   )r   r7   r  s     @r<   visit_parametersz TypeMeetVisitor.visit_parameters  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)rh   )(rB   r6   r   rC   r   r   r   r   r   r   r*   r   r5   rh   r"   rr   r   meetr   rs   r.   r0   r   r   r   r:   r   re   r   is_protocolr   unpack_callback_protocolrJ   is_type_objrd   ry   r  r(   r   r%   )r   r7   rh   r6   r   r   r   ry   s_prefixs_middles_suffixt_prefixt_middlet_suffixs_argst_argstasatvr  re   r   s                         r<   visit_instancezTypeMeetVisitor.visit_instance+  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)rB   r6   r   r   is_similar_callablesr   combine_similar_callablesmeet_similar_callablesr  type_objectis_abstractfrom_type_typer2   r   r.   r  r(   
is_genericrJ   rc   r   rb   r   rC   r  r  )r   r7   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 r\   )r6   rB   r   rs   r   r   rJ   ry   r   rC   r  r   r  )r   r7   r6   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   rs   r   ranger   r  rB   r0   r2   rC   r   r   rJ   r5   tuplerh   )r   r6   r7   s_unpack_indext_unpack_indexrs   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   )rJ   r6   rh   )rQ   r   r   s     r<   rS   z4TypeMeetVisitor.visit_tuple_type.<locals>.<listcomp>  s,    -_-_-_QSjTV[^.L.L-_-_-_r>   r   )rB   r6   r"   rN  r  r   r   rC   rf   r   rh   r   rs   r   r   r   )r   r7   rs   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 r\   )rB   r6   r%   r   r   r   r  zipallr   dictcreate_anonymous_fallbackreadonly_keysr   r   )r   r7   namer   r   	item_list	item_names_item_typet_item_typers   ry   r   rV  s                r<   visit_typeddict_typez$TypeMeetVisitor.visit_typeddict_type  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 r\   )rB   r6   r   r   r   ry   r  r   s     r<   visit_literal_typez"TypeMeetVisitor.visit_literal_type*  sg    dfk** 	(tv{{H)) 	(jTV.L.L 	(H<<'''r>   r    c                    J d            )NFzInternal errorrU   r   s     r<   visit_partial_typez"TypeMeetVisitor.visit_partial_type2  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   )rB   r6   r(   r  rc   r   rb   rb  r   rC   rf   r   r  )r   r7   rk   s      r<   visit_type_typezTypeMeetVisitor.visit_type_type6  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 rU   r   s     r<   visit_type_alias_typez%TypeMeetVisitor.visit_type_alias_typeC  s    ==!=====r>   r#   c                "    t          ||          S r\   )rJ   )r   r6   r7   s      r<   r  zTypeMeetVisitor.meetF  s    !Qr>   rk   c                    t          |t                    rt          t          j                  S t
          j        rt                      S t                      S r\   )	rB   r-   r   r'   r   r   r:   r.   r   )r   rk   s     r<   r  zTypeMeetVisitor.defaultI  sF    c;'' 	"91222$ "&(((zz!r>   N)r6   r!   r8   r   )r7   r-   r8   r!   )r7   r   r8   r!   )r7   r/   r8   r!   )r7   r   r8   r!   )r7   r.   r8   r!   )r7   r   r8   r!   )r7   r   r8   r!   )r7   r+   r8   r!   )r7   r   r8   r!   )r7   r*   r8   r!   )r7   r0   r8   r!   )r7   r   r8   r!   )r7   r   r8   r!   )r7   r   r8   r!   )r7   r   r8   r!   )r6   r"   r7   r"   r8   r5  )r7   r"   r8   r!   )r7   r%   r8   r!   )r7   r   r8   r!   )r7   r    r8   r!   )r7   r(   r8   r!   )r7   r$   r8   r!   r6   r#   r7   r#   r8   r!   )rk   r#   r8   r!   )__name__
__module____qualname__r   r   r   r   r   r   r   r  r  r  r  r  r  r'  r2  r4  rN  rQ  r\  r^  r`  rc  re  r  r  rU   r>   r<   rI   rI     s          	3 	3 	3 	3   , , , ,	 	 	 	   	 	 	 	   ( ( ( (( ( ( (( ( ( (" " " "
( 
( 
( 
(S$ S$ S$ S$j$ $ $ $8) ) ) )&L L L L\$ $ $ $(( ( ( (2( ( ( (' ' ' '( ( ( (> > > >       " " " " " "r>   rI   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   ry   rW  )r  rm  rn  r7  rE   r  r   ry   rC   rf   r   rJ   r   )r7   r6   rm  rn  r  r;  ry   s          r<   r+  r+  S  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'   rq   rJ   )ro  metr7   s      r<   meet_type_listrr  i  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   rB   r%   r   rC   r   )r   r   _r   s       r<   r   r   t  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rf   rQ   bases     r<   r]   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 )rt  Nrx  ry  s     r<   r]   z-typed_dict_mapping_overlap.<locals>.<genexpr>  s/      XXDdmGW6W6W46W6W6W6WXXr>   r   c              3  F   K   | ]} j         |                   V  d S r\   r   rQ   kr   typed
value_types     r<   r]   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 r\   r   r}  s     r<   r]   z-typed_dict_mapping_overlap.<locals>.<genexpr>  s5      QQq;;u{1~z::QQQQQQr>   )r3   rB   r%   r   nextrC   rp   rV  r   rh   as_anonymousry   basesr.   r   rg   r   rs   keysr}   )r   r   r   r   mutable_mappingmappingkey_typery   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>   rh  )rK   r#   rL   r#   r8   r#   )rk   r#   r8   rl   )rR   r!   ru   r!   r8   rv   )r7   r!   r8   rv   )FFFN)r   r#   r   r#   rA   rv   rY   rv   r   rv   r   r   r8   rv   )r   r#   r   r#   rA   rv   r8   rv   )r   r%   r   r%   r   r   r8   rv   )r   r#   r   r#   r   r   r8   rv   )r   r"   r   r   r8   r"   )r   r!   r   r!   r8   r   )rk   r#   r8   rv   )r7   r   r6   r   r8   r   )ro  rl   r8   r#   r   )r   r#   r   r#   r   r   r8   rv   )O
__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   r=   rJ   rP   rt   r`   r   r   rO   r   r   r   r   r   r   rI   r+  rr  r   r   rU   r>   r<   <module>r     sR   " " " " " "             % % % % % % 2 2 2 2 2 2                        R Q Q Q Q Q Q Q Q Q$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $R
 
 
 
'( '( '( '(TQ Q Q Qh/ / / /d
 
 
 
   L L L L $*/"'04P P P P Ph
 ;@	 	 	 	 	 	   0!M !M !M !MH. . . .*      ~" ~" ~" ~" ~"k*- ~" ~" ~"B   ,   Q Q Q Q(GR GR GR GR GR GRr>   