Skip to content

Commit cc748d3

Browse files
committed
add test for fully overlapping overloads
1 parent e0e0b8a commit cc748d3

File tree

8 files changed

+37
-9
lines changed

8 files changed

+37
-9
lines changed

conformance/results/mypy/overloads_overlap.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ errors_diff = """
44
"""
55
output = """
66
overloads_overlap.py:14: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
7+
overloads_overlap.py:36: error: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader [overload-cannot-match]
78
"""
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
conformant = "Fail"
1+
conformant = "Partial"
22
notes = """
3-
Does not check for overlapping overloads with inconsistent return type.
3+
Does not check for partially overlapping overloads with inconsistent return type.
44
"""
55
conformance_automated = "Fail"
66
errors_diff = """
77
Line 14: Expected 1 errors
88
"""
99
output = """
10+
overloads_overlap.py:36:0 Incompatible overload [43]: The overloaded function `full_overlap` on line 36 will never be matched. The signature `(x: bool) -> bool` is the same or broader.
1011
"""
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.7
2+
test_duration = 6.6

conformance/results/pyright/overloads_overlap.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ errors_diff = """
44
"""
55
output = """
66
overloads_overlap.py:14:5 - error: Overload 1 for "is_one" overlaps overload 2 and returns an incompatible type (reportOverlappingOverload)
7+
overloads_overlap.py:36:5 - error: Overload 2 for "full_overlap" will never be used because its parameters overlap overload 1 (reportOverlappingOverload)
78
"""
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
conformant = "Fail"
22
notes = """
3-
Does not check for overlapping overloads with inconsistent return type.
3+
Does not check for partially or fully overlapping overloads.
44
"""
55
conformance_automated = "Fail"
66
errors_diff = """
77
Line 14: Expected 1 errors
8+
Line 36: Expected 1 errors
89
Line 22: Unexpected errors ['overloads_overlap.py:22:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in is_one: bad return type [bad-return-type]']
10+
Line 40: Unexpected errors ['overloads_overlap.py:40:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in full_overlap: bad return type [bad-return-type]']
911
"""
1012
output = """
1113
overloads_overlap.py:22:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in is_one: bad return type [bad-return-type]
1214
1315
return x == 1
1416
\u001b[1m\u001b[31m~~~~~~~~~~~~~\u001b[39m\u001b[0m
1517
18+
overloads_overlap.py:40:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in full_overlap: bad return type [bad-return-type]
19+
20+
return 1
21+
\u001b[1m\u001b[31m~\u001b[39m\u001b[0m
22+
1623
"""
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 = 32.1
2+
test_duration = 30.1

conformance/results/results.html

Lines changed: 4 additions & 4 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.7sec</div>
168+
<div class='tc-time'>6.6sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
171-
<div class='tc-time'>32.1sec</div>
171+
<div class='tc-time'>30.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_overlap</th>
694694
<th class="column col2 conformant">Pass</th>
695695
<th class="column col2 conformant">Pass</th>
696-
<th class="column col2 not-conformant"><div class="hover-text">Fail<span class="tooltip-text" id="bottom"><p>Does not check for overlapping overloads with inconsistent return type.</p></span></div></th>
697-
<th class="column col2 not-conformant"><div class="hover-text">Fail<span class="tooltip-text" id="bottom"><p>Does not check for overlapping overloads with inconsistent return type.</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 check for partially overlapping overloads with inconsistent return type.</p></span></div></th>
697+
<th class="column col2 not-conformant"><div class="hover-text">Fail<span class="tooltip-text" id="bottom"><p>Does not check for partially or fully overlapping overloads.</p></span></div></th>
698698
</tr>
699699
<tr><th class="column" colspan="5">
700700
<a class="test_group" href="https://typing.readthedocs.io/en/latest/spec/exceptions.html">Exceptions</a>

conformance/tests/overloads_overlap.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,21 @@ def is_one(x: int) -> Literal[False]:
2020

2121
def is_one(x: int) -> bool:
2222
return x == 1
23+
24+
25+
# > If all possible sets of arguments accepted by an overload are also always
26+
# > accepted by an earlier overload, the two overloads are said to "fully overlap".
27+
# > In this case, the latter overload will never be used. This condition
28+
# > is indicative of a programming error and should be reported by type
29+
# > checkers.
30+
31+
@overload
32+
def full_overlap(x: bool) -> bool:
33+
...
34+
35+
@overload
36+
def full_overlap(x: Literal[False]) -> int: # E: overload will never be used due to full overlap
37+
...
38+
39+
def full_overlap(x: bool) -> int:
40+
return 1

0 commit comments

Comments
 (0)