Skip to content

Commit 55456ba

Browse files
fixed test after rebase
1 parent 473fb48 commit 55456ba

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

test-data/unit/check-python310.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2917,7 +2917,7 @@ match m[k]:
29172917

29182918
match 0:
29192919
case 0 as i:
2920-
reveal_type(i) # N: Revealed type is "Literal[0]"
2920+
reveal_type(i) # N: Revealed type is "Literal[0]?"
29212921
case int(i):
29222922
i # E: Statement is unreachable
29232923
case other:

test-data/unit/check-warnings.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ from typing import cast
4949
a = 1
5050
b = cast(object, 1)
5151

52+
[case testLiteralRedundantCast]
53+
# https://github.com/python/mypy/issues/19055
54+
# flags: --warn-redundant-cast
55+
56+
from typing import Literal, cast
57+
58+
# "a" is an AnyOf[str, Literal["a"]], denoted Literal['a']?
59+
# See: https://github.com/python/typing/issues/566
60+
61+
# This cast is not redundant because Literal["a"]? is not identical to Literal["a"]
62+
LiteralOnly = Literal["a"]
63+
reveal_type("a") # N: Revealed type is "Literal['a']?"
64+
cast(LiteralOnly, "a")
65+
66+
# This cast is redundant because the type is already Literal["a"]
67+
already_literal: Literal["a"] = "a"
68+
reveal_type(already_literal) # N: Revealed type is "Literal['a']"
69+
cast(LiteralOnly, already_literal) # E: Redundant cast to "Literal['a']"
70+
71+
LiteralUnion = Literal["a", "b"]
72+
cast(LiteralUnion, "a")
5273

5374
[case testCastFromUnionOfAnyOk]
5475
# flags: --warn-redundant-casts

0 commit comments

Comments
 (0)