File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -5577,6 +5577,8 @@ def infer_variable_types_from_type_maps(
5577
5577
previous_type , _ , _ = self .check_lvalue (expr )
5578
5578
if previous_type is not None :
5579
5579
already_exists = True
5580
+ if isinstance (expr .node , Var ) and expr .node .is_final :
5581
+ self .msg .cant_assign_to_final (expr .name , False , expr )
5580
5582
if self .check_subtype (
5581
5583
typ ,
5582
5584
previous_type ,
Original file line number Diff line number Diff line change @@ -2839,3 +2839,13 @@ match value_type:
2839
2839
case _:
2840
2840
assert_never(value_type)
2841
2841
[builtins fixtures/tuple.pyi]
2842
+
2843
+ [case testAssignmentToFinalInMatchCaseNotAllowed]
2844
+ from typing import Final
2845
+
2846
+ FOO: Final = 8
2847
+
2848
+ val = 8
2849
+ match val:
2850
+ case FOO: # E: Cannot assign to final name "FOO"
2851
+ pass
You can’t perform that action at this time.
0 commit comments