Skip to content

Commit c10a72d

Browse files
committed
add test for step 4 in overload matching
1 parent c041484 commit c10a72d

File tree

8 files changed

+43
-9
lines changed

8 files changed

+43
-9
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "mypy 1.14.1"
2-
test_duration = 1.7
2+
test_duration = 1.8

conformance/results/pyre/overloads_evaluation.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Does not expand boolean arguments to Literal[True] and Literal[False].
44
Does not expand enum arguments to literal variants.
55
Does not expand type[A | B] to type[A] and type[B].
66
Does not expand tuple arguments to possible combinations.
7+
Does not prefer variadic match to indeterminate-length unpacked argument.
78
"""
89
conformance_automated = "Fail"
910
errors_diff = """
@@ -17,6 +18,7 @@ Line 144: Unexpected errors ['overloads_evaluation.py:144:29 Incompatible parame
1718
Line 145: Unexpected errors ['overloads_evaluation.py:145:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
1819
Line 166: Unexpected errors ['overloads_evaluation.py:166:24 Incompatible parameter type [6]: In call `expand_tuple`, for 1st positional argument, expected `Tuple[int, int]` but got `Tuple[int, Union[int, str]]`.']
1920
Line 167: Unexpected errors ['overloads_evaluation.py:167:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
21+
Line 193: Unexpected errors ['overloads_evaluation.py:193:4 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.']
2022
"""
2123
output = """
2224
overloads_evaluation.py:27:0 Missing argument [20]: Call `example1` expects argument `x`.
@@ -34,4 +36,5 @@ overloads_evaluation.py:144:29 Incompatible parameter type [6]: In call `expand_
3436
overloads_evaluation.py:145:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
3537
overloads_evaluation.py:166:24 Incompatible parameter type [6]: In call `expand_tuple`, for 1st positional argument, expected `Tuple[int, int]` but got `Tuple[int, Union[int, str]]`.
3638
overloads_evaluation.py:167:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
39+
overloads_evaluation.py:193:4 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.
3740
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyre 0.9.23"
2-
test_duration = 5.9
2+
test_duration = 6.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyright 1.1.391"
2-
test_duration = 1.5
2+
test_duration = 1.6

conformance/results/pytype/overloads_evaluation.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Line 141: Unexpected errors ['overloads_evaluation.py:141:12: \\x1b[1m\\x1b[31me
2121
Line 145: Unexpected errors ['overloads_evaluation.py:145:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_type_union: int [assert-type]']
2222
Line 163: Unexpected errors ['overloads_evaluation.py:163:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in expand_tuple: bad return type [bad-return-type]']
2323
Line 167: Unexpected errors ['overloads_evaluation.py:167:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_tuple: int [assert-type]']
24+
Line 185: Unexpected errors ['overloads_evaluation.py:185:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in variadic: bad return type [bad-return-type]']
2425
"""
2526
output = """
2627
overloads_evaluation.py:23:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in example1: bad return type [bad-return-type]
@@ -120,4 +121,9 @@ overloads_evaluation.py:167:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in c
120121
assert_type(ret1, int | str)
121122
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
122123
124+
overloads_evaluation.py:185:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in variadic: bad return type [bad-return-type]
125+
126+
return 1
127+
\u001b[1m\u001b[31m~\u001b[39m\u001b[0m
128+
123129
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pytype 2024.10.11"
2-
test_duration = 31.0
2+
test_duration = 31.2

conformance/results/results.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ <h3>Python Type System Conformance Test Results</h3>
159159
<div class="table_container"><table><tbody>
160160
<tr><th class="col1">&nbsp;</th>
161161
<th class='tc-header'><div class='tc-name'>mypy 1.14.1</div>
162-
<div class='tc-time'>1.7sec</div>
162+
<div class='tc-time'>1.8sec</div>
163163
</th>
164164
<th class='tc-header'><div class='tc-name'>pyright 1.1.391</div>
165-
<div class='tc-time'>1.5sec</div>
165+
<div class='tc-time'>1.6sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
168-
<div class='tc-time'>5.9sec</div>
168+
<div class='tc-time'>6.0sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
171-
<div class='tc-time'>31.0sec</div>
171+
<div class='tc-time'>31.2sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">
@@ -693,7 +693,7 @@ <h3>Python Type System Conformance Test Results</h3>
693693
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_evaluation</th>
694694
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not pick a winning overload based on arity, prior to considering argument types.</p><p>Does not expand boolean arguments to Literal[True] and Literal[False].</p><p>Does not expand enum arguments to literal variants.</p><p>Does not expand tuple arguments to possible combinations.</p></span></div></th>
695695
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not expand boolean arguments to Literal[True] and Literal[False].</p><p>Does not expand enum arguments to literal variants.</p><p>Does not expand tuple arguments to possible combinations.</p></span></div></th>
696-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not expand boolean arguments to Literal[True] and Literal[False].</p><p>Does not expand enum arguments to literal variants.</p><p>Does not expand type[A | B] to type[A] and type[B].</p><p>Does not expand tuple arguments to possible combinations.</p></span></div></th>
696+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not expand boolean arguments to Literal[True] and Literal[False].</p><p>Does not expand enum arguments to literal variants.</p><p>Does not expand type[A | B] to type[A] and type[B].</p><p>Does not expand tuple arguments to possible combinations.</p><p>Does not prefer variadic match to indeterminate-length unpacked argument.</p></span></div></th>
697697
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not pick a winning overload based on arity, prior to considering argument types.</p><p>Does not perform argument expansion (on any types) when matching overloads.</p></span></div></th>
698698
</tr>
699699
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_overlap</th>

conformance/tests/overloads_evaluation.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,28 @@ def check_expand_tuple(v: int | str) -> None:
166166
ret1 = expand_tuple((1, v))
167167
assert_type(ret1, int | str)
168168

169+
170+
# > Step 4: If the argument list is compatible with two or more overloads,
171+
# > determine whether one or more of the overloads has a variadic parameter
172+
# > (either ``*args`` or ``**kwargs``) that maps to a corresponding argument
173+
# > that supplies an indeterminate number of positional or keyword arguments.
174+
# > If so, eliminate overloads that do not have a variadic parameter.
175+
176+
@overload
177+
def variadic(x: int, /) -> Literal[0]:
178+
...
179+
180+
@overload
181+
def variadic(*args: int) -> int:
182+
...
183+
184+
def variadic(*args: int) -> int | str:
185+
return 1
186+
187+
# > - If this results in only one remaining candidate overload, it is
188+
# > the winning match. Evaluate it as if it were a non-overloaded function
189+
# > call and stop.
190+
191+
def check_variadic(v: list[int]) -> None:
192+
ret1 = variadic(*v)
193+
assert_type(ret1, int)

0 commit comments

Comments
 (0)