Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5682,8 +5682,8 @@ def visit_match_stmt(self, s: MatchStmt) -> None:
self.push_type_map(else_map, from_assignment=False)
unmatched_types = else_map

if unmatched_types is not None:
for typ in list(unmatched_types.values()):
if unmatched_types is not None and not self.current_node_deferred:
for typ in unmatched_types.values():
self.msg.match_statement_inexhaustive_match(typ, s)

# This is needed due to a quirk in frame_context. Without it types will stay narrowed
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -2975,3 +2975,18 @@ val: int = 8
match val:
case FOO: # E: Cannot assign to final name "FOO"
pass

[case testMatchExhaustivenessWithDeferral]
# flags: --enable-error-code exhaustive-match
from typing import Literal
import unknown_module # E: Cannot find implementation or library stub for module named "unknown_module" \
# N: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

def foo(e: Literal[0, 1]) -> None:
match e:
case 0:
defer
case 1:
...

defer = unknown_module.foo
Loading