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-python310.test
+139Lines changed: 139 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2638,3 +2638,142 @@ def f2() -> None:
2638
2638
return
2639
2639
reveal_type(y) # N: Revealed type is "builtins.str"
2640
2640
[builtins fixtures/list.pyi]
2641
+
2642
+
[case testExhaustiveMatchNoFlag]
2643
+
2644
+
a: int = 5
2645
+
match a:
2646
+
case 1:
2647
+
pass
2648
+
case _:
2649
+
pass
2650
+
2651
+
b: str = "hello"
2652
+
match b:
2653
+
case "bye":
2654
+
pass
2655
+
case _:
2656
+
pass
2657
+
2658
+
[case testNonExhaustiveMatchNoFlag]
2659
+
2660
+
a: int = 5
2661
+
match a:
2662
+
case 1:
2663
+
pass
2664
+
2665
+
b: str = "hello"
2666
+
match b:
2667
+
case "bye":
2668
+
pass
2669
+
2670
+
2671
+
[case testExhaustiveMatchWithFlag]
2672
+
# flags: --only-allow-exhaustive-match-statements
2673
+
2674
+
a: int = 5
2675
+
match a:
2676
+
case 1:
2677
+
pass
2678
+
case _:
2679
+
pass
2680
+
2681
+
b: str = "hello"
2682
+
match b:
2683
+
case "bye":
2684
+
pass
2685
+
case _:
2686
+
pass
2687
+
2688
+
[case testNonExhaustiveMatchWithFlag]
2689
+
# flags: --only-allow-exhaustive-match-statements
2690
+
2691
+
a: int = 5
2692
+
match a: # E: Cases within match statement do not exhaustively handle all values: "int". If not intended to handle all cases, use `case _: pass`
2693
+
case 1:
2694
+
pass
2695
+
2696
+
b: str = "hello"
2697
+
match b: # E: Cases within match statement do not exhaustively handle all values: "str". If not intended to handle all cases, use `case _: pass`
2698
+
case "bye":
2699
+
pass
2700
+
2701
+
[case testNonExhaustiveMatchEnumWithFlag]
2702
+
# flags: --only-allow-exhaustive-match-statements
2703
+
2704
+
import enum
2705
+
2706
+
class Color(enum.Enum):
2707
+
RED = 1
2708
+
BLUE = 2
2709
+
GREEN = 3
2710
+
2711
+
val: Color = Color.RED
2712
+
2713
+
match val: # E: Cases within match statement do not exhaustively handle all values: "Literal[Color.GREEN]". If not intended to handle all cases, use `case _: pass`
match val: # E: Cases within match statement do not exhaustively handle all values: "Literal[Color.BLUE, Color.GREEN]". If not intended to handle all cases, use `case _: pass`
0 commit comments