Skip to content

Commit cb04dd6

Browse files
committed
add tests for correct usage of override with an overload
1 parent 8875a4a commit cb04dd6

File tree

7 files changed

+219
-38
lines changed

7 files changed

+219
-38
lines changed

conformance/results/mypy/overloads_invalid.toml

+21-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Does not allow an overload with no implementation in an abstract base class.
55
"""
66
errors_diff = """
77
Line 49: Unexpected errors ['overloads_invalid.py:49: error: An overloaded function outside a stub file must have an implementation [no-overload-impl]']
8+
Line 199: Unexpected errors ['overloads_invalid.py:199: error: Signature of "good_override" incompatible with supertype "Base" [override]']
89
"""
910
output = """
1011
overloads_invalid.py:14: error: Single overload definition, multiple required [misc]
@@ -15,15 +16,24 @@ overloads_invalid.py:78: error: Overload does not consistently use the "@staticm
1516
overloads_invalid.py:88: error: Overloaded function implementation does not accept all possible arguments of signature 1 [misc]
1617
overloads_invalid.py:88: error: Overloaded function implementation does not accept all possible arguments of signature 2 [misc]
1718
overloads_invalid.py:91: error: Overload does not consistently use the "@classmethod" decorator on all function signatures. [misc]
18-
overloads_invalid.py:127: error: @final should be applied only to overload implementation [misc]
19-
overloads_invalid.py:139: error: @final should be applied only to overload implementation [misc]
20-
overloads_invalid.py:155: error: Cannot override final attribute "final_method" (previously declared in base class "Base") [misc]
21-
overloads_invalid.py:155: error: Signature of "final_method" incompatible with supertype "Base" [override]
22-
overloads_invalid.py:155: note: Superclass:
23-
overloads_invalid.py:155: note: @overload
24-
overloads_invalid.py:155: note: def final_method(self, x: int) -> int
25-
overloads_invalid.py:155: note: @overload
26-
overloads_invalid.py:155: note: def final_method(self, x: str) -> str
27-
overloads_invalid.py:155: note: Subclass:
28-
overloads_invalid.py:155: note: def final_method(self, x: int | str) -> int | str
19+
overloads_invalid.py:133: error: @final should be applied only to overload implementation [misc]
20+
overloads_invalid.py:148: error: @final should be applied only to overload implementation [misc]
21+
overloads_invalid.py:173: error: Cannot override final attribute "final_method" (previously declared in base class "Base") [misc]
22+
overloads_invalid.py:173: error: Signature of "final_method" incompatible with supertype "Base" [override]
23+
overloads_invalid.py:173: note: Superclass:
24+
overloads_invalid.py:173: note: @overload
25+
overloads_invalid.py:173: note: def final_method(self, x: int) -> int
26+
overloads_invalid.py:173: note: @overload
27+
overloads_invalid.py:173: note: def final_method(self, x: str) -> str
28+
overloads_invalid.py:173: note: Subclass:
29+
overloads_invalid.py:173: note: def final_method(self, x: int | str) -> int | str
30+
overloads_invalid.py:180: error: Method "bad_override" is marked as an override, but no base method was found with this name [misc]
31+
overloads_invalid.py:199: error: Signature of "good_override" incompatible with supertype "Base" [override]
32+
overloads_invalid.py:199: note: Superclass:
33+
overloads_invalid.py:199: note: def good_override(self, x: int | str) -> int | str
34+
overloads_invalid.py:199: note: Subclass:
35+
overloads_invalid.py:199: note: @overload
36+
overloads_invalid.py:199: note: def good_override(self, x: int) -> int
37+
overloads_invalid.py:199: note: @overload
38+
overloads_invalid.py:199: note: def good_override(self, x: str) -> str
2939
"""

conformance/results/pyre/overloads_invalid.toml

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ conformant = "Partial"
22
conformance_automated = "Fail"
33
notes = """
44
Does not allow an overload with no implementation in a Protocol or an abstract base class.
5-
Expects @final on all overloads and implementation, instead of implementation only.
5+
Expects @final/@override on all overloads and implementation, instead of implementation only.
66
"""
77
errors_diff = """
8-
Lines 139, 141: Expected error (tag 'invalid_final_2')
8+
Lines 148, 150: Expected error (tag 'invalid_final_2')
99
Line 40: Unexpected errors ['overloads_invalid.py:40:4 Missing overload implementation [42]: Overloaded function `MyProto.func3` must have an implementation.']
1010
Line 51: Unexpected errors ['overloads_invalid.py:51:4 Missing overload implementation [42]: Overloaded function `MyAbstractBase.func4` must have an implementation.']
11-
Line 124: Unexpected errors ['overloads_invalid.py:124:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).']
11+
Line 128: Unexpected errors ['overloads_invalid.py:128:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).']
12+
Line 208: Unexpected errors ['overloads_invalid.py:208:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).']
1213
"""
1314
output = """
1415
overloads_invalid.py:15:0 Incompatible overload [43]: At least two overload signatures must be present.
@@ -21,7 +22,10 @@ overloads_invalid.py:85:4 Incompatible overload [43]: The implementation of `C.f
2122
overloads_invalid.py:88:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
2223
overloads_invalid.py:97:4 Incompatible overload [43]: The implementation of `C.func6` does not accept all possible arguments of overload defined on line `97`.
2324
overloads_invalid.py:97:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
24-
overloads_invalid.py:124:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
25-
overloads_invalid.py:133:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
26-
overloads_invalid.py:155:4 Invalid override [40]: `overloads_invalid.Child.final_method` cannot override final method defined in `Base`.
25+
overloads_invalid.py:128:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
26+
overloads_invalid.py:139:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
27+
overloads_invalid.py:173:4 Invalid override [40]: `overloads_invalid.Child.final_method` cannot override final method defined in `Base`.
28+
overloads_invalid.py:189:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
29+
overloads_invalid.py:189:4 Invalid override [40]: `overloads_invalid.Child.bad_override` is decorated with @override, but no method of the same name exists in superclasses of `Child`.
30+
overloads_invalid.py:208:4 Incompatible overload [43]: This definition does not have the same decorators as the preceding overload(s).
2731
"""

conformance/results/pyright/overloads_invalid.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Allows @final on all overloads and implementation; should be implementation-only
44
"""
55
conformance_automated = "Fail"
66
errors_diff = """
7-
Lines 139, 141: Expected error (tag 'invalid_final_2')
7+
Lines 148, 150: Expected error (tag 'invalid_final_2')
88
"""
99
output = """
1010
overloads_invalid.py:15:5 - error: "func1" is marked as overload, but additional overloads are missing (reportInconsistentOverload)
@@ -25,10 +25,11 @@ overloads_invalid.py:88:9 - error: Overloaded implementation is not consistent w
2525
    Extra parameter "x" (reportInconsistentOverload)
2626
overloads_invalid.py:93:9 - error: Overloads for "func6" use @classmethod inconsistently (reportInconsistentOverload)
2727
overloads_invalid.py:97:15 - warning: Instance methods should take a "self" parameter (reportSelfClsParameterName)
28-
overloads_invalid.py:129:9 - error: Overload for "invalid_final" is marked @final but implementation is not (reportInconsistentOverload)
29-
overloads_invalid.py:155:9 - error: Method "final_method" cannot override final method defined in class "Base" (reportIncompatibleMethodOverride)
30-
overloads_invalid.py:155:9 - error: Method "final_method" overrides class "Base" in an incompatible manner
28+
overloads_invalid.py:135:9 - error: Overload for "invalid_final" is marked @final but implementation is not (reportInconsistentOverload)
29+
overloads_invalid.py:173:9 - error: Method "final_method" cannot override final method defined in class "Base" (reportIncompatibleMethodOverride)
30+
overloads_invalid.py:173:9 - error: Method "final_method" overrides class "Base" in an incompatible manner
3131
  Return type mismatch: base method returns type "int", override returns type "int | str"
3232
    Type "int | str" is not assignable to type "int"
3333
      "str" is not assignable to "int" (reportIncompatibleMethodOverride)
34+
overloads_invalid.py:189:9 - error: Method "bad_override" is marked as override, but no base method of same name is present (reportGeneralTypeIssues)
3435
"""

0 commit comments

Comments
 (0)