Commit c6b40df
authored
Prevent final reassignment in match case (#19496)
Fixes #19507
This PR adds a check to prevent reassignment of final variables in a
match statement.
Currently, the following passes without an error:
```Python
from typing import Final
FOO: Final = 8
a = 10
match a:
case FOO:
pass
print(FOO) # FOO is reassigned, prints 10
```
MyPy already checks that the type of FOO isn't changed if used like
this. I added a check in the same place that makes sure it's not `Final`
either.
Since this tests the match syntax, I put the test where I did. If it's
not the appropriate place for it I will move it as instructed :)1 parent 31adfb4 commit c6b40df
2 files changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5577 | 5577 | | |
5578 | 5578 | | |
5579 | 5579 | | |
| 5580 | + | |
| 5581 | + | |
5580 | 5582 | | |
5581 | 5583 | | |
5582 | 5584 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2839 | 2839 | | |
2840 | 2840 | | |
2841 | 2841 | | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
| 2851 | + | |
0 commit comments