Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conformance tests: Ignore overlapping overload errors in LiteralString #1701

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions conformance/results/mypy/literals_literalstring.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ literals_literalstring.py:37: error: Parameter 1 of Literal[...] is invalid [va
literals_literalstring.py:43: error: Incompatible types in assignment (expression has type "Literal['two']", variable has type "Literal['']") [assignment]
literals_literalstring.py:74: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
literals_literalstring.py:75: error: Incompatible types in assignment (expression has type "bytes", variable has type "str") [assignment]
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]
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]
literals_literalstring.py:162: error: Expression is of type "bool", not "str" [assert-type]
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]
literals_literalstring.py:167: error: Expression is of type "B", not "A" [assert-type]
"""
conformance_automated = "Fail"
errors_diff = """
Line 66: Expected 1 errors
Line 120: Expected 1 errors
Line 134: Expected 1 errors
Line 166: Expected 1 errors
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]']
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]"]
Line 162: Unexpected errors ['literals_literalstring.py:162: error: Expression is of type "bool", not "str" [assert-type]']
Line 171: Expected 1 errors
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]"]
Line 167: Unexpected errors ['literals_literalstring.py:167: error: Expression is of type "B", not "A" [assert-type]']
"""
2 changes: 1 addition & 1 deletion conformance/results/pyre/literals_literalstring.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ literals_literalstring.py:74:4 Incompatible variable type [9]: x3 is declared to
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']`.
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`.
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`.
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]`.
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]`.
"""
conformance_automated = "Pass"
errors_diff = """
Expand Down
7 changes: 2 additions & 5 deletions conformance/results/pyright/literals_literalstring.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ literals_literalstring.py:120:22 - error: Argument of type "str" cannot be assig
literals_literalstring.py:134:51 - error: Argument of type "str" cannot be assigned to parameter "value" of type "T@Container" in function "__init__"
  Type "str" cannot be assigned to type "LiteralString"
    "str" is incompatible with "LiteralString" (reportArgumentType)
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)
literals_literalstring.py:166:21 - error: Expression of type "list[LiteralString]" cannot be assigned to declared type "list[str]"
literals_literalstring.py:171:21 - error: Expression of type "list[LiteralString]" cannot be assigned to declared type "list[str]"
  "list[LiteralString]" is incompatible with "list[str]"
    Type parameter "_T@list" is invariant, but "LiteralString" is not the same as "str"
    Consider switching from "list" to "Sequence" which is covariant (reportAssignmentType)
"""
conformance_automated = "Fail"
conformance_automated = "Pass"
errors_diff = """
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)']
"""
15 changes: 9 additions & 6 deletions conformance/results/pytype/literals_literalstring.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ File "literals_literalstring.py", line 37, in <module>: Invalid type annotation
File "literals_literalstring.py", line 43, in func1: Type annotation for x2 does not match type of assignment [annotation-type-mismatch]
File "literals_literalstring.py", line 74, in func2: Type annotation for x3 does not match type of assignment [annotation-type-mismatch]
File "literals_literalstring.py", line 75, in func2: Type annotation for x4 does not match type of assignment [annotation-type-mismatch]
File "literals_literalstring.py", line 157, in func8: bad return type [bad-return-type]
File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type]
Called from (traceback):
line 160, in current file
File "literals_literalstring.py", line 162, in <module>: bool [assert-type]
line 166, in current file
File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type]
Called from (traceback):
line 165, in current file
File "literals_literalstring.py", line 167, in <module>: B [assert-type]
"""
conformance_automated = "Fail"
errors_diff = """
Line 66: Expected 1 errors
Line 120: Expected 1 errors
Line 134: Expected 1 errors
Line 166: Expected 1 errors
Line 171: Expected 1 errors
Line 8: Unexpected errors ['File "literals_literalstring.py", line 8, in <module>: typing.LiteralString not supported yet [not-supported-yet]']
Line 24: Unexpected errors ['File "literals_literalstring.py", line 24, in my_function: bad return type [bad-return-type]']
Line 157: Unexpected errors ['File "literals_literalstring.py", line 157, in func8: bad return type [bad-return-type]']
Line 162: Unexpected errors ['File "literals_literalstring.py", line 162, in <module>: bool [assert-type]']
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]']
Line 167: Unexpected errors ['File "literals_literalstring.py", line 167, in <module>: B [assert-type]']
"""
17 changes: 11 additions & 6 deletions conformance/tests/literals_literalstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,33 @@ def func7(s: str):
xs: list[LiteralString] = ["foo", "bar", "baz"]


class A: pass
class B(A): pass
class C(B): pass


@overload
def func8(x: Literal["foo"]) -> int:
def func8(x: Literal["foo"]) -> C:
...


@overload
def func8(x: LiteralString) -> bool:
def func8(x: LiteralString) -> B:
...


@overload
def func8(x: str) -> str:
def func8(x: str) -> A:
...


def func8(x: Any) -> Any:
...


assert_type(func8("foo"), int) # First overload
assert_type(func8("bar"), bool) # Second overload
assert_type(func8(str(1)), str) # Third overload
assert_type(func8("foo"), C) # First overload
assert_type(func8("bar"), B) # Second overload
assert_type(func8(str(1)), A) # Third overload


def func9(val: list[LiteralString]):
Expand Down