Skip to content

Commit 237a853

Browse files
moved literal redundant test
1 parent cb6a089 commit 237a853

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

test-data/unit/check-kwargs.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,6 @@ kw: dict[Literal["a", "b"], Any]
577577
def func(a, b): ...
578578
func(**kw)
579579

580-
badkw: dict[Literal["one", 1], Any]
581-
func(**badkw) # E: Argument after ** must have string keys
580+
bad_kw: dict[Literal["one", 1], Any]
581+
func(**bad_kw) # E: Argument after ** must have string keys
582582
[builtins fixtures/dict.pyi]

test-data/unit/check-literal.test

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,26 +3135,3 @@ reveal_type(CONST) # N: Revealed type is "Literal['const']?"
31353135
reveal_type(join(Foo.A, CONST)) # N: Revealed type is "builtins.str"
31363136
reveal_type(join(CONST, Foo.A)) # N: Revealed type is "builtins.str"
31373137
[builtins fixtures/tuple.pyi]
3138-
3139-
3140-
[case testLiteralRedundantCast]
3141-
# https://github.com/python/mypy/issues/19055
3142-
# flags: --warn-redundant-cast
3143-
3144-
from typing import Literal, cast
3145-
3146-
# "a" is an AnyOf[str, Literal["a"]], denoted Literal['a']?
3147-
# See: https://github.com/python/typing/issues/566
3148-
3149-
# This cast is not redundant because Literal["a"]? is not identical to Literal["a"]
3150-
LiteralOnly = Literal["a"]
3151-
reveal_type("a") # N: Revealed type is "Literal['a']?"
3152-
cast(LiteralOnly, "a")
3153-
3154-
# This cast is redundant because the type is already Literal["a"]
3155-
already_literal: Literal["a"] = "a"
3156-
reveal_type(already_literal) # N: Revealed type is "Literal['a']"
3157-
cast(LiteralOnly, already_literal) # E: Redundant cast to "Literal['a']"
3158-
3159-
LiteralUnion = Literal["a", "b"]
3160-
cast(LiteralUnion, "a")

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)