Skip to content

Commit 17d3e15

Browse files
committed
add tests for step-1 of overload evaluation
1 parent cc748d3 commit 17d3e15

File tree

8 files changed

+144
-4
lines changed

8 files changed

+144
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
conformant = "Partial"
2+
notes = """
3+
Does not pick a winning overload based on arity, prior to considering argument types.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
7+
Line 36: Unexpected errors ['overloads_evaluation.py:36: error: Expression is of type "Any", not "int" [assert-type]']
8+
Line 42: Unexpected errors ['overloads_evaluation.py:42: error: Expression is of type "Any", not "str" [assert-type]']
9+
"""
10+
output = """
11+
overloads_evaluation.py:26: error: All overload variants of "num_args" require at least one argument [call-overload]
12+
overloads_evaluation.py:26: note: Possible overload variants:
13+
overloads_evaluation.py:26: note: def num_args(x: int, y: str) -> int
14+
overloads_evaluation.py:26: note: def num_args(x: str) -> str
15+
overloads_evaluation.py:35: error: No overload variant of "num_args" matches argument types "int", "int" [call-overload]
16+
overloads_evaluation.py:35: note: Possible overload variants:
17+
overloads_evaluation.py:35: note: def num_args(x: int, y: str) -> int
18+
overloads_evaluation.py:35: note: def num_args(x: str) -> str
19+
overloads_evaluation.py:36: error: Expression is of type "Any", not "int" [assert-type]
20+
overloads_evaluation.py:41: error: No overload variant of "num_args" matches argument type "int" [call-overload]
21+
overloads_evaluation.py:41: note: Possible overload variants:
22+
overloads_evaluation.py:41: note: def num_args(x: int, y: str) -> int
23+
overloads_evaluation.py:41: note: def num_args(x: str) -> str
24+
overloads_evaluation.py:42: error: Expression is of type "Any", not "str" [assert-type]
25+
"""
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
3+
errors_diff = """
4+
"""
5+
output = """
6+
overloads_evaluation.py:26:0 Missing argument [20]: Call `num_args` expects argument `x`.
7+
overloads_evaluation.py:35:19 Incompatible parameter type [6]: In call `num_args`, for 2nd positional argument, expected `str` but got `int`.
8+
overloads_evaluation.py:41:16 Incompatible parameter type [6]: In call `num_args`, for 1st positional argument, expected `str` but got `int`.
9+
"""
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.6
2+
test_duration = 6.7
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
3+
errors_diff = """
4+
"""
5+
output = """
6+
overloads_evaluation.py:26:1 - error: No overloads for "num_args" match the provided arguments
7+
  Argument types: () (reportCallIssue)
8+
overloads_evaluation.py:35:20 - error: Argument of type "Literal[1]" cannot be assigned to parameter "y" of type "str" in function "num_args"
9+
  "Literal[1]" is not assignable to "str" (reportArgumentType)
10+
overloads_evaluation.py:41:17 - error: Argument of type "Literal[1]" cannot be assigned to parameter "x" of type "str" in function "num_args"
11+
  "Literal[1]" is not assignable to "str" (reportArgumentType)
12+
"""
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
conformant = "Partial"
2+
notes = """
3+
Does not pick a winning overload based on arity, prior to considering argument types.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
7+
Line 24: Unexpected errors ['overloads_evaluation.py:24:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in num_args: bad return type [bad-return-type]']
8+
Line 36: Unexpected errors ['overloads_evaluation.py:36:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: Any [assert-type]']
9+
Line 42: Unexpected errors ['overloads_evaluation.py:42:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: Any [assert-type]']
10+
"""
11+
output = """
12+
overloads_evaluation.py:24:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in num_args: bad return type [bad-return-type]
13+
14+
return 1
15+
\u001b[1m\u001b[31m~\u001b[39m\u001b[0m
16+
17+
Called from (traceback):
18+
line 38, in current file
19+
overloads_evaluation.py:26:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Missing parameter 'x' in call to function num_args [missing-parameter]
20+
21+
num_args() # E: no matching overload
22+
\u001b[1m\u001b[31m~~~~~~~~~~\u001b[39m\u001b[0m
23+
24+
overloads_evaluation.py:35:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Function num_args was called with the wrong arguments [wrong-arg-types]
25+
26+
ret2 = num_args(1, 1) # E: Literal[1] not assignable to str
27+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~\u001b[39m\u001b[0m
28+
29+
overloads_evaluation.py:36:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Any [assert-type]
30+
31+
assert_type(ret2, int)
32+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
33+
34+
overloads_evaluation.py:41:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Function num_args was called with the wrong arguments [wrong-arg-types]
35+
36+
ret4 = num_args(1) # E: Literal[1] not assignable to str
37+
\u001b[1m\u001b[31m~~~~~~~~~~~\u001b[39m\u001b[0m
38+
39+
overloads_evaluation.py:42:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Any [assert-type]
40+
41+
assert_type(ret4, str)
42+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
43+
44+
"""
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 = 30.1
2+
test_duration = 30.7

conformance/results/results.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ <h3>Python Type System Conformance Test Results</h3>
165165
<div class='tc-time'>1.5sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
168-
<div class='tc-time'>6.6sec</div>
168+
<div class='tc-time'>6.7sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
171-
<div class='tc-time'>30.1sec</div>
171+
<div class='tc-time'>30.7sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">
@@ -690,6 +690,12 @@ <h3>Python Type System Conformance Test Results</h3>
690690
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Expects @final and @override to be present on all overloads, not just first.</p></span></div></th>
691691
<th class="column col2 not-conformant"><div class="hover-text">Fail<span class="tooltip-text" id="bottom"><p>Does not enforce any of the specified rules regarding overload definitions.</p></span></div></th>
692692
</tr>
693+
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_evaluation</th>
694+
<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></span></div></th>
695+
<th class="column col2 conformant">Pass</th>
696+
<th class="column col2 conformant">Pass</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></span></div></th>
698+
</tr>
693699
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_overlap</th>
694700
<th class="column col2 conformant">Pass</th>
695701
<th class="column col2 conformant">Pass</th>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Tests for evaluation of calls to overloaded functions.
3+
"""
4+
5+
from typing import assert_type, overload
6+
7+
8+
# > Step 1: Examine the argument list to determine the number of
9+
# > positional and keyword arguments. Use this information to eliminate any
10+
# > overload candidates that are not plausible based on their
11+
# > input signatures.
12+
13+
# > - If no candidate overloads remain, generate an error and stop.
14+
15+
@overload
16+
def num_args(x: int, y: str) -> int:
17+
...
18+
19+
@overload
20+
def num_args(x: str) -> str:
21+
...
22+
23+
def num_args(x: int | str, y: str = "") -> int | str:
24+
return 1
25+
26+
num_args() # E: no matching overload
27+
28+
29+
# > - If only one candidate overload remains, it is the winning match. Evaluate
30+
# > it as if it were a non-overloaded function call and stop.
31+
32+
ret1 = num_args(1, "")
33+
assert_type(ret1, int)
34+
35+
ret2 = num_args(1, 1) # E: Literal[1] not assignable to str
36+
assert_type(ret2, int)
37+
38+
ret3 = num_args("")
39+
assert_type(ret3, str)
40+
41+
ret4 = num_args(1) # E: Literal[1] not assignable to str
42+
assert_type(ret4, str)
43+
44+

0 commit comments

Comments
 (0)