Skip to content

Commit 27f1c79

Browse files
committed
fix abstractmethod without implementation check
1 parent 57495db commit 27f1c79

File tree

9 files changed

+61
-40
lines changed

9 files changed

+61
-40
lines changed

conformance/results/mypy/overloads_basic.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ overloads_basic.py:41: note: def __getitem__(self, slice[Any, Any, Any], /)
1010
overloads_basic.py:66: error: Single overload definition, multiple required [misc]
1111
overloads_basic.py:78: error: An overloaded function outside a stub file must have an implementation [no-overload-impl]
1212
overloads_basic.py:101: error: An overloaded function outside a stub file must have an implementation [no-overload-impl]
13-
overloads_basic.py:116: error: Overload does not consistently use the "@staticmethod" decorator on all function signatures. [misc]
14-
overloads_basic.py:126: error: Overloaded function implementation does not accept all possible arguments of signature 1 [misc]
15-
overloads_basic.py:126: error: Overloaded function implementation does not accept all possible arguments of signature 2 [misc]
16-
overloads_basic.py:129: error: Overload does not consistently use the "@classmethod" decorator on all function signatures. [misc]
13+
overloads_basic.py:115: error: An overloaded function outside a stub file must have an implementation [no-overload-impl]
14+
overloads_basic.py:130: error: Overload does not consistently use the "@staticmethod" decorator on all function signatures. [misc]
15+
overloads_basic.py:140: error: Overloaded function implementation does not accept all possible arguments of signature 1 [misc]
16+
overloads_basic.py:140: error: Overloaded function implementation does not accept all possible arguments of signature 2 [misc]
17+
overloads_basic.py:143: error: Overload does not consistently use the "@classmethod" decorator on all function signatures. [misc]
1718
"""
1819
conformance_automated = "Fail"
1920
errors_diff = """

conformance/results/pyre/overloads_basic.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ overloads_basic.py:41:2 Incompatible parameter type [6]: In call `Bytes.__getite
77
overloads_basic.py:67:0 Incompatible overload [43]: At least two overload signatures must be present.
88
overloads_basic.py:79:0 Missing overload implementation [42]: Overloaded function `func2` must have an implementation.
99
overloads_basic.py:92:4 Missing overload implementation [42]: Overloaded function `MyProto.func3` must have an implementation.
10-
overloads_basic.py:102:4 Missing overload implementation [42]: Overloaded function `MyAbstractBase.func4` must have an implementation.
11-
overloads_basic.py:118:4 Incompatible overload [43]: The implementation of `C.func5` does not accept all possible arguments of overload defined on line `118`.
12-
overloads_basic.py:123:4 Incompatible overload [43]: The implementation of `C.func5` does not accept all possible arguments of overload defined on line `123`.
13-
overloads_basic.py:126:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
14-
overloads_basic.py:131:4 Incompatible overload [43]: The implementation of `C.func6` does not accept all possible arguments of overload defined on line `131`.
15-
overloads_basic.py:136:4 Incompatible overload [43]: The implementation of `C.func6` does not accept all possible arguments of overload defined on line `136`.
16-
overloads_basic.py:139:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
10+
overloads_basic.py:103:4 Missing overload implementation [42]: Overloaded function `MyAbstractBase.func4` must have an implementation.
11+
overloads_basic.py:116:4 Missing overload implementation [42]: Overloaded function `MyAbstractBase.not_abstract` must have an implementation.
12+
overloads_basic.py:132:4 Incompatible overload [43]: The implementation of `C.func5` does not accept all possible arguments of overload defined on line `132`.
13+
overloads_basic.py:137:4 Incompatible overload [43]: The implementation of `C.func5` does not accept all possible arguments of overload defined on line `137`.
14+
overloads_basic.py:140:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
15+
overloads_basic.py:145:4 Incompatible overload [43]: The implementation of `C.func6` does not accept all possible arguments of overload defined on line `145`.
16+
overloads_basic.py:150:4 Incompatible overload [43]: The implementation of `C.func6` does not accept all possible arguments of overload defined on line `150`.
17+
overloads_basic.py:153:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
1718
"""
1819
conformance_automated = "Fail"
1920
errors_diff = """
2021
Line 92: Unexpected errors ['overloads_basic.py:92:4 Missing overload implementation [42]: Overloaded function `MyProto.func3` must have an implementation.']
21-
Line 102: Unexpected errors ['overloads_basic.py:102:4 Missing overload implementation [42]: Overloaded function `MyAbstractBase.func4` must have an implementation.']
22+
Line 103: Unexpected errors ['overloads_basic.py:103:4 Missing overload implementation [42]: Overloaded function `MyAbstractBase.func4` must have an implementation.']
2223
"""
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 = 5.9
2+
test_duration = 6.2
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
conformant = "Partial"
1+
conformant = "Pass"
22
notes = """
3-
Does not allow an overload with no implementation in an abstract base class.
43
"""
54
output = """
65
overloads_basic.py:41:1 - error: No overloads for "__getitem__" match the provided arguments (reportCallIssue)
76
overloads_basic.py:41:1 - error: Argument of type "Literal['']" cannot be assigned to parameter "__s" of type "slice[Any, Any, Any]" in function "__getitem__"
87
  "Literal['']" is not assignable to "slice[Any, Any, Any]" (reportArgumentType)
98
overloads_basic.py:67:5 - error: "func1" is marked as overload, but additional overloads are missing (reportInconsistentOverload)
109
overloads_basic.py:79:5 - error: "func2" is marked as overload, but no implementation is provided (reportNoOverloadImplementation)
11-
overloads_basic.py:102:9 - error: "func4" is marked as overload, but no implementation is provided (reportNoOverloadImplementation)
12-
overloads_basic.py:118:9 - error: Overloads for "func5" use @staticmethod inconsistently (reportInconsistentOverload)
13-
overloads_basic.py:126:9 - error: Overloaded implementation is not consistent with signature of overload 1
10+
overloads_basic.py:116:9 - error: "not_abstract" is marked as overload, but no implementation is provided (reportNoOverloadImplementation)
11+
overloads_basic.py:132:9 - error: Overloads for "func5" use @staticmethod inconsistently (reportInconsistentOverload)
12+
overloads_basic.py:140:9 - error: Overloaded implementation is not consistent with signature of overload 1
1413
  Type "(self: Self@C, x: int | str) -> (int | str)" is not assignable to type "(x: int) -> int"
1514
    Parameter name mismatch: "x" versus "self"
1615
    Parameter 1: type "int" is incompatible with type "Self@C"
1716
      Type "int" is not assignable to type "Self@C"
1817
    Extra parameter "x" (reportInconsistentOverload)
19-
overloads_basic.py:126:9 - error: Overloaded implementation is not consistent with signature of overload 2
18+
overloads_basic.py:140:9 - error: Overloaded implementation is not consistent with signature of overload 2
2019
  Type "(self: Self@C, x: int | str) -> (int | str)" is not assignable to type "(x: str) -> str"
2120
    Parameter name mismatch: "x" versus "self"
2221
    Parameter 1: type "str" is incompatible with type "Self@C"
2322
      Type "str" is not assignable to type "Self@C"
2423
    Extra parameter "x" (reportInconsistentOverload)
25-
overloads_basic.py:131:9 - error: Overloads for "func6" use @classmethod inconsistently (reportInconsistentOverload)
26-
overloads_basic.py:139:15 - warning: Instance methods should take a "self" parameter (reportSelfClsParameterName)
24+
overloads_basic.py:145:9 - error: Overloads for "func6" use @classmethod inconsistently (reportInconsistentOverload)
25+
overloads_basic.py:153:15 - warning: Instance methods should take a "self" parameter (reportSelfClsParameterName)
2726
"""
28-
conformance_automated = "Fail"
27+
conformance_automated = "Pass"
2928
errors_diff = """
30-
Line 102: Unexpected errors ['overloads_basic.py:102:9 - error: "func4" is marked as overload, but no implementation is provided (reportNoOverloadImplementation)']
3129
"""

conformance/results/pytype/overloads_basic.toml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,22 @@ overloads_basic.py:98:9: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func3:
2727
...
2828
\u001b[1m\u001b[31m~~~\u001b[39m\u001b[0m
2929
30-
overloads_basic.py:108:9: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func4: @typing.overload-decorated 'MyAbstractBase.func4' object is not callable [not-callable]
30+
overloads_basic.py:110:9: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func4: @typing.overload-decorated 'MyAbstractBase.func4' object is not callable [not-callable]
3131
3232
...
3333
\u001b[1m\u001b[31m~~~\u001b[39m\u001b[0m
3434
35-
overloads_basic.py:119:9: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func5: bad return type [bad-return-type]
35+
overloads_basic.py:122:9: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in not_abstract: @typing.overload-decorated 'MyAbstractBase.not_abstract' object is not callable [not-callable]
3636
3737
...
3838
\u001b[1m\u001b[31m~~~\u001b[39m\u001b[0m
3939
40-
overloads_basic.py:124:9: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func5: bad return type [bad-return-type]
40+
overloads_basic.py:133:9: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func5: bad return type [bad-return-type]
41+
42+
...
43+
\u001b[1m\u001b[31m~~~\u001b[39m\u001b[0m
44+
45+
overloads_basic.py:138:9: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func5: bad return type [bad-return-type]
4146
4247
...
4348
\u001b[1m\u001b[31m~~~\u001b[39m\u001b[0m
@@ -47,12 +52,14 @@ conformance_automated = "Fail"
4752
errors_diff = """
4853
Lines 66, 67: Expected error (tag 'func1')
4954
Lines 78, 79: Expected error (tag 'func2')
50-
Lines 116, 118, 123, 126: Expected error (tag 'func5')
51-
Lines 129, 131, 136, 139: Expected error (tag 'func6')
55+
Lines 115, 116: Expected error (tag 'not_abstract')
56+
Lines 130, 132, 137, 140: Expected error (tag 'func5')
57+
Lines 143, 145, 150, 153: Expected error (tag 'func6')
5258
Line 35: Unexpected errors ['overloads_basic.py:35:20: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in __getitem__: bad return type [bad-return-type]']
5359
Line 62: Unexpected errors ['overloads_basic.py:62:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in map: bad return type [bad-return-type]']
5460
Line 98: Unexpected errors ["overloads_basic.py:98:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func3: @typing.overload-decorated 'MyProto.func3' object is not callable [not-callable]"]
55-
Line 108: Unexpected errors ["overloads_basic.py:108:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func4: @typing.overload-decorated 'MyAbstractBase.func4' object is not callable [not-callable]"]
56-
Line 119: Unexpected errors ['overloads_basic.py:119:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func5: bad return type [bad-return-type]']
57-
Line 124: Unexpected errors ['overloads_basic.py:124:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func5: bad return type [bad-return-type]']
61+
Line 110: Unexpected errors ["overloads_basic.py:110:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func4: @typing.overload-decorated 'MyAbstractBase.func4' object is not callable [not-callable]"]
62+
Line 122: Unexpected errors ["overloads_basic.py:122:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in not_abstract: @typing.overload-decorated 'MyAbstractBase.not_abstract' object is not callable [not-callable]"]
63+
Line 133: Unexpected errors ['overloads_basic.py:133:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func5: bad return type [bad-return-type]']
64+
Line 138: Unexpected errors ['overloads_basic.py:138:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func5: bad return type [bad-return-type]']
5865
"""
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.3
2+
test_duration = 30.5

conformance/results/results.html

Lines changed: 3 additions & 3 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'>5.9sec</div>
168+
<div class='tc-time'>6.2sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
171-
<div class='tc-time'>30.3sec</div>
171+
<div class='tc-time'>30.5sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">
@@ -670,7 +670,7 @@ <h3>Python Type System Conformance Test Results</h3>
670670
<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></span></div></th>
671671
<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></span></div></th>
672672
<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 a Protocol or an abstract base class.</p></span></div></th>
673-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject a function with a single @overload signature.</p><p>Does not reject a function with @overload signature but no implementation.</p><p>Does not allow an overload with no implementation in a Protocol or an abstract base class.</p><p>Does not exempt overloads from checking of return type in body, when also decorated with `@staticmethod`.</p><p>Does not error on overloads inconsistently decorated with `@staticmethod`.</p></span></div></th>
673+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject a function with a single @overload signature.</p><p>Does not reject a function with @overload signature but no implementation.</p><p>Does not allow an overload with no implementation in a Protocol or an abstract base class.</p><p>Does not exempt overloads from checking of return type in body, when also decorated with `@staticmethod`.</p><p>Does not error on overloads inconsistently decorated with `@staticmethod` or `@classmethod`.</p></span></div></th>
674674
</tr>
675675
<tr><th class="column" colspan="5">
676676
<a class="test_group" href="https://typing.readthedocs.io/en/latest/spec/exceptions.html">Exceptions</a>

conformance/tests/overloads_basic.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Specification: https://typing.readthedocs.io/en/latest/spec/overload.html#overload
66

7-
from abc import ABC
7+
from abc import ABC, abstractmethod
88
from typing import (
99
Any,
1010
Callable,
@@ -85,8 +85,8 @@ def func2(x: str) -> str:
8585
...
8686

8787

88-
# > Overload definitions within stub files, protocols, and abstract base classes
89-
# > are exempt from this check.
88+
# > Overload definitions within stub files, protocols, and on abstract methods
89+
# > within abstract base classes are exempt from this check.
9090
class MyProto(Protocol):
9191
@overload
9292
def func3(self, x: int) -> int:
@@ -99,14 +99,28 @@ def func3(self, x: str) -> str:
9999

100100
class MyAbstractBase(ABC):
101101
@overload
102+
@abstractmethod
102103
def func4(self, x: int) -> int:
103104
...
104105

105106

106107
@overload
108+
@abstractmethod
107109
def func4(self, x: str) -> str:
108110
...
109111

112+
# A non-abstract method in an abstract base class still requires an
113+
# implementation:
114+
115+
@overload # E[not_abstract]
116+
def not_abstract(self, x: int) -> int: # E[not_abstract] no implementation
117+
...
118+
119+
120+
@overload
121+
def not_abstract(self, x: str) -> str:
122+
...
123+
110124

111125
# > If one overload signature is decorated with ``@staticmethod`` or
112126
# > ``@classmethod``, all overload signatures must be similarly decorated. The

docs/spec/overload.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ one is present, an error should be reported.
127127
The ``@overload``-decorated definitions must be followed by an overload
128128
implementation, which does not include an ``@overload`` decorator. Type
129129
checkers should report an error or warning if an implementation is missing.
130-
Overload definitions within stub files, protocols, and abstract base classes
131-
are exempt from this check.
130+
Overload definitions within stub files, protocols, and on abstract methods
131+
within abstract base classes are exempt from this check.
132132

133133
If one overload signature is decorated with ``@staticmethod`` or
134134
``@classmethod``, all overload signatures must be similarly decorated. The

0 commit comments

Comments
 (0)