[ty] Disallow assignment to Final class attributes (#19457)

## Summary

Emit errors for the following assignments:
```py
class C:
    CLASS_LEVEL_CONSTANT: Final[int] = 1

C.CLASS_LEVEL_CONSTANT = 2
C().CLASS_LEVEL_CONSTANT = 2
```

## Test Plan

Updated and new MD tests
This commit is contained in:
David Peter 2025-07-21 14:27:56 +02:00 committed by GitHub
parent f063c0e874
commit b6579eaf04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 63 additions and 20 deletions

View file

@ -498,7 +498,7 @@ class C:
reveal_type(C.__init__) # revealed: (self: C, instance_variable_no_default: int, instance_variable: int = Literal[1]) -> None
c = C(1)
# TODO: this should be an error
# error: [invalid-assignment] "Cannot assign to final attribute `instance_variable` on type `C`"
c.instance_variable = 2
```