mypy
mypy copied to clipboard
treat uppercase variables as `Final`
Feature
A = 1
A = 2
make A be treated as
from typing import Final
A: Final = 1
A = 2
thus, it will emit error with
test.py:1: error: Cannot assign to final name "A" (because it is uppercase)
Found 1 error in 1 file (checked 1 source file)
Pitch
It would be convenient to not add Final to uppercase variables.
Since pep 8 states that constants are named with uppercase, uppercase variables could be considered Final.
Pylance also uses this convention and warns when UPPERCASE variables are mutated.