Skip to content

Commit 87377ed

Browse files
committed
add initial overloads_consistency tests
1 parent ac3b70e commit 87377ed

File tree

9 files changed

+109
-8
lines changed

9 files changed

+109
-8
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
3+
errors_diff = """
4+
"""
5+
output = """
6+
overloads_consistency.py:27: error: Overloaded function implementation cannot produce return type of signature 2 [misc]
7+
overloads_consistency.py:42: error: Overloaded function implementation does not accept all possible arguments of signature 2 [misc]
8+
"""
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
3+
errors_diff = """
4+
"""
5+
output = """
6+
overloads_consistency.py:24:0 Incompatible overload [43]: The return type of overloaded function `return_type` (`str`) is incompatible with the return type of the implementation (`int`).
7+
overloads_consistency.py:39:0 Incompatible overload [43]: The implementation of `parameter_type` does not accept all possible arguments of overload defined on line `39`.
8+
"""
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
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
3+
errors_diff = """
4+
"""
5+
output = """
6+
overloads_consistency.py:27:5 - error: Overloaded implementation is not consistent with signature of overload 2
7+
  Function return type "str" is incompatible with type "int"
8+
    "str" is not assignable to "int" (reportInconsistentOverload)
9+
overloads_consistency.py:42:5 - error: Overloaded implementation is not consistent with signature of overload 2
10+
  Type "(x: int) -> (int | str)" is not assignable to type "(x: str) -> str"
11+
    Parameter 1: type "str" is incompatible with type "int"
12+
      "str" is not assignable to "int" (reportInconsistentOverload)
13+
"""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
conformant = "Fail"
2+
notes = """
3+
Doesn't appear to validate overload consistency at all.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
7+
Lines 24, 27: Expected error (tag 'return_type')
8+
Lines 39, 42: Expected error (tag 'parameter_type')
9+
Line 28: Unexpected errors ['overloads_consistency.py:28:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in return_type: bad return type [bad-return-type]']
10+
Line 43: Unexpected errors ['overloads_consistency.py:43:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in parameter_type: bad return type [bad-return-type]']
11+
"""
12+
output = """
13+
overloads_consistency.py:28:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in return_type: bad return type [bad-return-type]
14+
15+
return 1
16+
\u001b[1m\u001b[31m~\u001b[39m\u001b[0m
17+
18+
overloads_consistency.py:43:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in parameter_type: bad return type [bad-return-type]
19+
20+
return 1
21+
\u001b[1m\u001b[31m~\u001b[39m\u001b[0m
22+
23+
"""

conformance/results/pytype/overloads_definitions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ class Child(Base): # E[override-final]
139139
\u001b[1m\u001b[31m\u001b[39m\u001b[0m
140140
@overload # E[override-final]
141141
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
142-
def final_method(self, x: int) -> int: # E[override-final]
143-
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
142+
def final_method(self, x: int) -> int:
143+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
144144
...
145145
\u001b[1m\u001b[31m~~~~~~~~~~~\u001b[39m\u001b[0m
146146
147147
\u001b[1m\u001b[31m\u001b[39m\u001b[0m
148148
@overload
149149
\u001b[1m\u001b[31m~~~~~~~~~~~~~\u001b[39m\u001b[0m
150-
def final_method(self, x: str) -> str: # E[override-final]
151-
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
150+
def final_method(self, x: str) -> str:
151+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
152152
...
153153
\u001b[1m\u001b[31m~~~~~~~~~~~\u001b[39m\u001b[0m
154154
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.0
2+
test_duration = 30.3

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.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'>30.0sec</div>
171+
<div class='tc-time'>30.3sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">
@@ -672,6 +672,12 @@ <h3>Python Type System Conformance Test Results</h3>
672672
<th class="column col2 conformant">Pass</th>
673673
<th class="column col2 partially-conformant">Partial</th>
674674
</tr>
675+
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_consistency</th>
676+
<th class="column col2 not-conformant">Unknown</th>
677+
<th class="column col2 not-conformant">Unknown</th>
678+
<th class="column col2 not-conformant">Unknown</th>
679+
<th class="column col2 not-conformant">Unknown</th>
680+
</tr>
675681
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_definitions</th>
676682
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not allow an overload with no implementation in an abstract base class.</p><p>Allows @override to be on all overloads and implementation, instead of just implementation.</p></span></div></th>
677683
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Allows @final/@override on all overloads and implementation; should be implementation-only.</p></span></div></th>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Tests consistency of overloads with implementation.
3+
"""
4+
5+
from typing import overload
6+
7+
# > If an overload implementation is defined, type checkers should validate
8+
# > that it is consistent with all of its associated overload signatures.
9+
# > The implementation should accept all potential sets of arguments
10+
# > that are accepted by the overloads and should produce all potential return
11+
# > types produced by the overloads. In typing terms, this means the input
12+
# > signature of the implementation should be :term:<assignable> to the input
13+
# > signatures of all overloads, and the return type of all overloads should be
14+
# > assignable to the return type of the implementation.
15+
16+
# Return type of all overloads must be assignable to return type of
17+
# implementation:
18+
19+
@overload
20+
def return_type(x: int) -> int:
21+
...
22+
23+
@overload
24+
def return_type(x: str) -> str: # E[return_type]
25+
...
26+
27+
def return_type(x: int | str) -> int: # E[return_type] an overload returns `str`, not assignable to `int`
28+
return 1
29+
30+
31+
# Input signature of implementation must be assignable to signature of each
32+
# overload:
33+
34+
@overload
35+
def parameter_type(x: int) -> int:
36+
...
37+
38+
@overload
39+
def parameter_type(x: str) -> str: # E[parameter_type]
40+
...
41+
42+
def parameter_type(x: int) -> int | str: # E[parameter_type] impl type of `x` must be assignable from overload types of `x`
43+
return 1

0 commit comments

Comments
 (0)