Skip to content

Detect if there is no binding to a symbol declared Final #872

@sharkdp

Description

@sharkdp

This should be an error: the constant is declared Final, but there is no binding:

CONSTANT: Final[int]  # this should be an error

Note that we do allow separating the declaration and the binding of a Final symbol:

CONSTANT: Final[int]  # this is allowed
CONSTANT = 1

Also, even if we would disallow this particular pattern (it's not explicitly required by the spec), Final-annotations without a right-hand side can appear in (data)class definitions, for example:

class C:
    CONSTANT: Final[int]  # this is allowed

    def __init__(self):
        self.CONSTANT = 1

We have existing tests for this here.

Metadata

Metadata

Assignees

Labels

typing semanticstyping-module features, spec compliance, etc

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions