11"""Test cases for type inference helper functions."""
22
3- import typing
3+ from typing import List , Optional , Tuple , Union
44
55from mypy .myunit import Suite , assert_equal , assert_true
66from mypy .checkexpr import map_actuals_to_formals
77from mypy .nodes import ARG_POS , ARG_OPT , ARG_STAR , ARG_STAR2 , ARG_NAMED
8- from mypy .types import AnyType , TupleType
8+ from mypy .types import AnyType , TupleType , Type
99
1010
1111class MapActualsToFormalsSuite (Suite ):
1212 """Test cases for checkexpr.map_actuals_to_formals."""
1313
14- def test_basic (self ):
14+ def test_basic (self ) -> None :
1515 self .assert_map ([], [], [])
1616
17- def test_positional_only (self ):
17+ def test_positional_only (self ) -> None :
1818 self .assert_map ([ARG_POS ],
1919 [ARG_POS ],
2020 [[0 ]])
2121 self .assert_map ([ARG_POS , ARG_POS ],
2222 [ARG_POS , ARG_POS ],
2323 [[0 ], [1 ]])
2424
25- def test_optional (self ):
25+ def test_optional (self ) -> None :
2626 self .assert_map ([],
2727 [ARG_OPT ],
2828 [[]])
@@ -33,7 +33,7 @@ def test_optional(self):
3333 [ARG_OPT , ARG_OPT ],
3434 [[0 ], []])
3535
36- def test_callee_star (self ):
36+ def test_callee_star (self ) -> None :
3737 self .assert_map ([],
3838 [ARG_STAR ],
3939 [[]])
@@ -44,7 +44,7 @@ def test_callee_star(self):
4444 [ARG_STAR ],
4545 [[0 , 1 ]])
4646
47- def test_caller_star (self ):
47+ def test_caller_star (self ) -> None :
4848 self .assert_map ([ARG_STAR ],
4949 [ARG_STAR ],
5050 [[0 ]])
@@ -58,7 +58,7 @@ def test_caller_star(self):
5858 [ARG_OPT , ARG_STAR ],
5959 [[0 ], [0 ]])
6060
61- def test_too_many_caller_args (self ):
61+ def test_too_many_caller_args (self ) -> None :
6262 self .assert_map ([ARG_POS ],
6363 [],
6464 [])
@@ -69,7 +69,7 @@ def test_too_many_caller_args(self):
6969 [ARG_POS ],
7070 [[0 ]])
7171
72- def test_tuple_star (self ):
72+ def test_tuple_star (self ) -> None :
7373 self .assert_vararg_map (
7474 [ARG_STAR ],
7575 [ARG_POS ],
@@ -86,10 +86,10 @@ def test_tuple_star(self):
8686 [[0 ], [0 ], []],
8787 self .tuple (AnyType (), AnyType ()))
8888
89- def tuple (self , * args ) :
90- return TupleType (args , None )
89+ def tuple (self , * args : Type ) -> TupleType :
90+ return TupleType (list ( args ) , None )
9191
92- def test_named_args (self ):
92+ def test_named_args (self ) -> None :
9393 self .assert_map (
9494 ['x' ],
9595 [(ARG_POS , 'x' )],
@@ -99,25 +99,25 @@ def test_named_args(self):
9999 [(ARG_POS , 'x' ), (ARG_POS , 'y' )],
100100 [[1 ], [0 ]])
101101
102- def test_some_named_args (self ):
102+ def test_some_named_args (self ) -> None :
103103 self .assert_map (
104104 ['y' ],
105105 [(ARG_OPT , 'x' ), (ARG_OPT , 'y' ), (ARG_OPT , 'z' )],
106106 [[], [0 ], []])
107107
108- def test_missing_named_arg (self ):
108+ def test_missing_named_arg (self ) -> None :
109109 self .assert_map (
110110 ['y' ],
111111 [(ARG_OPT , 'x' )],
112112 [[]])
113113
114- def test_duplicate_named_arg (self ):
114+ def test_duplicate_named_arg (self ) -> None :
115115 self .assert_map (
116116 ['x' , 'x' ],
117117 [(ARG_OPT , 'x' )],
118118 [[0 , 1 ]])
119119
120- def test_varargs_and_bare_asterisk (self ):
120+ def test_varargs_and_bare_asterisk (self ) -> None :
121121 self .assert_map (
122122 [ARG_STAR ],
123123 [ARG_STAR , (ARG_NAMED , 'x' )],
@@ -127,7 +127,7 @@ def test_varargs_and_bare_asterisk(self):
127127 [ARG_STAR , (ARG_NAMED , 'x' )],
128128 [[0 ], [1 ]])
129129
130- def test_keyword_varargs (self ):
130+ def test_keyword_varargs (self ) -> None :
131131 self .assert_map (
132132 ['x' ],
133133 [ARG_STAR2 ],
@@ -145,13 +145,13 @@ def test_keyword_varargs(self):
145145 [(ARG_POS , 'x' ), ARG_STAR2 ],
146146 [[0 ], [1 ]])
147147
148- def test_both_kinds_of_varargs (self ):
148+ def test_both_kinds_of_varargs (self ) -> None :
149149 self .assert_map (
150150 [ARG_STAR , ARG_STAR2 ],
151151 [(ARG_POS , 'x' ), (ARG_POS , 'y' )],
152152 [[0 , 1 ], [0 , 1 ]])
153153
154- def test_special_cases (self ):
154+ def test_special_cases (self ) -> None :
155155 self .assert_map ([ARG_STAR ],
156156 [ARG_STAR , ARG_STAR2 ],
157157 [[0 ], []])
@@ -165,9 +165,13 @@ def test_special_cases(self):
165165 [ARG_STAR2 ],
166166 [[0 ]])
167167
168- def assert_map (self , caller_kinds , callee_kinds , expected ):
169- caller_kinds , caller_names = expand_caller_kinds (caller_kinds )
170- callee_kinds , callee_names = expand_callee_kinds (callee_kinds )
168+ def assert_map (self ,
169+ caller_kinds_ : List [Union [int , str ]],
170+ callee_kinds_ : List [Union [int , Tuple [int , str ]]],
171+ expected : List [List [int ]],
172+ ) -> None :
173+ caller_kinds , caller_names = expand_caller_kinds (caller_kinds_ )
174+ callee_kinds , callee_names = expand_callee_kinds (callee_kinds_ )
171175 result = map_actuals_to_formals (
172176 caller_kinds ,
173177 caller_names ,
@@ -176,8 +180,12 @@ def assert_map(self, caller_kinds, callee_kinds, expected):
176180 lambda i : AnyType ())
177181 assert_equal (result , expected )
178182
179- def assert_vararg_map (self , caller_kinds , callee_kinds , expected ,
180- vararg_type ):
183+ def assert_vararg_map (self ,
184+ caller_kinds : List [int ],
185+ callee_kinds : List [int ],
186+ expected : List [List [int ]],
187+ vararg_type : Type ,
188+ ) -> None :
181189 result = map_actuals_to_formals (
182190 caller_kinds ,
183191 [],
@@ -187,7 +195,8 @@ def assert_vararg_map(self, caller_kinds, callee_kinds, expected,
187195 assert_equal (result , expected )
188196
189197
190- def expand_caller_kinds (kinds_or_names ):
198+ def expand_caller_kinds (kinds_or_names : List [Union [int , str ]]
199+ ) -> Tuple [List [int ], List [Optional [str ]]]:
191200 kinds = []
192201 names = []
193202 for k in kinds_or_names :
@@ -200,7 +209,8 @@ def expand_caller_kinds(kinds_or_names):
200209 return kinds , names
201210
202211
203- def expand_callee_kinds (kinds_and_names ):
212+ def expand_callee_kinds (kinds_and_names : List [Union [int , Tuple [int , str ]]]
213+ ) -> Tuple [List [int ], List [Optional [str ]]]:
204214 kinds = []
205215 names = []
206216 for v in kinds_and_names :
0 commit comments