Skip to content

Commit 3eaa5ad

Browse files
committed
error message change, use notes
1 parent da2752a commit 3eaa5ad

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

mypy/messages.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,11 +2488,13 @@ def type_parameters_should_be_declared(self, undeclared: list[str], context: Con
24882488

24892489
def match_statement_inexhaustive_match(self, typ: Type, context: Context) -> None:
24902490
type_str = format_type(typ, self.options)
2491-
msg = (
2492-
f"Cases within match statement do not exhaustively handle all values: {type_str}."
2493-
" If not intended to handle all cases, use `case _: pass`"
2494-
)
2491+
msg = f"Match statement has unhandled case for values of type {type_str}"
24952492
self.fail(msg, context, code=codes.EXHAUSTIVE_MATCH)
2493+
self.note(
2494+
"If match statement is intended to be non-exhaustive, add `case _: pass`",
2495+
context,
2496+
code=codes.EXHAUSTIVE_MATCH,
2497+
)
24962498

24972499

24982500
def quote_type_string(type_string: str) -> str:

test-data/unit/check-python310.test

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,15 +2689,16 @@ match b:
26892689
# flags: --enable-error-code exhaustive-match
26902690

26912691
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`
2692+
match a: # E: Match statement has unhandled case for values of type "int" \
2693+
# N: If match statement is intended to be non-exhaustive, add `case _: pass`
26932694
case 1:
26942695
pass
26952696

26962697
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+
match b: # E: Match statement has unhandled case for values of type "str" \
2699+
# N: If match statement is intended to be non-exhaustive, add `case _: pass`
26982700
case "bye":
26992701
pass
2700-
27012702
[case testNonExhaustiveMatchEnumWithFlag]
27022703
# flags: --enable-error-code exhaustive-match
27032704

@@ -2710,7 +2711,8 @@ class Color(enum.Enum):
27102711

27112712
val: Color = Color.RED
27122713

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+
match val: # E: Match statement has unhandled case for values of type "Literal[Color.GREEN]" \
2715+
# N: If match statement is intended to be non-exhaustive, add `case _: pass`
27142716
case Color.RED:
27152717
a = "red"
27162718
case Color.BLUE:
@@ -2747,7 +2749,8 @@ class Color(enum.Enum):
27472749

27482750
val: Color = Color.RED
27492751

2750-
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`
2752+
match val: # E: Match statement has unhandled case for values of type "Literal[Color.BLUE, Color.GREEN]" \
2753+
# N: If match statement is intended to be non-exhaustive, add `case _: pass`
27512754
case Color.RED:
27522755
a = "red"
27532756
[builtins fixtures/enum.pyi]
@@ -2786,8 +2789,9 @@ class B(TypedDict):
27862789
num: int
27872790

27882791
d: A | B
2789-
match d["tag"]: # E: Cases within match statement do not exhaustively handle all values: "Literal['b']". If not intended to handle all cases, use `case _: pass` \
2790-
# E: Cases within match statement do not exhaustively handle all values: "B". If not intended to handle all cases, use `case _: pass`
2792+
match d["tag"]: # E: Match statement has unhandled case for values of type "Literal['b']" \
2793+
# N: If match statement is intended to be non-exhaustive, add `case _: pass` \
2794+
# E: Match statement has unhandled case for values of type "B"
27912795
case "a":
27922796
reveal_type(d) # N: Revealed type is "TypedDict('__main__.A', {'tag': Literal['a'], 'name': builtins.str})"
27932797
reveal_type(d["name"]) # N: Revealed type is "builtins.str"

0 commit comments

Comments
 (0)