
    *e                       d Z ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
mZmZ ddlmZ ddlmZmZmZmZmZmZ dd	lmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5  G d
 d          Z6d3dZ7d4dZ8e	 d5d6d            Z9ed5d7d            Z9d5d7dZ9 G d de-e#                   Z:d8dZ;d9dZ<d:d!Z=d;d"Z>d<d#Z?d<d$Z@d;d%ZAd=d(ZBd>d+ZCd?d-ZDd@d0ZEdAd2ZFdS )Bz3Calculation of the least upper bound types (joins).    )annotations)overloadN)map_instance_to_supertype)CONTRAVARIANT	COVARIANT	INVARIANT)state)SubtypeContextfind_memberis_equivalentis_proper_subtypeis_protocol_implementation
is_subtype)AnyTypeCallableTypeDeletedType
ErasedTypeFunctionLikeInstanceLiteralTypeNoneType
Overloaded
ParametersParamSpecTypePartialType
ProperType	TupleTypeTypeTypeAliasTypeTypedDictType	TypeOfAnyTypeTypeTypeVarLikeTypeTypeVarTupleTypeTypeVarTypeTypeVisitorUnboundTypeUninhabitedType	UnionType
UnpackTypefind_unpack_in_listget_proper_typeget_proper_typessplit_with_prefix_and_suffixc                  &    e Zd ZddZddZdd	Zd
S )InstanceJoinerreturnNonec                    g | _         d S N)seen_instances)selfs    )lib/python3.11/site-packages/mypy/join.py__init__zInstanceJoiner.__init__7   s    ?A    tr   sr   c                6	   ||f| j         v s||f| j         v rt          |          S | j                             ||f           |j        |j        k    rg }|j        j        r|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        }t!          |||j        j        j                  D ]\  }}}t#          |          }t#          |          }d }t          |t$                    rt%          t&          j        |          }n)t          |t$                    rt%          t&          j        |          }nt          |t*                    r|j        t.          k    rt1          |||           }t3          |j                  dk    r3||j        vr*| j                                          t          |          c S t9          ||j                  s*| j                                          t          |          c S n5|j        t<          t>          fv rKtA          ||          s*| j                                          t          |          c S t1          |||           }nt          |t                    rt#          t1          |||                     }t          |tB                    r"|j        j"        dk    sJ tG          |          }njt          |t                    sJ |$                    |j%                   JtA          ||          st#          |j                  c S t1          |||           }|J |                    |           tC          |j        |          }nY|j        j&        r7tO          ||tQ          d                    r| )                    ||          }n| )                    ||          }| j                                          |S )Nr   builtins.tupleT)ignore_type_params)subtype_context)*r5   object_from_instanceappendtypehas_type_var_tuple_typetype_var_tuple_prefixtype_var_tuple_suffixdefn	type_vars
isinstancer$   tuple_fallbackr.   argsr   listzipr,   r   r!   from_another_anyr%   variancer   
join_typeslenvaluespopr   upper_boundr   r   r   r   fullnamer*   extenditemsbasesr   r
   join_instances_via_supertype)r6   r:   r;   rJ   prefixsuffixtvtfallbacks_prefixs_middles_suffixt_prefixt_middlet_suffixs_argst_argstasatype_var	ta_proper	sa_propernew_typeresults                          r7   join_instanceszInstanceJoiner.join_instances:   s   q6T(((QFd6I,I,I'***""Aq6*** 6QV
  "D v-   v3???v3???55fk+F3!#'788888-/KAFTZ\b/c/c,(H/KAFTZ\b/c/c,(H!YtH~~x%H%H$JJXU!YtH~~x%H%H$JJXU$'8M$N$N ,& ,& B+B//	+B//	(,i11 &8&y'A9MMHH	733 $8&y'A9MMHH+66 "8(I55#-b"d#;#;x//1449X9X /33555#7#:#::::)(H4HII ; /33555#7#:#::::;
 "*y-.HHH,R44 ; /33555#7#:#:::: $.b"d#;#;*:;; 8.z"b$/G/GHHH "(H55 !'}59IIIII#-h#7#7)(I>>>>>HN333  )R00 E.x/CDDDDD)"b$77H+++H%%%%!)!&$!7!7FFV\ 	=/q.D"I"I"I
 
 
 	= 66q!<<FF
 66q!<<F!!!r9   c                   |j         j        D ]%}t          ||          rt          |||           c S &|j         j        D ]%}t          ||          rt          |||           c S &d }|j         j        D ]A}t          ||j                   }|                     ||          }|t          ||          r|}B|J |j         j        D ]?}t          |t                    r(|                     ||          }t          ||          r|}@|S r4   )
rB   _promoter   rO   rW   r   rl   	is_betterrH   r   )	r6   r:   r;   pbestbasemappedrespromotes	            r7   rX   z+InstanceJoiner.join_instances_via_supertype   sD     	. 	.A!Q .!!Q-----. 	. 	.A!Q .!!Q-----. #'FL 	 	D.q$)<<F%%fa00C|yd33|v 	 	G'8,, ))'155S$'' Dr9   N)r1   r2   )r:   r   r;   r   r1   r   )__name__
__module____qualname__r8   rl   rX    r9   r7   r0   r0   6   sY        B B B BZ Z Z Zx     r9   r0   declarationType | Noner;   r   r:   r1   r   c                   t          |           } t          |          }t          |          }|j        |j        f|j        |j        fk    r>t          j                            |          }t          j                            |          }t          |t                    r|S t          |t                    r|S t          ||d          r|S t          ||d          r|S t          | t                    r!t          j                            ||g          S t          |t                    rt          |t                    s||}}t          |t                    rt          |t                    s||}}t          ||          \  }}t          |t                    rt          |t                    s||}}|                    t!          |                    }| t#          ||           r|S | S )zReturn a simple least upper bound given the declared type.

    This function should be only used by binder, and should not recurse.
    For all other uses, use `join_types()`.
    T)ignore_promotions)r,   can_be_truecan_be_falsemypytypeopstrue_or_falserH   r   r   r   r)   make_simplified_unionr   r(   normalize_callablesacceptTypeJoinVisitorr   )rz   r;   r:   values       r7   join_simpler      s    "+..KAA	q~&1=!.*IIIL&&q))L&&q))!W !Z   A666 A666 +y)) :|111a&999!X z!X'>'> !1!_%% jO.L.L !1 q!$$DAq!Y 
1i(@(@ !1HH_Q''((Ej<<r9   c                    t          | |          r|S t          ||           r| S t          t          |                    S )zQReturn one of types (expanded) if it is a supertype of other, otherwise top type.)r   object_or_any_from_typer,   r;   r:   s     r7   trivial_joinr      sF    !Q ;	Aq		 ;&q'9'9:::r9   instance_joinerInstanceJoiner | Nonec                    d S r4   ry   r;   r:   r   s      r7   rO   rO      s	     Cr9   c                    d S r4   ry   r   s      r7   rO   rO      s    Cr9   c                2   t           j                            | |          rt          | |          S t	          |           } t	          |          }| j        | j        f|j        |j        fk    r>t           j                            |           } t           j                            |          }t          | t                    rt          |t                    s|| }} t          | t                    r| S t          | t                    r|S t          | t                    rt          |t                    s|| }} t          | t                    rt          |t                    s|| }} t          | |          \  } }|                    t!          | |                    S )zkReturn the least upper bound of s and t.

    For example, the join of 'int' and 'object' is 'object'.
    )r   r   is_recursive_pairr   r,   r~   r   r   rH   r)   r   r   r   r(   r   r   r   r   s      r7   rO   rO      sv   
 |%%a++ " Aq!!!AA	q~&1=!.*IIIL&&q))L&&q))!Y 
1i(@(@ !1!W !Z   !X z!X'>'> !1!_%% jO.L.L !1 q!$$DAq 88OA77888r9   c                      e Zd ZdZd: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dMd.ZdNd0ZdOd2ZdPd4ZdQd6ZdRd9ZdS )Sr   zpImplementation of the least upper bound algorithm.

    Attributes:
      s: The other (left) type operand.
    Nr;   r   r   r   r1   r2   c                "    || _         || _        d S r4   )r;   r   )r6   r;   r   s      r7   r8   zTypeJoinVisitor.__init__'  s    .r9   r:   r'   c                4    t          t          j                  S r4   )r   r!   special_formr6   r:   s     r7   visit_unbound_typez"TypeJoinVisitor.visit_unbound_type+  s    y-...r9   r)   c                |    t          | j        |          r|S t          j                            | j        |g          S r4   )r   r;   r   r   r   r   s     r7   visit_union_typez TypeJoinVisitor.visit_union_type.  s8    TVQ'' 	CH<55tvqkBBBr9   r   c                    |S r4   ry   r   s     r7   	visit_anyzTypeJoinVisitor.visit_any4  s    r9   r   c                    t           j        r|t          | j        t          t
          f          r|S t          | j        t                    rt          t          j	                  S t          j                            | j        |g          S | j        S r4   )r	   strict_optionalrH   r;   r   r(   r'   r   r!   r   r   r   r   r   s     r7   visit_none_typezTypeJoinVisitor.visit_none_type7  su      	$&8_"=>> GDFK00 Gy5666|99461+FFF6Mr9   r(   c                    | j         S r4   r;   r   s     r7   visit_uninhabited_typez&TypeJoinVisitor.visit_uninhabited_typeB  	    vr9   r   c                    | j         S r4   r   r   s     r7   visit_deleted_typez"TypeJoinVisitor.visit_deleted_typeE  r   r9   r   c                    | j         S r4   r   r   s     r7   visit_erased_typez!TypeJoinVisitor.visit_erased_typeH  r   r9   r%   c                    t          | j        t                    r| j        j        |j        k    r| j        S |                     | j                  S r4   )rH   r;   r%   iddefaultr   s     r7   visit_type_varzTypeJoinVisitor.visit_type_varK  sA    dfk** 	(tvyAD/@/@6M<<'''r9   r   c                P    | j         |k    r|S |                     | j                   S r4   r;   r   r   s     r7   visit_param_specz TypeJoinVisitor.visit_param_specQ  &    6Q;;H||DF###r9   r$   c                P    | j         |k    r|S |                     | j                   S r4   r   r   s     r7   visit_type_var_tuplez$TypeJoinVisitor.visit_type_var_tupleV  r   r9   r*   c                    t           r4   )NotImplementedErrorr   s     r7   visit_unpack_typez!TypeJoinVisitor.visit_unpack_type[  s    !!r9   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             t          | j        |                    S |                     | j                  S )Nr   
meet_typesc                .    g | ]\  }} ||          S ry   ry   ).0s_at_ar   s      r7   
<listcomp>z4TypeJoinVisitor.visit_parameters.<locals>.<listcomp>e  s6       -5S#JJsC((  r9   )	arg_types	arg_names)rH   r;   r   rP   r   r   	mypy.meetr   copy_modifiedrL   combine_arg_names)r6   r:   r   s     @r7   visit_parametersz TypeJoinVisitor.visit_parameters^  s    dfj)) 	(1;3tv'7#8#888||DF+++,,,,,,??   9<TV=Mq{9[9[   ,DFA66	 #    <<'''r9   r   c                   t          | j        t                    r| j        t	                      | _        | j                            || j                  }d }|j        j        rt          | j        |          r|}n-| j        j        j        rt          || j                  r| j        }|rt          ||          r|S |S t          | j        t                    rL|j        j        r&t          |          }|rt          || j                  S t          || j        j                  S t          | j        t                    rt          || j                  S t          | j        t                    rt          || j                  S t          | j        t                     rt          || j                  S t          | j        t"                    rt          || j                  S |                     | j                  S r4   )rH   r;   r   r   r0   rl   rB   is_protocolr   ro   r   unpack_callback_protocolrO   r\   r"   r    r   r   r   )r6   r:   nominal
structuralcalls        r7   visit_instancezTypeJoinVisitor.visit_instancem  s   dfh'' 	(#+'5'7'7$*99!TVDDG*.Jv! $&@&K&K $

( $-G46-R-R $!V
  7J!?!? -- 	(v! 4/22 4%dDF333a111)) 		(a(((.. 	(a(((	** 	(a(((,, 	(a(((<<'''r9   r   c                x   t          | j        t                    rt          || j                  rt	          || j                  rt          || j                  S t          || j                  }|                                r|                                j	        s>| j                                        r| j                                        j	        sd|_
        t          d t          |j                  D                       rt          |j        | j                  S |S t          | j        t                     rt          || j                  S t          | j        t"                    r7| j        j        j        r&t)          | j                  }|rt          ||          S t          |j        | j                  S )NTc              3  N   K   | ] }t          |t          t          f          V  !d S r4   )rH   r   r(   )r   tps     r7   	<genexpr>z6TypeJoinVisitor.visit_callable_type.<locals>.<genexpr>  sE         2/:;;     r9   )rH   r;   r   is_similar_callablesr   combine_similar_callablesjoin_similar_callablesis_type_objtype_objectis_abstractfrom_type_typeanyr-   r   rO   r\   r   r   rB   r   r   )r6   r:   rk   r   s       r7   visit_callable_typez#TypeJoinVisitor.visit_callable_type  s   dfl++ 	+0DQ0O0O 	+Q'' <0DF;;;+Atv66F -%&]]__%@-F&&((--1V-?-?-A-A-M- )-%  *6+;<<     6
 "!*df555M
++ 	+a((()) 	+dfk.E 	++DF33D +!!T***!*df---r9   r   c                r   g }| j         }t          |t                    r|j        D ]u}|j        D ]k}t	          ||          rYt          ||          r$|                    t          ||                     Ft          ||          r|                    |           lv|r*t          |          dk    r|d         S t          |          S t          |j        |j                  S t          |t                    r-|j        j        r!t!          |          }|rt          ||          S t          |j        |          S )N   r   )r;   rH   r   rV   r   r   rA   r   r   rP   r   rO   r\   r   rB   r   r   )r6   r:   rk   r;   t_items_itemr   s          r7   visit_overloadedz TypeJoinVisitor.visit_overloaded  sN   : &(Fa&& 	+' 2 2g 2 2F+FF;; 2(88 2"MM*CFF*S*STTTT'77 2"MM&1112  .v;;!##!!9$%f---aj!*5558$$ 	+); 	++A..D +!!T***!*a(((r9   r   list[Type] | Nonec           	        t          |j                  t          |j                  |                                |                                k    rag }t          |                                          D ];}|                    t          |j        |         |j        |                              <|S dS |j                 }t          |t                    sJ t          |j	                  }|j                 }t          |t                    sJ t          |j	                  }|                                |                                k    rk    r}	|                                z
  dz
  }
g }t          |j        d|	         |j        d|	                   D ](\  }}|                    t          ||                     )t          ||          }t          |t                    r#|                    t          |                     nt          |t                    r3|j	        j        dk    r#|                    t          |                     nt          |t                    r|j	        j        dk    sJ |}nt          |t                    sJ |j        }|                    t          |                    t!          |          g                               |
rUt          |j        |
 d         |j        |
 d                   D ](\  }}|                    t          ||                     )|S |                                dk    s|                                dk    rt          |t                    rt          |t                    sdS |j	        j        dk    sJ |j	        j        dk    sJ t          |j        d         |j        d                   }fdt%          |j                  D             }fdt%          |j                  D             }t'          ||z             }t          ||          }t          |                    |g                    g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 ](\  }}|                    t          ||                     )t'          t-          |                    }t          ||j        d                   }|                    t          |                    |g                               |
rGt          ||j        |
 d                   D ](\  }}|                    t          ||                     )|S )a<  Join 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).
        Nr   r=   )rJ   r   c                &    g | ]\  }}|k    |S ry   ry   )r   iat_unpack_indexs      r7   r   z/TypeJoinVisitor.join_tuples.<locals>.<listcomp>   '    SSSAqN?R?R1?R?R?Rr9   c                &    g | ]\  }}|k    |S ry   ry   )r   r   r   s_unpack_indexs      r7   r   z/TypeJoinVisitor.join_tuples.<locals>.<listcomp>!  r   r9   )r+   rV   lengthrangerA   rO   rH   r*   r,   rB   rL   r$   r   rT   rI   r   r@   rJ   	enumeratejoin_type_listr.   tuplerK   )r6   r;   r:   rV   r   s_unpack
s_unpackedt_unpack
t_unpacked
prefix_len
suffix_lensitijoinedtuple_instance
mid_joinedt_others_otherother_joinedvariadicunpack_indexfixedunpackunpackedrY   middlerZ   fivir   r   s                                @@r7   join_tupleszTypeJoinVisitor.join_tuples  s1    -QW55,QW55!n&<xxzzQXXZZ''$&qxxzz** E EALLAGAJ
!C!CDDDD4%.*Dw~.Hh
33333(77Jw~.Hh
33333(77JxxzzQXXZZ''Nn,L,L ,
XXZZ.81<
!!'+:+"68LMM 5 5FBLLB!3!34444#J
;;f&677 LLF!3!3444411 fk6JN^6^6^LLF!3!34444!*h77 C)7;KKKKK)3)*6FGGGGG)3)BLL"*88&:>&J&J%K 9       9"%agzkll&;QWj[\\=R"S"S 9 9BZB%7%78888xxzzQ!((**// #:x88  Z
T\=]=]  4!/3CCCCC!/3CCCCC'
(:JOA<NOO
SSSS17););SSSSSSS17););SSS-g.?@@'
LAA
":#;#;*#;#N#NOOPP4%H)LEE!---H)LE -&*-----"6;//(H-- 	4<<>>HOO--1114!
__&&3a7
!=%+
J"
 "
 &(.*"=>> 	- 	-FBLLB++,,,,#DLL11

HM!,<==
Z 6 6ZL 6 I IJJKKK 	1fhnj[\\&BCC 1 1BZB//0000r9   c                t   t          | j        t                    r| j        t	                      | _        | j                            t          j                            | j                  t          j                            |                    }t          |t                    sJ | 
                    | j        |          }|t          ||          S t          | j        |          r|S t          || j                  r| j        S |S t          | j        t          j                            |                    S r4   )rH   r;   r   r   r0   rl   r   r   rI   r   r  r   rO   )r6   r:   r\   rV   s       r7   visit_tuple_typez TypeJoinVisitor.visit_tuple_typeJ  s    dfi(( 	F#+'5'7'7$+::++DF33T\5P5PQR5S5S H h11111$$TVQ//E  111 %TVQ// H$Q// "6Mdfdl&A&A!&D&DEEEr9   r    c                    t           j        t                    r fd j                                      D             } j                                        }t          |                                          j        z   j        j        z  }t          |||          S t           j        t                    rt           j        j
                  S                       j                  S )Nc                p    i | ]2\  }}}t          ||          r|j        v |j        j        v k    /||3S ry   )r   required_keysr;   )r   	item_names_item_typet_item_typer6   r:   s       r7   
<dictcomp>z8TypeJoinVisitor.visit_typeddict_type.<locals>.<dictcomp>l  s^       9Y[!+{;;	
 #ao59H\;\]]	 ; ^]]r9   )rH   r;   r    rL   create_anonymous_fallbacksetkeysr  r   rO   r\   r   )r6   r:   rV   r\   r  s   ``   r7   visit_typeddict_typez$TypeJoinVisitor.visit_typeddict_typej  s    dfm,, 	(    =AVZZ]]  E v7799H  

--?$&BVVM x@@@)) 	(dfaj111<<'''r9   r   c                \   t          | j        t                    ry|| j        k    r|S | j        j        j        j        r7|j        j        j        r&t          j                            | j        |g          S t          | j        j        |j                  S t          | j        |j                  S r4   )
rH   r;   r   r\   rB   is_enumr   r   r   rO   r   s     r7   visit_literal_typez"TypeJoinVisitor.visit_literal_type~  s    dfk** 	2DF{{v#+ G
0G G|99461+FFFdfoqz:::dfaj111r9   r   c                    J d            )NFzInternal errorry   r   s     r7   visit_partial_typez"TypeJoinVisitor.visit_partial_type  s     	'&&&&r9   r"   c                F   t          | j        t                    r8t          j        t	          |j        | j        j                  |j                  S t          | j        t                    r| j        j        j	        dk    r| j        S | 
                    | j                  S )N)linezbuiltins.type)rH   r;   r"   make_normalizedrO   itemr  r   rB   rT   r   r   s     r7   visit_type_typezTypeJoinVisitor.visit_type_type  s    dfh'' 	(+Jqvtv{,K,KRSRXYYYY)) 	(dfk.Bo.U.U6M<<'''r9   r   c                    J d|             )NFz!This should be never called, got ry   r   s     r7   visit_type_alias_typez%TypeJoinVisitor.visit_type_alias_type  s    ==!=====r9   typr   c                   t          |          }t          |t                    rt          |          S t          |t                    rt          t          j                  S t          |t                    r2| 	                    t          j                            |                    S t          |t                    r| 	                    |j                  S t          |t                    r| 	                    |j                  S t          |t                     r| 	                    |j                  S t          |t$                    r| 	                    |j                  S t          t          j                  S r4   )r,   rH   r   r@   r'   r   r!   r   r   r   r   r   rI   r    r\   r   r%   rS   r   )r6   r  s     r7   r   zTypeJoinVisitor.default  s/   c""c8$$ 	3',,,[)) 	391222Y'' 	3<< ; ;C @ @AAA]++ 		3<<---\** 	3<<---[)) 	3<<000]++ 	3<<00091222r9   r4   )r;   r   r   r   r1   r2   )r:   r'   r1   r   )r:   r)   r1   r   )r:   r   r1   r   )r:   r   r1   r   )r:   r(   r1   r   )r:   r   r1   r   )r:   r   r1   r   )r:   r%   r1   r   )r:   r   r1   r   )r:   r$   r1   r   )r:   r*   r1   r*   )r:   r   r1   r   )r:   r   r1   r   )r:   r   r1   r   )r:   r   r1   r   )r;   r   r:   r   r1   r   )r:   r   r1   r   )r:   r    r1   r   )r:   r   r1   r   )r:   r   r1   r   )r:   r"   r1   r   )r:   r   r1   r   )r  r   r1   r   )rv   rw   rx   __doc__r8   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r   ry   r9   r7   r   r      s        / / / / // / / /C C C C   	 	 	 	         ( ( ( ($ $ $ $
$ $ $ $
" " " "( ( ( (( ( ( (B. . . .83) 3) 3) 3)ji i i iVF F F F@( ( ( ((2 2 2 2' ' ' '
( ( ( (> > > >3 3 3 3 3 3r9   r   boolc                   t          |           } t          |          }t          | t                    rMt          |t                    sdS t          | j        j                  t          |j        j                  k    rdS dS )NTF)r,   rH   r   rP   rB   mror:   r;   s     r7   ro   ro     sp     	AA!X !X&& 	4qvz??S__,,45r9   tuple[ProperType, ProperType]c                    t          | t          t          f          r|                                 } t          |t          t          f          r|                                }| |fS r4   )rH   r   r   with_unpacked_kwargsr   s     r7   r   r     s[    !lJ/00 %""$$!lJ/00 %""$$a4Kr9   r   c                    t          | j                  t          |j                  k    o| j        |j        k    o| j        |j        k    S )zcReturn True if t and s have identical numbers of
    arguments, default arguments and varargs.
    )rP   r   min_args
is_var_argr!  s     r7   r   r     sG    
 	AKC,,, 	)J!*$	)LAL(r9   c                   g }t          t          | j                            D ];}|                    t	          | j        |         |j        |                              <| j        j        j        dk    r| j        }n|j        }|                     |t          | |          t          | j        |j                  |d           S Nzbuiltins.function)r   r   ret_typer\   name)r   rP   r   rA   	safe_meetr\   rB   rT   r   r   rO   r*  r:   r;   r   r   r\   s        r7   r   r     s    I3q{##$$ D D1;q>1;q>BBCCCC 	z#666::??#Aq))AJ
33    r9   c                P   t          | t                    s%t          |t                    st          | |          S t          | t                    r<t          |t                    r't          t          | j        |j                            S t	          t          |                     S r4   )rH   r*   rO   rB   r   r,   r!  s     r7   	safe_joinr/    s     a$$  Z:-F-F  !Q!Z   6Z:%>%> 6*QVQV44555"?1#5#5666r9   c                   ddl m} t          | t                    s!t          |t                    s || |          S t          | t                    rt          |t                    rt	          | j                  }t          |t                    r|j        j        }nPt          |t                    r|j	        j        }n.t          |t                    r|j        j        dk    sJ |j        } || j        |j                  }t          |t                    rt          ||g          }t          |          S t                      S )Nr   r   r=   )r   r   rH   r*   r,   rB   r$   rI   r   partial_fallbackr   rT   r(   )r:   r;   r   r   fallback_typert   s         r7   r,  r,    s7   $$$$$$a$$  Z:-F-F  z!Q!Z   Z:%>%> "16**h 011 	*$38MM),, 	*$5:MMh11`hm6LP`6`6`6`6`$MMj((c?++ 	1=3%00C#r9   c                   g }t          t          | j                            D ];}|                    t	          | j        |         |j        |                              <| j        j        j        dk    r| j        }n|j        }|                     |t          | |          t          | j        |j                  |d           S r)  )r   rP   r   rA   r/  r\   rB   rT   r   r   rO   r*  r-  s        r7   r   r     s    I3q{##$$ D D1;q>1;q>BBCCCC
 	z#666::??#Aq))AJ
33    r9   CallableType | Parameterslist[str | None]c                h   t          | j                  }g }t          |          D ]}| j        |         }|j        |         }||k    s>| j        |                                         s|j        |                                         r|                    |           v|                    d           |S )aL  Produces a list of argument names compatible with both callables.

    For example, suppose 't' and 's' have the following signatures:

    - t: (a: int, b: str, X: str) -> None
    - s: (a: int, b: str, Y: str) -> None

    This function would return ["a", "b", None]. This information
    is then used above to compute the join of t and s, which results
    in a signature of (a: int, b: str, str) -> None.

    Note that the third argument's name is omitted and 't' and 's'
    are both valid subtypes of this inferred signature.

    Precondition: is_similar_types(t, s) is true.
    N)rP   r   r   r   	arg_kindsis_namedrA   )r:   r;   num_args	new_namesr   t_names_names          r7   r   r     s    & 1;HI8__ # #QQVq{1~6688AKN<S<S<U<UV$$$$T""""r9   instancer   c                F    t          | j        j        d         g           }|S )z;Construct the type 'builtins.object' from an instance type.)r   rB   r   )r=  rt   s     r7   r@   r@   6  s"     8=$R("
-
-CJr9   r  c                8   t          | t                    rt          |           S t          | t          t          t
          f          rt          | j                  S t          | t                    rt          | j                  S t          | t                    rt          | j                  S t          | t                    r.t          | j        t                    rt          | j                  S t          | t                    rH| j        D ]?}t          |t                    r(t          |          }t          |t                    r|c S @n6t          | t"                    r!t          t%          | j                             t)          t*          j                  S r4   )rH   r   r@   r   r    r   r\   r   r1  r"   r   r  r#   rS   r   r)   rV   r*   r,   rB   r   r!   implementation_artifact)r  r  	candidates      r7   r   r   =  sj    #x   ;#C(((	C,{C	D	D ;#CL111	C	#	# ;#C$8999	C	"	" ;&sx000	C	)	) 	;j*.U.U 	;&s777	C	#	# ;I 	% 	%D$
++ %3D99	i22 %$$$$		%
 
C	$	$ ; 9 9:::94555r9   types
list[Type]c                p    | st                      S | d         }| dd          D ]}t          ||          }|S )Nr   r   )r(   rO   )rC  r   r:   s      r7   r   r   U  sN     !    1XF122Y ' 'FA&&Mr9   ProperType | Nonec                    | j         j        sJ | j         j        dgk    r t          t	          d| | d                    S d S )N__call__T)is_operator)rB   r   protocol_membersr,   r   )r:   s    r7   r   r   `  sI    6v:,..{:q!NNNOOO4r9   )rz   r{   r;   r   r:   r   r1   r   )r;   r   r:   r   r1   r   r4   )r;   r   r:   r   r   r   r1   r   )r;   r   r:   r   r   r   r1   r   )r:   r   r;   r   r1   r  )r;   r   r:   r   r1   r"  )r:   r   r;   r   r1   r  )r:   r   r;   r   r1   r   )r:   r   r;   r   r1   r   )r:   r4  r;   r4  r1   r5  )r=  r   r1   r   )r  r   r1   r   )rC  rD  r1   r   )r:   r   r1   rF  )Gr  
__future__r   typingr   mypy.typeopsr   mypy.maptyper   
mypy.nodesr   r   r   
mypy.stater	   mypy.subtypesr
   r   r   r   r   r   
mypy.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r0   r   r   rO   r   ro   r   r   r   r/  r,  r   r   r@   r   r   r   ry   r9   r7   <module>rS     s   9 9 " " " " " "           2 2 2 2 2 2 : : : : : : : : : :                                                                                                                                                        Fy y y y y y y yx. . . .b; ; ; ; 
KO    
 
    
$9 $9 $9 $9 $9NI3 I3 I3 I3 I3k*- I3 I3 I3X            (7 7 7 7   ,   *   >   6 6 6 60        r9   