Skip to content

Commit 4936ac1

Browse files
committed
add tests for signature-transforming decorators
1 parent f7bf384 commit 4936ac1

File tree

8 files changed

+63
-11
lines changed

8 files changed

+63
-11
lines changed
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.7
2+
test_duration = 1.8
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
conformant = "Pass"
2-
conformance_automated = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Does not apply decorator transforms before checking overload consistency.
4+
"""
5+
conformance_automated = "Fail"
36
errors_diff = """
7+
Line 107: Unexpected errors ['overloads_consistency.py:107:0 Incompatible overload [43]: The return type of overloaded function `decorated` (`None`) is incompatible with the return type of the implementation (`bytes`).', 'overloads_consistency.py:107:0 Incompatible overload [43]: The implementation of `decorated` does not accept all possible arguments of overload defined on line `107`.']
8+
Line 111: Unexpected errors ['overloads_consistency.py:111:0 Incompatible overload [43]: The return type of overloaded function `decorated` (`str`) is incompatible with the return type of the implementation (`bytes`).', 'overloads_consistency.py:111:0 Incompatible overload [43]: The implementation of `decorated` does not accept all possible arguments of overload defined on line `111`.', 'overloads_consistency.py:111:0 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).']
49
"""
510
output = """
611
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`).
712
overloads_consistency.py:40:0 Incompatible overload [43]: The implementation of `parameter_type` does not accept all possible arguments of overload defined on line `40`.
13+
overloads_consistency.py:107:0 Incompatible overload [43]: The return type of overloaded function `decorated` (`None`) is incompatible with the return type of the implementation (`bytes`).
14+
overloads_consistency.py:107:0 Incompatible overload [43]: The implementation of `decorated` does not accept all possible arguments of overload defined on line `107`.
15+
overloads_consistency.py:111:0 Incompatible overload [43]: The return type of overloaded function `decorated` (`str`) is incompatible with the return type of the implementation (`bytes`).
16+
overloads_consistency.py:111:0 Incompatible overload [43]: The implementation of `decorated` does not accept all possible arguments of overload defined on line `111`.
17+
overloads_consistency.py:111:0 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
818
"""
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.5
2+
test_duration = 6.0
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.5
2+
test_duration = 1.7

conformance/results/pytype/overloads_consistency.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Line 28: Unexpected errors ['overloads_consistency.py:28:12: \\x1b[1m\\x1b[31mer
1010
Line 44: Unexpected errors ['overloads_consistency.py:44:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in parameter_type: bad return type [bad-return-type]']
1111
Line 73: Unexpected errors ['overloads_consistency.py:73:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in returns_coroutine: bad return type [bad-return-type]']
1212
Line 88: Unexpected errors ['overloads_consistency.py:88:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in returns_coroutine_2: bad return type [bad-return-type]', 'overloads_consistency.py:88:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in returns_coroutine_2: bad return type [bad-return-type]']
13+
Line 107: Unexpected errors ['overloads_consistency.py:107:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: Function decorated expects 0 arg(s), got 1 [wrong-arg-count]']
14+
Line 115: Unexpected errors ["overloads_consistency.py:115:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: Missing parameter 'z' in call to function decorated [missing-parameter]"]
1315
"""
1416
output = """
1517
overloads_consistency.py:28:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in return_type: bad return type [bad-return-type]
@@ -37,4 +39,18 @@ overloads_consistency.py:88:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in r
3739
return _wrapped(x)
3840
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
3941
42+
overloads_consistency.py:107:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Function decorated expects 0 arg(s), got 1 [wrong-arg-count]
43+
44+
def decorated() -> None:
45+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
46+
...
47+
\u001b[1m\u001b[31m~~~~~~~\u001b[39m\u001b[0m
48+
49+
overloads_consistency.py:115:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Missing parameter 'z' in call to function decorated [missing-parameter]
50+
51+
def decorated(y: bytes, z: bytes) -> bytes:
52+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
53+
return b""
54+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~\u001b[39m\u001b[0m
55+
4056
"""
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 = 31.1

conformance/results/results.html

Lines changed: 4 additions & 4 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.7sec</div>
162+
<div class='tc-time'>1.8sec</div>
163163
</th>
164164
<th class='tc-header'><div class='tc-name'>pyright 1.1.391</div>
165-
<div class='tc-time'>1.5sec</div>
165+
<div class='tc-time'>1.7sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
168-
<div class='tc-time'>6.5sec</div>
168+
<div class='tc-time'>6.0sec</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'>31.1sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">

conformance/tests/overloads_consistency.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Tests consistency of overloads with implementation.
33
"""
44

5-
from typing import Coroutine, overload
5+
from typing import Callable, Coroutine, overload
66

77
# > If an overload implementation is defined, type checkers should validate
88
# > that it is consistent with all of its associated overload signatures.
@@ -89,3 +89,29 @@ def returns_coroutine_2(x: int | str) -> Coroutine[None, None, int | str]:
8989

9090
async def _wrapped(x: int | str) -> int | str:
9191
return 2
92+
93+
# Decorator transforms are applied before checking overload consistency:
94+
95+
def _deco_1(f: Callable) -> Callable[[int], int]:
96+
def wrapped(_x: int, /) -> int:
97+
return 1
98+
return wrapped
99+
100+
def _deco_2(f: Callable) -> Callable[[int | str], int | str]:
101+
def wrapped(_x: int | str, /) -> int | str:
102+
return 1
103+
return wrapped
104+
105+
@overload
106+
@_deco_1
107+
def decorated() -> None:
108+
...
109+
110+
@overload
111+
def decorated(x: str, /) -> str:
112+
...
113+
114+
@_deco_2
115+
def decorated(y: bytes, z: bytes) -> bytes:
116+
return b""
117+

0 commit comments

Comments
 (0)