Skip to content

Commit 8ff42d7

Browse files
Conformance tests: Ignore overlapping overload errors in LiteralString (#1701)
Part of #1692
1 parent 586d494 commit 8ff42d7

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

conformance/results/mypy/literals_literalstring.toml

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@ literals_literalstring.py:37: error: Parameter 1 of Literal[...] is invalid [va
88
literals_literalstring.py:43: error: Incompatible types in assignment (expression has type "Literal['two']", variable has type "Literal['']") [assignment]
99
literals_literalstring.py:74: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
1010
literals_literalstring.py:75: error: Incompatible types in assignment (expression has type "bytes", variable has type "str") [assignment]
11-
literals_literalstring.py:142: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
12-
literals_literalstring.py:142: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [overload-overlap]
13-
literals_literalstring.py:152: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [misc]
14-
literals_literalstring.py:162: error: Expression is of type "bool", not "str" [assert-type]
11+
literals_literalstring.py:157: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [misc]
12+
literals_literalstring.py:167: error: Expression is of type "B", not "A" [assert-type]
1513
"""
1614
conformance_automated = "Fail"
1715
errors_diff = """
1816
Line 66: Expected 1 errors
1917
Line 120: Expected 1 errors
2018
Line 134: Expected 1 errors
21-
Line 166: Expected 1 errors
22-
Line 142: Unexpected errors ['literals_literalstring.py:142: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]', 'literals_literalstring.py:142: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [overload-overlap]']
23-
Line 152: Unexpected errors ["literals_literalstring.py:152: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [misc]"]
24-
Line 162: Unexpected errors ['literals_literalstring.py:162: error: Expression is of type "bool", not "str" [assert-type]']
19+
Line 171: Expected 1 errors
20+
Line 157: Unexpected errors ["literals_literalstring.py:157: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [misc]"]
21+
Line 167: Unexpected errors ['literals_literalstring.py:167: error: Expression is of type "B", not "A" [assert-type]']
2522
"""

conformance/results/pyre/literals_literalstring.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ literals_literalstring.py:74:4 Incompatible variable type [9]: x3 is declared to
99
literals_literalstring.py:75:4 Incompatible variable type [9]: x4 is declared to have type `typing_extensions.LiteralString` but is used as type `typing_extensions.Literal[b'test']`.
1010
literals_literalstring.py:120:21 Incompatible parameter type [6]: In call `literal_identity`, for 1st positional argument, expected `Variable[TLiteral (bound to typing_extensions.LiteralString)]` but got `str`.
1111
literals_literalstring.py:134:50 Incompatible parameter type [6]: In call `Container.__init__`, for 1st positional argument, expected `Variable[T (bound to typing_extensions.LiteralString)]` but got `str`.
12-
literals_literalstring.py:166:4 Incompatible variable type [9]: x1 is declared to have type `List[str]` but is used as type `List[typing_extensions.LiteralString]`.
12+
literals_literalstring.py:171:4 Incompatible variable type [9]: x1 is declared to have type `List[str]` but is used as type `List[typing_extensions.LiteralString]`.
1313
"""
1414
conformance_automated = "Pass"
1515
errors_diff = """

conformance/results/pyright/literals_literalstring.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ literals_literalstring.py:120:22 - error: Argument of type "str" cannot be assig
1616
literals_literalstring.py:134:51 - error: Argument of type "str" cannot be assigned to parameter "value" of type "T@Container" in function "__init__"
1717
  Type "str" cannot be assigned to type "LiteralString"
1818
    "str" is incompatible with "LiteralString" (reportArgumentType)
19-
literals_literalstring.py:142:5 - error: Overload 1 for "func8" overlaps overload 2 and returns an incompatible type (reportOverlappingOverload)
20-
literals_literalstring.py:142:5 - error: Overload 1 for "func8" overlaps overload 3 and returns an incompatible type (reportOverlappingOverload)
21-
literals_literalstring.py:166:21 - error: Expression of type "list[LiteralString]" cannot be assigned to declared type "list[str]"
19+
literals_literalstring.py:171:21 - error: Expression of type "list[LiteralString]" cannot be assigned to declared type "list[str]"
2220
  "list[LiteralString]" is incompatible with "list[str]"
2321
    Type parameter "_T@list" is invariant, but "LiteralString" is not the same as "str"
2422
    Consider switching from "list" to "Sequence" which is covariant (reportAssignmentType)
2523
"""
26-
conformance_automated = "Fail"
24+
conformance_automated = "Pass"
2725
errors_diff = """
28-
Line 142: Unexpected errors ['literals_literalstring.py:142:5 - error: Overload 1 for "func8" overlaps overload 2 and returns an incompatible type (reportOverlappingOverload)', 'literals_literalstring.py:142:5 - error: Overload 1 for "func8" overlaps overload 3 and returns an incompatible type (reportOverlappingOverload)']
2926
"""

conformance/results/pytype/literals_literalstring.toml

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ File "literals_literalstring.py", line 37, in <module>: Invalid type annotation
1010
File "literals_literalstring.py", line 43, in func1: Type annotation for x2 does not match type of assignment [annotation-type-mismatch]
1111
File "literals_literalstring.py", line 74, in func2: Type annotation for x3 does not match type of assignment [annotation-type-mismatch]
1212
File "literals_literalstring.py", line 75, in func2: Type annotation for x4 does not match type of assignment [annotation-type-mismatch]
13-
File "literals_literalstring.py", line 157, in func8: bad return type [bad-return-type]
13+
File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type]
1414
Called from (traceback):
15-
line 160, in current file
16-
File "literals_literalstring.py", line 162, in <module>: bool [assert-type]
15+
line 166, in current file
16+
File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type]
17+
Called from (traceback):
18+
line 165, in current file
19+
File "literals_literalstring.py", line 167, in <module>: B [assert-type]
1720
"""
1821
conformance_automated = "Fail"
1922
errors_diff = """
2023
Line 66: Expected 1 errors
2124
Line 120: Expected 1 errors
2225
Line 134: Expected 1 errors
23-
Line 166: Expected 1 errors
26+
Line 171: Expected 1 errors
2427
Line 8: Unexpected errors ['File "literals_literalstring.py", line 8, in <module>: typing.LiteralString not supported yet [not-supported-yet]']
2528
Line 24: Unexpected errors ['File "literals_literalstring.py", line 24, in my_function: bad return type [bad-return-type]']
26-
Line 157: Unexpected errors ['File "literals_literalstring.py", line 157, in func8: bad return type [bad-return-type]']
27-
Line 162: Unexpected errors ['File "literals_literalstring.py", line 162, in <module>: bool [assert-type]']
29+
Line 162: Unexpected errors ['File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type]', 'File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type]']
30+
Line 167: Unexpected errors ['File "literals_literalstring.py", line 167, in <module>: B [assert-type]']
2831
"""

conformance/tests/literals_literalstring.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -138,28 +138,33 @@ def func7(s: str):
138138
xs: list[LiteralString] = ["foo", "bar", "baz"]
139139

140140

141+
class A: pass
142+
class B(A): pass
143+
class C(B): pass
144+
145+
141146
@overload
142-
def func8(x: Literal["foo"]) -> int:
147+
def func8(x: Literal["foo"]) -> C:
143148
...
144149

145150

146151
@overload
147-
def func8(x: LiteralString) -> bool:
152+
def func8(x: LiteralString) -> B:
148153
...
149154

150155

151156
@overload
152-
def func8(x: str) -> str:
157+
def func8(x: str) -> A:
153158
...
154159

155160

156161
def func8(x: Any) -> Any:
157162
...
158163

159164

160-
assert_type(func8("foo"), int) # First overload
161-
assert_type(func8("bar"), bool) # Second overload
162-
assert_type(func8(str(1)), str) # Third overload
165+
assert_type(func8("foo"), C) # First overload
166+
assert_type(func8("bar"), B) # Second overload
167+
assert_type(func8(str(1)), A) # Third overload
163168

164169

165170
def func9(val: list[LiteralString]):

0 commit comments

Comments
 (0)