
    X-Ph 6                        d Z ddlmZ ddlmZ ddlmZ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 ddlmZ dd	lmZmZmZmZ  G d
 de          ZddZddZ G d de          Z G d de          Z dS )z/Test cases for type inference helper functions.    )annotations)map_actuals_to_formals)DisjointDictgroup_comparison_operands)Key)	ARG_NAMEDARG_OPTARG_POSARG_STAR	ARG_STAR2ArgKindNameExpr)Suiteassert_equal)TypeFixture)AnyType	TupleTypeType	TypeOfAnyc                      e Zd ZdZd$dZd$dZd$dZd$dZd$dZd$d	Z	d$d
Z
d%dZd$dZd$dZd$dZd$dZd$dZd$dZd$dZd$dZd&dZd'd"Zd#S )(MapActualsToFormalsSuitez-Test cases for argmap.map_actuals_to_formals.returnNonec                4    |                      g g g            d S N)
assert_mapselfs    S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/test/testinfer.py
test_basicz#MapActualsToFormalsSuite.test_basic   s    B#####    c                    |                      t          gt          gdgg           |                      t          t          gt          t          gdgdgg           d S Nr      r   r
   r   s    r   test_positional_onlyz-MapActualsToFormalsSuite.test_positional_only   sN    	G9se444'*Wg,>!qc
KKKKKr!   c                    |                      g t          gg g           |                      t          gt          gdgg           |                      t          gt          t          gdgg g           d S Nr   )r   r	   r
   r   s    r   test_optionalz&MapActualsToFormalsSuite.test_optional   sc    WIt,,,	G9se444	GW#5RyAAAAAr!   c                    |                      g t          gg g           |                      t          gt          gdgg           |                      t          t          gt          gddgg           d S r#   )r   r   r
   r   s    r   test_callee_starz)MapActualsToFormalsSuite.test_callee_star   sc    XJ---	H:u555'*XJ!QAAAAAr!   c                \   |                      t          gt          gdgg           |                      t          t          gt          gddgg           |                      t          gt          t          gdgdgg           |                      t          gt          t          gdgdgg           d S r#   )r   r   r
   r	   r   s    r   test_caller_starz)MapActualsToFormalsSuite.test_caller_star"   s    
XJ!666(+hZ1a&BBB
Wh$71#sDDD
Wh$71#sDDDDDr!   c                    |                      t          gg g            |                      t          gg g            |                      t          gt          gdgg           d S r(   )r   r
   r   r   s    r   test_too_many_caller_argsz2MapActualsToFormalsSuite.test_too_many_caller_args(   sV    	2r***
B+++
WIu55555r!   c           	        t          t          j                  }|                     t          gt
          gdgg|                     |                     |                     t          gt
          t
          gdgdgg|                     ||                     |                     t          gt
          t          t          gdgdgg g|                     ||                     d S r(   )r   r   special_formassert_vararg_mapr   r
   
make_tupler	   )r   any_types     r   test_tuple_starz(MapActualsToFormalsSuite.test_tuple_star-   s    9122zG9seT__X=V=VWWWJ'*aS1#JRZ8[8[	
 	
 	
 	Jgw'S1#rNOOHh//		
 	
 	
 	
 	
r!   argsr   r   c                ^    t          t          |          t                      j                  S r   )r   listr   	std_tuple)r   r6   s     r   r3   z#MapActualsToFormalsSuite.make_tuple:   s    d[]]%<===r!   c                    |                      dgt          dfgdgg           |                      ddgt          dft          dfgdgdgg           d S )Nxr   yr$   r%   r   s    r   test_named_argsz(MapActualsToFormalsSuite.test_named_args=   sZ    #/1#777c
gs^gs^$DsQCjQQQQQr!   c                n    |                      dgt          dft          dft          dfgg dgg g           d S )Nr<   r;   zr   r   r	   r   s    r   test_some_named_argsz-MapActualsToFormalsSuite.test_some_named_argsA   s@    ###ORTWXVY[]Q^_____r!   c                H    |                      dgt          dfgg g           d S )Nr<   r;   r@   r   s    r   test_missing_named_argz/MapActualsToFormalsSuite.test_missing_named_argD   s)    #/"66666r!   c                N    |                      ddgt          dfgddgg           d S Nr;   r   r$   r@   r   s    r   test_duplicate_named_argz1MapActualsToFormalsSuite.test_duplicate_named_argG   s/    c
gs^$41vh?????r!   c                    |                      t          gt          t          dfgdgg g           |                      t          dgt          t          dfgdgdgg           d S rE   )r   r   r   r   s    r   test_varargs_and_bare_asteriskz7MapActualsToFormalsSuite.test_varargs_and_bare_asteriskJ   s\    
X	3/?$@A3)LLL3(Y4D)EaSzRRRRRr!   c                ^   |                      dgt          gdgg           |                      dt          gt          gddgg           |                      dt          gt          dft          gdgdgg           |                      t          t          gt          dft          gdgdgg           d S rE   )r   r   r
   r   s    r   test_keyword_varargsz-MapActualsToFormalsSuite.test_keyword_varargsN   s    	{aSE222i(9+Ax@@@i(GS>9*EaSzRRR),~y.IQCRSQT:VVVVVr!   c                x    |                      t          t          gt          dft          dfgddgddgg           d S )Nr;   r<   r   r$   r   r   r   r
   r   s    r   test_both_kinds_of_varargsz3MapActualsToFormalsSuite.test_both_kinds_of_varargsT   sC    9-##/OSTVWRX[\^_Z`Qabbbbbr!   c                l   |                      t          gt          t          gdgg g           |                      t          t          gt          t          gdgdgg           |                      t          gt          dft          gdgdgg           |                      t          gt          gdgg           d S )Nr   r$   r;   rL   r   s    r   test_special_casesz+MapActualsToFormalsSuite.test_special_casesW   s    
Xy$9QC9EEE9-)/DsQCjQQQwni%@A3*MMMi[A3%88888r!   caller_kinds_list[ArgKind | str]callee_kinds_#list[ArgKind | tuple[ArgKind, str]]expectedlist[list[int]]c                    t          |          \  }}t          |          \  }}t          ||||d           }t          ||           d S )Nc                4    t          t          j                  S r   )r   r   r1   )is    r   <lambda>z5MapActualsToFormalsSuite.assert_map.<locals>.<lambda>j   s    gi455 r!   )expand_caller_kindsexpand_callee_kindsr   r   )	r   rP   rR   rT   caller_kindscaller_namescallee_kindscallee_namesresults	            r   r   z#MapActualsToFormalsSuite.assert_map]   sa     &9%G%G"l%8%G%G"l'55
 
 	VX&&&&&r!   r\   list[ArgKind]r^   vararg_typec                T    t          |g |g fd          }t          ||           d S )Nc                    S r    )rX   rb   s    r   rY   z<MapActualsToFormalsSuite.assert_vararg_map.<locals>.<lambda>u   s    Va r!   )r   r   )r   r\   r^   rT   rb   r`   s       ` r   r2   z*MapActualsToFormalsSuite.assert_vararg_mapn   s:     (b,LaLaLaLabbVX&&&&&r!   Nr   r   )r6   r   r   r   )rP   rQ   rR   rS   rT   rU   r   r   )
r\   ra   r^   ra   rT   rU   rb   r   r   r   )__name__
__module____qualname____doc__r    r&   r)   r+   r-   r/   r5   r3   r=   rA   rC   rF   rH   rJ   rM   rO   r   r2   re   r!   r   r   r      s       77$ $ $ $L L L LB B B B
B B B B
E E E E6 6 6 6

 
 
 
> > > >R R R R` ` ` `7 7 7 7@ @ @ @S S S SW W W Wc c c c9 9 9 9' ' ' '"' ' ' ' ' 'r!   r   kinds_or_namesrQ   r   &tuple[list[ArgKind], list[str | None]]c                    g }g }| D ]q}t          |t                    r0|                    t                     |                    |           G|                    |           |                    d            r||fS r   )
isinstancestrappendr   )rk   kindsnamesks       r   rZ   rZ   y   s     E E  a 	LL###LLOOOOLLOOOLL%<r!   kinds_and_namesrS   c                   g }g }| D ]x}t          |t                    r7|                    |d                    |                    |d                    N|                    |           |                    d            y||fS r#   )rn   tuplerp   )rt   rq   rr   vs       r   r[   r[      s     E E  a 	LL1LL1LLOOOLL%<r!   c                  :    e Zd ZdZddZddZddZddZdd	Zd
S )OperandDisjointDictSuitezTTest cases for checker.DisjointDict, which is used for type inference with operands.r   DisjointDict[int, str]c                    t                      S r   )r   r   s    r   newzOperandDisjointDictSuite.new   s    ~~r!   r   c                8   |                                  }|                    ddhdh           |                    h ddh           |                    h ddh           |                     |                                ddhdhfh ddhfh ddhfg           d S )Nr   r$   group1            group2>            group3r|   add_mappingassertEqualitemsr   ds     r   test_independent_mapsz.OperandDisjointDictSuite.test_independent_maps   s    HHJJ	q!fxj)))	iii(,,,	iii(,,,GGII!Q(,yyy8*.E			T\S]G^_	
 	
 	
 	
 	
r!   c                   |                                  }|                    ddhdh           |                    ddhdh           |                    ddhdh           |                    d	dhd
h           |                    d	dhdh           |                    ddhdh           |                     |                                h dh dfh dddhfg           d S )Nr   r$   r~   r   r   r   r   r   r   group4r   group5r   group6>   r   r$   r   r   r   >   r~   r   r   r   >   r   r   r   r   r   s     r   test_partial_mergingz-OperandDisjointDictSuite.test_partial_merging   s   HHJJ	q!fxj)))	q!fxj)))	q!fxj)))	q!fxj)))	q!fxj)))	q!fxj)))GGII "J"J"JKXx01	
 	
 	
 	
 	
r!   c                   |                                  }|                    h ddh           |                    h ddh           |                    h ddh           |                    h ddh           |                    h d	d
h           |                    ddhdh           |                     |                                h dh dfg           d S )N   r   r$   r   ar   b>   
         c>            r   >   r   r      er   r   f>   r   r$   r   r   r   r   r   r   r   r   r   r   >   r   r   r   r   r   r   r   r   s     r   test_full_mergingz*OperandDisjointDictSuite.test_full_merging   s    HHJJ	iii#'''	iii#'''	lllSE***	lllSE***	lllSE***	q"gu%%%GGII999;Y;Y;YZ[	
 	
 	
 	
 	
r!   c                   |                                  }|                    h ddh           |                    h ddh           |                    h ddh           |                    h ddh           |                    h dd	h           |                     |                                h d
h dfg           d S )Nr   r   >   r   r   r   r   >   r$   r   r   r   r   >   r$   r   r   r   r   r   r   >   r   r$   r   r   r   r   r   >   r   r   r   r   r   r   r   s     r   !test_merge_with_multiple_overlapsz:OperandDisjointDictSuite.test_merge_with_multiple_overlaps   s    HHJJ	iii#'''	iii#'''	lllSE***	ooou---	ooou---&;&;&;=V=V=V%W$XYYYYYr!   N)r   rz   rf   )	rg   rh   ri   rj   r|   r   r   r   r   re   r!   r   ry   ry      s        ^^   
 
 
 

 
 
 
"
 
 
 
Z Z Z Z Z Zr!   ry   c                  J    e Zd ZdZddZddZdd	Zdd
ZddZddZ	ddZ
dS )OperandComparisonGroupingSuitez1Test cases for checker.group_comparison_operands.assignable_operandsdict[int, NameExpr]r   dict[int, Key]c                V    i }|                                 D ]\  }}d|j        f||<   |S )NFakeExpr)r   name)r   r   outputindexexprs        r   literal_keymapz-OperandComparisonGroupingSuite.literal_keymap   s=    !#.4466 	4 	4KE4'3F5MMr!   r   c           
        t          d          }t          d          }t          d          }t          d          }t          d          }d||fd||fd||fd||fg}|                     i           }|                     |||||d          }||fD ]}	|                     t          ||	t	                                dd	d
gfdd
dgfdddgfdddgfg           |                     t          ||	dh          dg dfdddgfdddgfg           |                     t          ||	dh          dd	d
gfdd
dgfdddgfdddgfg           |                     t          ||	ddh          dg dfdddgfdddgfg           d S )Nx0x1x2x3x4==<r   r$   r   r   r   r   r$   r   r   r   r   r$   r   )r   r   r   r   set)
r   r   r   r   r   r   basic_inputnone_assignableall_assignable
assignables
             r   test_basic_casesz/OperandComparisonGroupingSuite.test_basic_cases   s    d^^d^^d^^d^^d^^b"~b"~R}tRQSnU--b11,,rbR-P-PQQ*N; 	 	J)+z355IIA$A#1v1vO   )+zD6JJ			"S1a&MD1a&>B   )+zC5IIA$A#1v1vO   )+zD#;OO			"S1a&MD1a&>B   	 	r!   c                b   t          d          }t          d          }t          d          }t          d          }t          d          }t          d          }|                     t          d||fd||fd||fd||fg|                     i           ddh          dg d	fdg d
fg           |                     t          d||fd||fd||fd||fg|                     i           ddh          dg dfg           |                     t          d||fd||fd||fd||fg|                     i           ddh          dddgfdg dfg           |                     t          d||fd||fd||fd||fd||fg|                     i           ddh          dg d	fdddgfdg dfg           d S )Nr   r   r   r   r   x5r   isr   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   s          r   test_multiple_groupsz3OperandComparisonGroupingSuite.test_multiple_groups   sR   d^^d^^d^^d^^d^^d^^%B$B$B$BP##B''t 
 IIIyyy 12	
 	
 	
 	%B$B$B$BP##B''t 
 OOO$%	
 	
 	
 	%B$B$B$BP##B''t 
 QF^dLLL12	
 	
 	
 	%B$B#r2r2QUWY[]P^_##B''t 
 IIIq!fiii/@A	
 	
 	
 	
 	
r!   c                   t          d          }t          d          }t          d          }t          d          }t          d          }dg dfdd	d
gfdg dfg}dg dfdd	d
gfg}d||fd||fd||fd||fd||fg}|                     t          ||                     ||||||d          dh          |d           |                     t          ||                     ||||d          dh          |d           |                     t          ||                     ||||d          dh          |d           |                     t          ||                     ||d          dh          |d           d S )Nr   r   r   r   r   r   r   r   r   r   r   )r   r$   r   r   r   r   z/All vars are assignable, everything is combinedr   z#x0 is unassignable, so no combining)r   r$   r   r   z3Some vars are unassignable but x0 is, so we combine)r   r   z2All vars are unassignable but x0 is, so we combiner   )	r   r   r   r   r   r   nothing_combinedeverything_combined
two_groupss	            r   test_multiple_groups_coalescingz>OperandComparisonGroupingSuite.test_multiple_groups_coalescing#  s   d^^d^^d^^d^^d^^!999-aV}tYYY>OP $&8&8&89C!Q=I 2rN2rN"bM2rN2rN

 	%D//B2"PRWY0Z0Z[[^b]c   =	
 	
 	
 	%D//B2"0L0LMMPTv  1	
 	
 	
 	%D//B2"0L0LMMPTv   A	
 	
 	
 	%j$2E2E"QSnn2U2UX\W]^^@	
 	
 	
 	
 	
r!   c                <   t          d          }t          d          }t          d          }t          d          }d||fd||fd||fd||fg}|                     |||||d          }|                     t          ||ddh          dg dfdg d	fgd
           d S )Nr   r   r   r   r   r   r   r   r   z)Different operators can never be combined)r   r   r   r   )r   r   r   r   r   groupskeymaps          r   (test_multiple_groups_different_operatorszGOperandComparisonGroupingSuite.test_multiple_groups_different_operatorsP  s    d^^d^^d^^d^^R.4R.4R.4R.Q$$rbR%H%HII%fftTlCCIIIyyy 127	
 	
 	
 	
 	
r!   c           	     $   t          d          }t          d          }d||fg}dddgfg}i d|id|i||dg}t                      dhdhg}|D ]A}|D ]<}|                     |          }	|                     t	          ||	|          |           =Bd S )Nr   r   r   r   r$   )r   r$   r   )r   r   r   r   r   )
r   r   r   single_comparisonexpected_outputassignable_combinationsto_group_bycombo	operatorsr   s
             r   test_single_pairz/OperandComparisonGroupingSuite.test_single_pair^  s    d^^d^^"B^, 1a&>*>@1b'Ar7XZ_aTbTb=c'*uutftf&=, 	 	E(  	,,U33  -.?SS#   	 	r!   c                    |                      t          g i t                                g            |                      t          g i dh          g            d S )Nr   )r   r   r   r   s    r   test_empty_pair_listz3OperandComparisonGroupingSuite.test_empty_pair_listp  sV     	22r355AA2FFF22rD6BBBGGGGGr!   N)r   r   r   r   rf   )rg   rh   ri   rj   r   r   r   r   r   r   r   re   r!   r   r   r      s        ;;      @'
 '
 '
 '
R+
 +
 +
 +
Z
 
 
 
   $H H H H H Hr!   r   N)rk   rQ   r   rl   )rt   rS   r   rl   )!rj   
__future__r   mypy.argmapr   mypy.checkerr   r   mypy.literalsr   
mypy.nodesr   r	   r
   r   r   r   r   mypy.test.helpersr   r   mypy.test.typefixturer   
mypy.typesr   r   r   r   r   rZ   r[   ry   r   re   r!   r   <module>r      s   5 5 " " " " " " . . . . . . @ @ @ @ @ @ @ @       Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z 1 1 1 1 1 1 1 1 - - - - - - : : : : : : : : : : : :h' h' h' h' h'u h' h' h'V      7Z 7Z 7Z 7Z 7Zu 7Z 7Z 7ZtdH dH dH dH dHU dH dH dH dH dHr!   