Skip to content

Commit 8437cf5

Browse files
authored
Do not report exhaustive-match after deferral (#19804)
Fixes #19791
1 parent bf77aab commit 8437cf5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mypy/checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5682,8 +5682,8 @@ def visit_match_stmt(self, s: MatchStmt) -> None:
56825682
self.push_type_map(else_map, from_assignment=False)
56835683
unmatched_types = else_map
56845684

5685-
if unmatched_types is not None:
5686-
for typ in list(unmatched_types.values()):
5685+
if unmatched_types is not None and not self.current_node_deferred:
5686+
for typ in unmatched_types.values():
56875687
self.msg.match_statement_inexhaustive_match(typ, s)
56885688

56895689
# This is needed due to a quirk in frame_context. Without it types will stay narrowed

test-data/unit/check-python310.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,3 +2975,18 @@ val: int = 8
29752975
match val:
29762976
case FOO: # E: Cannot assign to final name "FOO"
29772977
pass
2978+
2979+
[case testMatchExhaustivenessWithDeferral]
2980+
# flags: --enable-error-code exhaustive-match
2981+
from typing import Literal
2982+
import unknown_module # E: Cannot find implementation or library stub for module named "unknown_module" \
2983+
# N: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
2984+
2985+
def foo(e: Literal[0, 1]) -> None:
2986+
match e:
2987+
case 0:
2988+
defer
2989+
case 1:
2990+
...
2991+
2992+
defer = unknown_module.foo

0 commit comments

Comments
 (0)