Skip to content

Commit 8a98eae

Browse files
committed
add test for steps 5/6 in overload matching
1 parent c10a72d commit 8a98eae

File tree

7 files changed

+53
-9
lines changed

7 files changed

+53
-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.8
2+
test_duration = 1.7

conformance/results/pyre/overloads_evaluation.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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.
77
Does not prefer variadic match to indeterminate-length unpacked argument.
8+
Does not treat multiple matches due to gradual types as ambiguous.
89
"""
910
conformance_automated = "Fail"
1011
errors_diff = """
@@ -19,6 +20,7 @@ Line 145: Unexpected errors ['overloads_evaluation.py:145:4 Assert type [70]: Ex
1920
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]]`.']
2021
Line 167: Unexpected errors ['overloads_evaluation.py:167:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
2122
Line 193: Unexpected errors ['overloads_evaluation.py:193:4 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.']
23+
Line 221: Unexpected errors ['overloads_evaluation.py:221:4 Assert type [70]: Expected `typing.Any` but got `int`.']
2224
"""
2325
output = """
2426
overloads_evaluation.py:27:0 Missing argument [20]: Call `example1` expects argument `x`.
@@ -37,4 +39,5 @@ overloads_evaluation.py:145:4 Assert type [70]: Expected `Union[int, str]` but g
3739
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]]`.
3840
overloads_evaluation.py:167:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
3941
overloads_evaluation.py:193:4 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.
42+
overloads_evaluation.py:221:4 Assert type [70]: Expected `typing.Any` but got `int`.
4043
"""
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 = 6.0
2+
test_duration = 6.1

conformance/results/pytype/overloads_evaluation.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ conformant = "Partial"
22
notes = """
33
Does not pick a winning overload based on arity, prior to considering argument types.
44
Does not perform argument expansion (on any types) when matching overloads.
5+
Does not treat multiple matches due to gradual types as ambiguous.
56
"""
67
conformance_automated = "Fail"
78
errors_diff = """
@@ -22,6 +23,8 @@ Line 145: Unexpected errors ['overloads_evaluation.py:145:5: \\x1b[1m\\x1b[31mer
2223
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]']
2324
Line 167: Unexpected errors ['overloads_evaluation.py:167:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_tuple: int [assert-type]']
2425
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]']
26+
Line 214: Unexpected errors ['overloads_evaluation.py:214:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in example4: bad return type [bad-return-type]']
27+
Line 221: Unexpected errors ['overloads_evaluation.py:221:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_example4: int [assert-type]']
2528
"""
2629
output = """
2730
overloads_evaluation.py:23:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in example1: bad return type [bad-return-type]
@@ -126,4 +129,14 @@ overloads_evaluation.py:185:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in
126129
return 1
127130
\u001b[1m\u001b[31m~\u001b[39m\u001b[0m
128131
132+
overloads_evaluation.py:214:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in example4: bad return type [bad-return-type]
133+
134+
return 1
135+
\u001b[1m\u001b[31m~\u001b[39m\u001b[0m
136+
137+
overloads_evaluation.py:221:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in check_example4: int [assert-type]
138+
139+
assert_type(ret2, Any)
140+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
141+
129142
"""
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.2
2+
test_duration = 31.1

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.8sec</div>
162+
<div class='tc-time'>1.7sec</div>
163163
</th>
164164
<th class='tc-header'><div class='tc-name'>pyright 1.1.391</div>
165165
<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'>6.0sec</div>
168+
<div class='tc-time'>6.1sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
171-
<div class='tc-time'>31.2sec</div>
171+
<div class='tc-time'>31.1sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">
@@ -693,8 +693,8 @@ <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><p>Does not prefer variadic match to indeterminate-length unpacked argument.</p></span></div></th>
697-
<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>
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><p>Does not treat multiple matches due to gradual types as ambiguous.</p></span></div></th>
697+
<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><p>Does not treat multiple matches due to gradual types as ambiguous.</p></span></div></th>
698698
</tr>
699699
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_overlap</th>
700700
<th class="column col2 conformant">Pass</th>

conformance/tests/overloads_evaluation.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
from enum import Enum
6-
from typing import assert_type, Literal, overload
6+
from typing import Any, assert_type, Literal, overload
77

88

99
# > Step 1: Examine the argument list to determine the number of
@@ -191,3 +191,31 @@ def variadic(*args: int) -> int | str:
191191
def check_variadic(v: list[int]) -> None:
192192
ret1 = variadic(*v)
193193
assert_type(ret1, int)
194+
195+
196+
# > Step 5: For each argument, determine whether all possible
197+
# > :term:`materializations <materialize>` of the argument's type are assignable to
198+
# > the corresponding parameter type for each of the remaining overloads. If so,
199+
# > eliminate all of the subsequent remaining overloads.
200+
201+
@overload
202+
def example4(x: list[int], y: int) -> int:
203+
...
204+
205+
@overload
206+
def example4(x: list[str], y: str) -> int:
207+
...
208+
209+
@overload
210+
def example4(x: int, y: int) -> list[int]:
211+
...
212+
213+
def example4(x: list[int] | list[str] | int, y: int | str) -> int | list[int]:
214+
return 1
215+
216+
def check_example4(v1: list[Any], v2: Any):
217+
ret1 = example4(v1, v2)
218+
assert_type(ret1, int)
219+
220+
ret2 = example4(v2, 1)
221+
assert_type(ret2, Any)

0 commit comments

Comments
 (0)