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
This flag will cause mypy to report an error whenever it encounters a match statement
805
-
that does not cover all possible cases.
806
-
807
-
.. code-block:: python
808
-
809
-
import enum
810
-
811
-
812
-
classColor(enum.Enum):
813
-
RED=1
814
-
BLUE=2
815
-
816
-
val: Color = Color.RED
817
-
818
-
# without --disallow-inexhaustive-match-statements
819
-
match val:
820
-
case Color.RED:
821
-
print("red")
822
-
823
-
# Also no issues without --disallow-inexhaustive-match-statements, but this is exhaustive
824
-
match val:
825
-
case Color.RED:
826
-
print("red")
827
-
case _:
828
-
print("other")
829
-
830
-
# with --disallow-inexhaustive-match-statements
831
-
# error: Cases within match statement do not exhaustively handle all values: "Literal[Color.BLUE]". If not intended to handle all cases, use `case _: pass`
832
-
match val:
833
-
case Color.RED:
834
-
print("red")
835
-
836
-
# no error with --disallow-inexhaustive-match-statements since all cases are handled
If you use:option:`--disallow-inexhaustive-match-statements <mypy --disallow-inexhaustive-match-statements>`,
622
+
If enabled with:option:`--enable-error-code exhaustive-match <mypy --enable-error-code>`,
623
623
mypy generates an error if a match statement does not match all possible cases/types.
624
624
625
625
@@ -636,25 +636,25 @@ Example:
636
636
637
637
val: Color = Color.RED
638
638
639
-
# without --disallow-inexhaustive-match-statements
639
+
# without --enable-error-code exhaustive-match
640
640
match val:
641
641
case Color.RED:
642
642
print("red")
643
643
644
-
# Also no issues without --disallow-inexhaustive-match-statements, but this is exhaustive
644
+
# Also no issues without --enable-error-code exhaustive-match, but this is exhaustive
645
645
match val:
646
646
case Color.RED:
647
647
print("red")
648
648
case _:
649
649
print("other")
650
650
651
-
# with --disallow-inexhaustive-match-statements
651
+
# with --enable-error-code exhaustive-match
652
652
# error: Cases within match statement do not exhaustively handle all values: "Literal[Color.BLUE]". If not intended to handle all cases, use `case _: pass`
653
653
match val:
654
654
case Color.RED:
655
655
print("red")
656
656
657
-
# no error with --disallow-inexhaustive-match-statements since all cases are handled
657
+
# no error with --enable-error-code exhaustive-match since all cases are handled
0 commit comments