Skip to content

Commit 8ce5b6a

Browse files
committed
Rename flag to better follow other flags
1 parent ec55c81 commit 8ce5b6a

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

docs/source/command_line.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ of the above sections.
799799
x = 'a string'
800800
x.trim() # error: "str" has no attribute "trim" [attr-defined]
801801
802-
.. option:: --only-allow-exhaustive-match-statements
802+
.. option:: --disallow-inexhaustive-match-statements
803803

804804
This flag will cause mypy to report an error whenever it encounters a match statement
805805
that does not cover all possible cases.
@@ -815,21 +815,25 @@ of the above sections.
815815
816816
val: Color = Color.RED
817817
818-
match val: # error: Cases within match statement do not exhaustively handle all values: "Literal[Color.BLUE]". If not intended to handle all cases, use `case _: pass`
818+
# without --disallow-inexhaustive-match-statements
819+
match val:
819820
case Color.RED:
820821
print("red")
821-
# without --only-allow-exhaustive-match-statements
822+
823+
# Also no issues without --disallow-inexhaustive-match-statements, but this is exhaustive
822824
match val:
823825
case Color.RED:
824826
print("red")
825-
# with --only-allow-exhaustive-match-statements
827+
case _:
828+
print("other")
829+
830+
# with --disallow-inexhaustive-match-statements
826831
match val: # error: Cases within match statement do not exhaustively handle all values: "Literal[Color.BLUE]". If not intended to handle all cases, use `case _: pass`
827832
case Color.RED:
828833
print("red")
829834
830-
831-
# no error with --only-allow-exhaustive-match-statements since all cases are handled
832-
match val: # error: Cases within match statement do not exhaustively handle all values: "Literal[Color.BLUE]". If not intended to handle all cases, use `case _: pass`
835+
# no error with --disallow-inexhaustive-match-statements since all cases are handled
836+
match val:
833837
case Color.RED:
834838
print("red")
835839
case _:

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5512,7 +5512,7 @@ def visit_match_stmt(self, s: MatchStmt) -> None:
55125512
unmatched_types = else_map
55135513

55145514
if (
5515-
self.options.only_allow_exhaustive_match_statements is True
5515+
self.options.disallow_inexhaustive_match_statements is True
55165516
and unmatched_types is not None
55175517
):
55185518
for typ in set(unmatched_types.values()):

mypy/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ def add_invertible_flag(
932932
group=strictness_group,
933933
)
934934
add_invertible_flag(
935-
"--only-allow-exhaustive-match-statements",
935+
"--disallow-inexhaustive-match-statements",
936936
default=False,
937937
strict_flag=False,
938938
help="Raise type error for match statements that do not match exhaustively",

mypy/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def __init__(self) -> None:
350350
self.test_env = False
351351

352352
# Only allow exhaustive match statements
353-
self.only_allow_exhaustive_match_statements = False
353+
self.disallow_inexhaustive_match_statements = False
354354

355355
# -- experimental options --
356356
self.shadow_file: list[list[str]] | None = None

test-data/unit/check-python310.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,7 +2669,7 @@ match b:
26692669

26702670

26712671
[case testExhaustiveMatchWithFlag]
2672-
# flags: --only-allow-exhaustive-match-statements
2672+
# flags: --disallow-inexhaustive-match-statements
26732673

26742674
a: int = 5
26752675
match a:
@@ -2686,7 +2686,7 @@ match b:
26862686
pass
26872687

26882688
[case testNonExhaustiveMatchWithFlag]
2689-
# flags: --only-allow-exhaustive-match-statements
2689+
# flags: --disallow-inexhaustive-match-statements
26902690

26912691
a: int = 5
26922692
match a: # E: Cases within match statement do not exhaustively handle all values: "int". If not intended to handle all cases, use `case _: pass`
@@ -2699,7 +2699,7 @@ match b: # E: Cases within match statement do not exhaustively handle all values
26992699
pass
27002700

27012701
[case testNonExhaustiveMatchEnumWithFlag]
2702-
# flags: --only-allow-exhaustive-match-statements
2702+
# flags: --disallow-inexhaustive-match-statements
27032703

27042704
import enum
27052705

@@ -2720,7 +2720,7 @@ match val: # E: Cases within match statement do not exhaustively handle all valu
27202720

27212721

27222722
[case testExhaustiveMatchEnumWithFlag]
2723-
# flags: --only-allow-exhaustive-match-statements
2723+
# flags: --disallow-inexhaustive-match-statements
27242724

27252725
import enum
27262726

@@ -2739,7 +2739,7 @@ match val:
27392739
[builtins fixtures/enum.pyi]
27402740

27412741
[case testNonExhaustiveMatchEnumMultipleMissingMatchesWithFlag]
2742-
# flags: --only-allow-exhaustive-match-statements
2742+
# flags: --disallow-inexhaustive-match-statements
27432743

27442744
import enum
27452745

@@ -2758,7 +2758,7 @@ match val: # E: Cases within match statement do not exhaustively handle all valu
27582758
[builtins fixtures/enum.pyi]
27592759

27602760
[case testExhaustiveMatchEnumFallbackWithFlag]
2761-
# flags: --only-allow-exhaustive-match-statements
2761+
# flags: --disallow-inexhaustive-match-statements
27622762

27632763
import enum
27642764

0 commit comments

Comments
 (0)