Skip to content

Commit e0e0b8a

Browse files
committed
add test for partially overlapping overloads
1 parent 4936ac1 commit e0e0b8a

File tree

10 files changed

+77
-9
lines changed

10 files changed

+77
-9
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
3+
errors_diff = """
4+
"""
5+
output = """
6+
overloads_overlap.py:14: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
7+
"""
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
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
conformant = "Fail"
2+
notes = """
3+
Does not check for overlapping overloads with inconsistent return type.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
7+
Line 14: Expected 1 errors
8+
"""
9+
output = """
10+
"""
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.7
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
3+
errors_diff = """
4+
"""
5+
output = """
6+
overloads_overlap.py:14:5 - error: Overload 1 for "is_one" overlaps overload 2 and returns an incompatible type (reportOverlappingOverload)
7+
"""
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.7
2+
test_duration = 1.5
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
conformant = "Fail"
2+
notes = """
3+
Does not check for overlapping overloads with inconsistent return type.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
7+
Line 14: Expected 1 errors
8+
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]']
9+
"""
10+
output = """
11+
overloads_overlap.py:22:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in is_one: bad return type [bad-return-type]
12+
13+
return x == 1
14+
\u001b[1m\u001b[31m~~~~~~~~~~~~~\u001b[39m\u001b[0m
15+
16+
"""
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.1
2+
test_duration = 32.1

conformance/results/results.html

Lines changed: 11 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>
165-
<div class='tc-time'>1.7sec</div>
165+
<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.0sec</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'>31.1sec</div>
171+
<div class='tc-time'>32.1sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">
@@ -675,7 +675,7 @@ <h3>Python Type System Conformance Test Results</h3>
675675
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_consistency</th>
676676
<th class="column col2 conformant">Pass</th>
677677
<th class="column col2 conformant">Pass</th>
678-
<th class="column col2 conformant">Pass</th>
678+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not apply decorator transforms before checking overload consistency.</p></span></div></th>
679679
<th class="column col2 not-conformant"><div class="hover-text">Fail<span class="tooltip-text" id="bottom"><p>Doesn't appear to validate overload consistency at all.</p></span></div></th>
680680
</tr>
681681
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_definitions</th>
@@ -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_overlap</th>
694+
<th class="column col2 conformant">Pass</th>
695+
<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>
698+
</tr>
693699
<tr><th class="column" colspan="5">
694700
<a class="test_group" href="https://typing.readthedocs.io/en/latest/spec/exceptions.html">Exceptions</a>
695701
</th></tr>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Tests checks for overlapping overloads.
3+
"""
4+
5+
from typing import Literal, overload
6+
7+
# > If two overloads can accept the same set of arguments, they are said
8+
# > to "partially overlap". If two overloads partially overlap, the return type
9+
# > of the former overload should be assignable to the return type of the
10+
# > latter overload. If this condition doesn't hold, it is indicative of a
11+
# > programming error and should be reported by type checkers.
12+
13+
@overload
14+
def is_one(x: Literal[1]) -> Literal[True]: # E: overlapping overloads, inconsistent return type
15+
...
16+
17+
@overload
18+
def is_one(x: int) -> Literal[False]:
19+
...
20+
21+
def is_one(x: int) -> bool:
22+
return x == 1

0 commit comments

Comments
 (0)