Skip to content

Commit ec55c81

Browse files
committed
Move tests to 3.10 file so only run on >=3.10
1 parent a186cc8 commit ec55c81

File tree

2 files changed

+139
-136
lines changed

2 files changed

+139
-136
lines changed

test-data/unit/check-match-exhaustive.test

Lines changed: 0 additions & 136 deletions
This file was deleted.

test-data/unit/check-python310.test

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,3 +2638,142 @@ def f2() -> None:
26382638
return
26392639
reveal_type(y) # N: Revealed type is "builtins.str"
26402640
[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`
2714+
case Color.RED:
2715+
a = "red"
2716+
case Color.BLUE:
2717+
a= "blue"
2718+
2719+
[builtins fixtures/enum.pyi]
2720+
2721+
2722+
[case testExhaustiveMatchEnumWithFlag]
2723+
# flags: --only-allow-exhaustive-match-statements
2724+
2725+
import enum
2726+
2727+
class Color(enum.Enum):
2728+
RED = 1
2729+
BLUE = 2
2730+
2731+
val: Color = Color.RED
2732+
2733+
match val:
2734+
case Color.RED:
2735+
a = "red"
2736+
case Color.BLUE:
2737+
a= "blue"
2738+
2739+
[builtins fixtures/enum.pyi]
2740+
2741+
[case testNonExhaustiveMatchEnumMultipleMissingMatchesWithFlag]
2742+
# flags: --only-allow-exhaustive-match-statements
2743+
2744+
import enum
2745+
2746+
class Color(enum.Enum):
2747+
RED = 1
2748+
BLUE = 2
2749+
GREEN = 3
2750+
2751+
val: Color = Color.RED
2752+
2753+
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`
2754+
case Color.RED:
2755+
a = "red"
2756+
2757+
2758+
[builtins fixtures/enum.pyi]
2759+
2760+
[case testExhaustiveMatchEnumFallbackWithFlag]
2761+
# flags: --only-allow-exhaustive-match-statements
2762+
2763+
import enum
2764+
2765+
class Color(enum.Enum):
2766+
RED = 1
2767+
BLUE = 2
2768+
GREEN = 3
2769+
2770+
val: Color = Color.RED
2771+
2772+
match val:
2773+
case Color.RED:
2774+
a = "red"
2775+
case _:
2776+
a = "other"
2777+
2778+
2779+
[builtins fixtures/enum.pyi]

0 commit comments

Comments
 (0)