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
2 changes: 2 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5577,6 +5577,8 @@ def infer_variable_types_from_type_maps(
previous_type, _, _ = self.check_lvalue(expr)
if previous_type is not None:
already_exists = True
if isinstance(expr.node, Var) and expr.node.is_final:
self.msg.cant_assign_to_final(expr.name, False, expr)
if self.check_subtype(
typ,
previous_type,
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -2839,3 +2839,13 @@ match value_type:
case _:
assert_never(value_type)
[builtins fixtures/tuple.pyi]

[case testAssignmentToFinalInMatchCaseNotAllowed]
from typing import Final

FOO: Final[int] = 10

val: int = 8
match val:
case FOO: # E: Cannot assign to final name "FOO"
pass