Skip to content

Commit d219871

Browse files
committed
Add test for more complex narrowing use case
1 parent 681a327 commit d219871

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎test-data/unit/check-python310.test‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,3 +2770,24 @@ match val:
27702770
case _:
27712771
a = "other"
27722772
[builtins fixtures/enum.pyi]
2773+
2774+
# Fork of testMatchNarrowingUnionTypedDictViaIndex to check behaviour with exhaustive match flag
2775+
[case testExhaustiveMatchNarrowingUnionTypedDictViaIndex]
2776+
# flags: --enable-error-code exhaustive-match
2777+
2778+
from typing import Literal, TypedDict
2779+
2780+
class A(TypedDict):
2781+
tag: Literal["a"]
2782+
name: str
2783+
2784+
class B(TypedDict):
2785+
tag: Literal["b"]
2786+
num: int
2787+
2788+
d: A | B
2789+
match d["tag"]: # E: Cases within match statement do not exhaustively handle all values: "B". If not intended to handle all cases, use `case _: pass` # E: Cases within match statement do not exhaustively handle all values: "Literal['b']". If not intended to handle all cases, use `case _: pass`
2790+
case "a":
2791+
reveal_type(d) # N: Revealed type is "TypedDict('__main__.A', {'tag': Literal['a'], 'name': builtins.str})"
2792+
reveal_type(d["name"]) # N: Revealed type is "builtins.str"
2793+
[typing fixtures/typing-typeddict.pyi]

0 commit comments

Comments
 (0)