Skip to content

treat uppercase variables as Final #14445

@scarf005

Description

@scarf005

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions