Skip to content

Commit

Permalink
add test for step 4 in overload matching
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Jan 11, 2025
1 parent c041484 commit c10a72d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion conformance/results/mypy/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "mypy 1.14.1"
test_duration = 1.7
test_duration = 1.8
3 changes: 3 additions & 0 deletions conformance/results/pyre/overloads_evaluation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Does not expand boolean arguments to Literal[True] and Literal[False].
Does not expand enum arguments to literal variants.
Does not expand type[A | B] to type[A] and type[B].
Does not expand tuple arguments to possible combinations.
Does not prefer variadic match to indeterminate-length unpacked argument.
"""
conformance_automated = "Fail"
errors_diff = """
Expand All @@ -17,6 +18,7 @@ Line 144: Unexpected errors ['overloads_evaluation.py:144:29 Incompatible parame
Line 145: Unexpected errors ['overloads_evaluation.py:145:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
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]]`.']
Line 167: Unexpected errors ['overloads_evaluation.py:167:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
Line 193: Unexpected errors ['overloads_evaluation.py:193:4 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.']
"""
output = """
overloads_evaluation.py:27:0 Missing argument [20]: Call `example1` expects argument `x`.
Expand All @@ -34,4 +36,5 @@ overloads_evaluation.py:144:29 Incompatible parameter type [6]: In call `expand_
overloads_evaluation.py:145:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
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]]`.
overloads_evaluation.py:167:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
overloads_evaluation.py:193:4 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.
"""
2 changes: 1 addition & 1 deletion conformance/results/pyre/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyre 0.9.23"
test_duration = 5.9
test_duration = 6.0
2 changes: 1 addition & 1 deletion conformance/results/pyright/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyright 1.1.391"
test_duration = 1.5
test_duration = 1.6
6 changes: 6 additions & 0 deletions conformance/results/pytype/overloads_evaluation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Line 141: Unexpected errors ['overloads_evaluation.py:141:12: \\x1b[1m\\x1b[31me
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]']
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]']
Line 167: Unexpected errors ['overloads_evaluation.py:167:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_tuple: int [assert-type]']
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]']
"""
output = """
overloads_evaluation.py:23:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in example1: bad return type [bad-return-type]
Expand Down Expand Up @@ -120,4 +121,9 @@ overloads_evaluation.py:167:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in c
assert_type(ret1, int | str)
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
overloads_evaluation.py:185:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in variadic: bad return type [bad-return-type]
return 1
\u001b[1m\u001b[31m~\u001b[39m\u001b[0m
"""
2 changes: 1 addition & 1 deletion conformance/results/pytype/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pytype 2024.10.11"
test_duration = 31.0
test_duration = 31.2
10 changes: 5 additions & 5 deletions conformance/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ <h3>Python Type System Conformance Test Results</h3>
<div class="table_container"><table><tbody>
<tr><th class="col1">&nbsp;</th>
<th class='tc-header'><div class='tc-name'>mypy 1.14.1</div>
<div class='tc-time'>1.7sec</div>
<div class='tc-time'>1.8sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyright 1.1.391</div>
<div class='tc-time'>1.5sec</div>
<div class='tc-time'>1.6sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
<div class='tc-time'>5.9sec</div>
<div class='tc-time'>6.0sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
<div class='tc-time'>31.0sec</div>
<div class='tc-time'>31.2sec</div>
</th>
</tr>
<tr><th class="column" colspan="5">
Expand Down Expand Up @@ -693,7 +693,7 @@ <h3>Python Type System Conformance Test Results</h3>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_evaluation</th>
<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>
<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>
<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>
<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>
<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>
</tr>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_overlap</th>
Expand Down
25 changes: 25 additions & 0 deletions conformance/tests/overloads_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,28 @@ def check_expand_tuple(v: int | str) -> None:
ret1 = expand_tuple((1, v))
assert_type(ret1, int | str)


# > Step 4: If the argument list is compatible with two or more overloads,
# > determine whether one or more of the overloads has a variadic parameter
# > (either ``*args`` or ``**kwargs``) that maps to a corresponding argument
# > that supplies an indeterminate number of positional or keyword arguments.
# > If so, eliminate overloads that do not have a variadic parameter.

@overload
def variadic(x: int, /) -> Literal[0]:
...

@overload
def variadic(*args: int) -> int:
...

def variadic(*args: int) -> int | str:
return 1

# > - If this results in only one remaining candidate overload, it is
# > the winning match. Evaluate it as if it were a non-overloaded function
# > call and stop.

def check_variadic(v: list[int]) -> None:
ret1 = variadic(*v)
assert_type(ret1, int)

0 comments on commit c10a72d

Please sign in to comment.