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
Copy file name to clipboardExpand all lines: test-data/unit/check-enum.test
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1405,9 +1405,9 @@ class E(Enum):
1405
1405
1406
1406
e: E
1407
1407
a: Literal[E.A, E.B, E.C] = e
1408
-
b: Literal[E.A, E.B] = e # E: Incompatible types in assignment (expression has type "E", variable has type "Union[Literal[E.A], Literal[E.B]]")
1409
-
c: Literal[E.A, E.C] = e # E: Incompatible types in assignment (expression has type "E", variable has type "Union[Literal[E.A], Literal[E.C]]")
1410
-
b = a # E: Incompatible types in assignment (expression has type "Union[Literal[E.A], Literal[E.B], Literal[E.C]]", variable has type "Union[Literal[E.A], Literal[E.B]]")
1408
+
b: Literal[E.A, E.B] = e # E: Incompatible types in assignment (expression has type "E", variable has type "Literal[E.A, E.B]")
1409
+
c: Literal[E.A, E.C] = e # E: Incompatible types in assignment (expression has type "E", variable has type "Literal[E.A, E.C]")
1410
+
b = a # E: Incompatible types in assignment (expression has type "Literal[E.A, E.B, E.C]", variable has type "Literal[E.A, E.B]")
func('baz') # E: Argument 1 to "func" has incompatible type "Literal['baz']"; expected "Union[Literal['foo'], Literal['bar'], Literal[' foo ']]"
849
+
func('baz') # E: Argument 1 to "func" has incompatible type "Literal['baz']"; expected "Literal['foo', 'bar', ' foo ']"
850
850
851
851
a: Literal['foo']
852
852
b: Literal['bar']
@@ -860,7 +860,7 @@ func(b)
860
860
func(c)
861
861
func(d)
862
862
func(e)
863
-
func(f) # E: Argument 1 to "func" has incompatible type "Union[Literal['foo'], Literal['bar'], Literal['baz']]"; expected "Union[Literal['foo'], Literal['bar'], Literal[' foo ']]"
863
+
func(f) # E: Argument 1 to "func" has incompatible type "Literal['foo', 'bar', 'baz']"; expected "Literal['foo', 'bar', ' foo ']"
864
864
[builtins fixtures/tuple.pyi]
865
865
[out]
866
866
@@ -1129,8 +1129,8 @@ d: int
1129
1129
1130
1130
foo(a)
1131
1131
foo(b)
1132
-
foo(c) # E: Argument 1 to "foo" has incompatible type "Union[Literal[4], Literal[5]]"; expected "Union[Literal[1], Literal[2], Literal[3]]"
1133
-
foo(d) # E: Argument 1 to "foo" has incompatible type "int"; expected "Union[Literal[1], Literal[2], Literal[3]]"
1132
+
foo(c) # E: Argument 1 to "foo" has incompatible type "Literal[4, 5]"; expected "Literal[1, 2, 3]"
1133
+
foo(d) # E: Argument 1 to "foo" has incompatible type "int"; expected "Literal[1, 2, 3]"
1134
1134
[builtins fixtures/tuple.pyi]
1135
1135
[out]
1136
1136
@@ -1144,7 +1144,7 @@ c: Literal[4, 'foo']
1144
1144
1145
1145
foo(a)
1146
1146
foo(b)
1147
-
foo(c) # E: Argument 1 to "foo" has incompatible type "Union[Literal[4], Literal['foo']]"; expected "int"
1147
+
foo(c) # E: Argument 1 to "foo" has incompatible type "Literal[4, 'foo']"; expected "int"
1148
1148
[builtins fixtures/tuple.pyi]
1149
1149
[out]
1150
1150
@@ -1248,19 +1248,19 @@ class Contravariant(Generic[T_contra]): pass
1248
1248
a1: Invariant[Literal[1]]
1249
1249
a2: Invariant[Literal[1, 2]]
1250
1250
a3: Invariant[Literal[1, 2, 3]]
1251
-
a2 = a1 # E: Incompatible types in assignment (expression has type "Invariant[Literal[1]]", variable has type "Invariant[Union[Literal[1], Literal[2]]]")
1252
-
a2 = a3 # E: Incompatible types in assignment (expression has type "Invariant[Union[Literal[1], Literal[2], Literal[3]]]", variable has type "Invariant[Union[Literal[1], Literal[2]]]")
1251
+
a2 = a1 # E: Incompatible types in assignment (expression has type "Invariant[Literal[1]]", variable has type "Invariant[Literal[1, 2]]")
1252
+
a2 = a3 # E: Incompatible types in assignment (expression has type "Invariant[Literal[1, 2, 3]]", variable has type "Invariant[Literal[1, 2]]")
1253
1253
1254
1254
b1: Covariant[Literal[1]]
1255
1255
b2: Covariant[Literal[1, 2]]
1256
1256
b3: Covariant[Literal[1, 2, 3]]
1257
1257
b2 = b1
1258
-
b2 = b3 # E: Incompatible types in assignment (expression has type "Covariant[Union[Literal[1], Literal[2], Literal[3]]]", variable has type "Covariant[Union[Literal[1], Literal[2]]]")
1258
+
b2 = b3 # E: Incompatible types in assignment (expression has type "Covariant[Literal[1, 2, 3]]", variable has type "Covariant[Literal[1, 2]]")
1259
1259
1260
1260
c1: Contravariant[Literal[1]]
1261
1261
c2: Contravariant[Literal[1, 2]]
1262
1262
c3: Contravariant[Literal[1, 2, 3]]
1263
-
c2 = c1 # E: Incompatible types in assignment (expression has type "Contravariant[Literal[1]]", variable has type "Contravariant[Union[Literal[1], Literal[2]]]")
1263
+
c2 = c1 # E: Incompatible types in assignment (expression has type "Contravariant[Literal[1]]", variable has type "Contravariant[Literal[1, 2]]")
foo(a) # E: Argument 1 to "foo" has incompatible type "List[Literal[1]]"; expected "List[Union[Literal[1], Literal[2]]]" \
1278
+
foo(a) # E: Argument 1 to "foo" has incompatible type "List[Literal[1]]"; expected "List[Literal[1, 2]]" \
1279
1279
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
1280
1280
# N: Consider using "Sequence" instead, which is covariant
1281
-
foo(b) # E: Argument 1 to "foo" has incompatible type "List[Union[Literal[1], Literal[2], Literal[3]]]"; expected "List[Union[Literal[1], Literal[2]]]"
1281
+
foo(b) # E: Argument 1 to "foo" has incompatible type "List[Literal[1, 2, 3]]"; expected "List[Literal[1, 2]]"
1282
1282
bar(a)
1283
-
bar(b) # E: Argument 1 to "bar" has incompatible type "List[Union[Literal[1], Literal[2], Literal[3]]]"; expected "Sequence[Union[Literal[1], Literal[2]]]"
1283
+
bar(b) # E: Argument 1 to "bar" has incompatible type "List[Literal[1, 2, 3]]"; expected "Sequence[Literal[1, 2]]"
1284
1284
[builtins fixtures/list.pyi]
1285
1285
[out]
1286
1286
@@ -1363,9 +1363,9 @@ x = b # E: Incompatible types in assignment (expression has type "str", variabl
1363
1363
y = c # E: Incompatible types in assignment (expression has type "bool", variable has type "Literal[True]")
1364
1364
z = d # This is ok: Literal[None] and None are equivalent.
1365
1365
1366
-
combined = a # E: Incompatible types in assignment (expression has type "int", variable has type "Union[Literal[1], Literal['foo'], Literal[True], None]")
1367
-
combined = b # E: Incompatible types in assignment (expression has type "str", variable has type "Union[Literal[1], Literal['foo'], Literal[True], None]")
1368
-
combined = c # E: Incompatible types in assignment (expression has type "bool", variable has type "Union[Literal[1], Literal['foo'], Literal[True], None]")
1366
+
combined = a # E: Incompatible types in assignment (expression has type "int", variable has type "Optional[Literal[1, 'foo', True]]")
1367
+
combined = b # E: Incompatible types in assignment (expression has type "str", variable has type "Optional[Literal[1, 'foo', True]]")
1368
+
combined = c # E: Incompatible types in assignment (expression has type "bool", variable has type "Optional[Literal[1, 'foo', True]]")
1369
1369
combined = d # Also ok, for similar reasons.
1370
1370
1371
1371
e: Literal[1] = 1
@@ -1392,9 +1392,9 @@ a: Literal[1] = 2 # E: Incompatible types in assignment (expression ha
1392
1392
b: Literal["foo"] = "bar" # E: Incompatible types in assignment (expression has type "Literal['bar']", variable has type "Literal['foo']")
1393
1393
c: Literal[True] = False # E: Incompatible types in assignment (expression has type "Literal[False]", variable has type "Literal[True]")
1394
1394
1395
-
d: Literal[1, 2] = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Union[Literal[1], Literal[2]]")
1396
-
e: Literal["foo", "bar"] = "baz" # E: Incompatible types in assignment (expression has type "Literal['baz']", variable has type "Union[Literal['foo'], Literal['bar']]")
1397
-
f: Literal[True, 4] = False # E: Incompatible types in assignment (expression has type "Literal[False]", variable has type "Union[Literal[True], Literal[4]]")
1395
+
d: Literal[1, 2] = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Literal[1, 2]")
1396
+
e: Literal["foo", "bar"] = "baz" # E: Incompatible types in assignment (expression has type "Literal['baz']", variable has type "Literal['foo', 'bar']")
1397
+
f: Literal[True, 4] = False # E: Incompatible types in assignment (expression has type "Literal[False]", variable has type "Literal[True, 4]")
1398
1398
1399
1399
[builtins fixtures/primitives.pyi]
1400
1400
[out]
@@ -1504,7 +1504,7 @@ reveal_type(arr3) # N: Revealed type is "builtins.list[builtins.int*]"
1504
1504
reveal_type(arr4) # N: Revealed type is "builtins.list[builtins.object*]"
1505
1505
reveal_type(arr5) # N: Revealed type is "builtins.list[builtins.object*]"
1506
1506
1507
-
bad: List[Literal[1, 2]] = [1, 2, 3] # E: List item 2 has incompatible type "Literal[3]"; expected "Union[Literal[1], Literal[2]]"
1507
+
bad: List[Literal[1, 2]] = [1, 2, 3] # E: List item 2 has incompatible type "Literal[3]"; expected "Literal[1, 2]"
1508
1508
1509
1509
[builtins fixtures/list.pyi]
1510
1510
[out]
@@ -1619,19 +1619,19 @@ reveal_type(func(a)) # N: Revealed type is "Union[__main__.A, __main__.C]"
1619
1619
reveal_type(func(b)) # N: Revealed type is "__main__.B"
1620
1620
reveal_type(func(c)) # N: Revealed type is "Union[__main__.B, __main__.A]"
1621
1621
reveal_type(func(d)) # N: Revealed type is "__main__.B" \
1622
-
# E: Argument 1 to "func" has incompatible type "Union[Literal[6], Literal[7]]"; expected "Union[Literal[3], Literal[4], Literal[5], Literal[6]]"
1622
+
# E: Argument 1 to "func" has incompatible type "Literal[6, 7]"; expected "Literal[3, 4, 5, 6]"
1623
1623
1624
1624
reveal_type(func(e)) # E: No overload variant of "func" matches argument type "int" \
0 commit comments