mypy icon indicating copy to clipboard operation
mypy copied to clipboard

treat uppercase variables as `Final`

Open scarf005 opened this issue 2 years ago • 0 comments

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.

image Pylance also uses this convention and warns when UPPERCASE variables are mutated.

scarf005 avatar Jan 14 '23 08:01 scarf005