You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Conformance: minor update to LiteralString tests (#2179)
I ran into this while looking at ty's conformance results. For an
expression like `str(1)`, ty infers `Literal["1"]`. It can therefore
infer that `some_literal_str + str(1)` is also of type `LiteralString`.
The conformance suite asserts the opposite (that the result should be of
type `str`), based on the assumption that `str(1)` is definitely of type
`str`.
The updated code also seems like a readability-improvement to me, as
there is now just one way to refer to a non-`LiteralStr` object.
The updates here only lead to line-number changes in the results for
all type checkers.
Copy file name to clipboardExpand all lines: conformance/results/mypy/literals_literalstring.toml
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,17 @@ output = """
6
6
literals_literalstring.py:36: error: Parameter 2 of Literal[...] is invalid [valid-type]
7
7
literals_literalstring.py:37: error: Parameter 1 of Literal[...] is invalid [valid-type]
8
8
literals_literalstring.py:43: error: Incompatible types in assignment (expression has type "Literal['two']", variable has type "Literal['']") [assignment]
9
-
literals_literalstring.py:74: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
10
-
literals_literalstring.py:75: error: Incompatible types in assignment (expression has type "bytes", variable has type "str") [assignment]
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 [overload-cannot-match]
12
-
literals_literalstring.py:167: error: Expression is of type "B", not "A" [assert-type]
9
+
literals_literalstring.py:73: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
10
+
literals_literalstring.py:74: error: Incompatible types in assignment (expression has type "bytes", variable has type "str") [assignment]
11
+
literals_literalstring.py:156: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [overload-cannot-match]
12
+
literals_literalstring.py:166: error: Expression is of type "B", not "A" [assert-type]
13
13
"""
14
14
conformance_automated = "Fail"
15
15
errors_diff = """
16
-
Line 66: Expected 1 errors
17
-
Line 120: Expected 1 errors
18
-
Line 134: Expected 1 errors
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 [overload-cannot-match]"]
21
-
Line 167: Unexpected errors ['literals_literalstring.py:167: error: Expression is of type "B", not "A" [assert-type]']
16
+
Line 65: Expected 1 errors
17
+
Line 119: Expected 1 errors
18
+
Line 133: Expected 1 errors
19
+
Line 170: Expected 1 errors
20
+
Line 156: Unexpected errors ["literals_literalstring.py:156: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [overload-cannot-match]"]
21
+
Line 166: Unexpected errors ['literals_literalstring.py:166: error: Expression is of type "B", not "A" [assert-type]']
Copy file name to clipboardExpand all lines: conformance/results/pyrefly/literals_literalstring.toml
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,10 @@ output = """
5
5
ERROR literals_literalstring.py:36:29-42: Invalid type inside literal, `LiteralString` [invalid-literal]
6
6
ERROR literals_literalstring.py:37:22-35: Invalid type inside literal, `LiteralString` [invalid-literal]
7
7
ERROR literals_literalstring.py:43:23-24: `Literal['two']` is not assignable to `Literal['']` [bad-assignment]
8
-
ERROR literals_literalstring.py:66:25-47: `str` is not assignable to `LiteralString` [bad-assignment]
9
-
ERROR literals_literalstring.py:74:25-26: `Literal[3]` is not assignable to `LiteralString` [bad-assignment]
10
-
ERROR literals_literalstring.py:75:25-32: `Literal[b'test']` is not assignable to `LiteralString` [bad-assignment]
11
-
ERROR literals_literalstring.py:120:21-24: `str` is not assignable to upper bound `LiteralString` of type variable `TLiteral` [bad-specialization]
12
-
ERROR literals_literalstring.py:134:51-52: Argument `str` is not assignable to parameter `value` with type `LiteralString` in function `Container.__init__` [bad-argument-type]
13
-
ERROR literals_literalstring.py:171:21-24: `list[LiteralString]` is not assignable to `list[str]` [bad-assignment]
8
+
ERROR literals_literalstring.py:65:25-45: `str` is not assignable to `LiteralString` [bad-assignment]
9
+
ERROR literals_literalstring.py:73:25-26: `Literal[3]` is not assignable to `LiteralString` [bad-assignment]
10
+
ERROR literals_literalstring.py:74:25-32: `Literal[b'test']` is not assignable to `LiteralString` [bad-assignment]
11
+
ERROR literals_literalstring.py:119:21-24: `str` is not assignable to upper bound `LiteralString` of type variable `TLiteral` [bad-specialization]
12
+
ERROR literals_literalstring.py:133:51-52: Argument `str` is not assignable to parameter `value` with type `LiteralString` in function `Container.__init__` [bad-argument-type]
13
+
ERROR literals_literalstring.py:170:21-24: `list[LiteralString]` is not assignable to `list[str]` [bad-assignment]
Copy file name to clipboardExpand all lines: conformance/results/pyright/literals_literalstring.toml
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -4,19 +4,19 @@ literals_literalstring.py:36:29 - error: Type arguments for "Literal" must be No
4
4
literals_literalstring.py:37:22 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
5
5
literals_literalstring.py:43:23 - error: Type "Literal['two']" is not assignable to declared type "Literal['']"
6
6
"Literal['two']" is not assignable to type "Literal['']" (reportAssignmentType)
7
-
literals_literalstring.py:66:25 - error: Type "str" is not assignable to declared type "LiteralString"
7
+
literals_literalstring.py:65:25 - error: Type "str" is not assignable to declared type "LiteralString"
8
8
"str" is not assignable to "LiteralString" (reportAssignmentType)
9
-
literals_literalstring.py:74:25 - error: Type "Literal[3]" is not assignable to declared type "LiteralString"
9
+
literals_literalstring.py:73:25 - error: Type "Literal[3]" is not assignable to declared type "LiteralString"
10
10
"Literal[3]" is not assignable to "LiteralString" (reportAssignmentType)
11
-
literals_literalstring.py:75:25 - error: Type "Literal[b"test"]" is not assignable to declared type "LiteralString"
11
+
literals_literalstring.py:74:25 - error: Type "Literal[b"test"]" is not assignable to declared type "LiteralString"
12
12
"Literal[b"test"]" is not assignable to "LiteralString" (reportAssignmentType)
13
-
literals_literalstring.py:120:22 - error: Argument of type "str" cannot be assigned to parameter "s" of type "TLiteral@literal_identity" in function "literal_identity"
13
+
literals_literalstring.py:119:22 - error: Argument of type "str" cannot be assigned to parameter "s" of type "TLiteral@literal_identity" in function "literal_identity"
14
14
Type "str" is not assignable to type "LiteralString"
15
15
"str" is not assignable to "LiteralString" (reportArgumentType)
16
-
literals_literalstring.py:134:51 - error: Argument of type "str" cannot be assigned to parameter "value" of type "T@Container" in function "__init__"
16
+
literals_literalstring.py:133:51 - error: Argument of type "str" cannot be assigned to parameter "value" of type "T@Container" in function "__init__"
17
17
Type "str" is not assignable to type "LiteralString"
18
18
"str" is not assignable to "LiteralString" (reportArgumentType)
19
-
literals_literalstring.py:171:21 - error: Type "list[LiteralString]" is not assignable to declared type "list[str]"
19
+
literals_literalstring.py:170:21 - error: Type "list[LiteralString]" is not assignable to declared type "list[str]"
20
20
"list[LiteralString]" is not assignable to "list[str]"
21
21
Type parameter "_T@list" is invariant, but "LiteralString" is not the same as "str"
22
22
Consider switching from "list" to "Sequence" which is covariant (reportAssignmentType)
Copy file name to clipboardExpand all lines: conformance/results/zuban/literals_literalstring.toml
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,12 @@ output = """
5
5
literals_literalstring.py:36: error: Parameter 2 of Literal[...] is invalid [valid-type]
6
6
literals_literalstring.py:37: error: Parameter 1 of Literal[...] is invalid [valid-type]
7
7
literals_literalstring.py:43: error: Incompatible types in assignment (expression has type "Literal['two']", variable has type "Literal['']") [assignment]
8
-
literals_literalstring.py:66: error: Incompatible types in assignment (expression has type "str", variable has type "LiteralString") [assignment]
9
-
literals_literalstring.py:74: error: Incompatible types in assignment (expression has type "Literal[3]", variable has type "LiteralString") [assignment]
10
-
literals_literalstring.py:75: error: Incompatible types in assignment (expression has type "Literal[b'test']", variable has type "LiteralString") [assignment]
11
-
literals_literalstring.py:120: error: Value of type variable "TLiteral" of "literal_identity" cannot be "str" [type-var]
12
-
literals_literalstring.py:134: error: Value of type variable "T" of "Container" cannot be "str" [type-var]
13
-
literals_literalstring.py:171: error: Incompatible types in assignment (expression has type "list[LiteralString]", variable has type "list[str]") [assignment]
14
-
literals_literalstring.py:171: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
15
-
literals_literalstring.py:171: note: Consider using "Sequence" instead, which is covariant
8
+
literals_literalstring.py:65: error: Incompatible types in assignment (expression has type "str", variable has type "LiteralString") [assignment]
9
+
literals_literalstring.py:73: error: Incompatible types in assignment (expression has type "Literal[3]", variable has type "LiteralString") [assignment]
10
+
literals_literalstring.py:74: error: Incompatible types in assignment (expression has type "Literal[b'test']", variable has type "LiteralString") [assignment]
11
+
literals_literalstring.py:119: error: Value of type variable "TLiteral" of "literal_identity" cannot be "str" [type-var]
12
+
literals_literalstring.py:133: error: Value of type variable "T" of "Container" cannot be "str" [type-var]
13
+
literals_literalstring.py:170: error: Incompatible types in assignment (expression has type "list[LiteralString]", variable has type "list[str]") [assignment]
14
+
literals_literalstring.py:170: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
15
+
literals_literalstring.py:170: note: Consider using "Sequence" instead, which is covariant
0 commit comments