Skip to content

Infer Final from all-caps-named variablesΒ #19987

@m-aciek

Description

@m-aciek

Feature

Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL. (ref. PEP 8)

It's de-facto standard in the industry, therefore we could infer Final from variables written in all capital letters.

Pitch

I think that this behaviour would match natural programmers expectations. Currently the need of using all-caps and a Final type annotation seems not being minimal.

MAX_SIZE = 9000
MAX_SIZE += 1  # Error reported by type checker

class Connection:
    TIMEOUT = 10

class FastConnector(Connection):
    TIMEOUT = 1  # Error reported by type checker

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions