KEMBAR78
Disallow `ClassVar` and `Final` qualifiers in `TypedDict` and `NamedTuple` items · Issue #18220 · python/mypy · GitHub
Skip to content

Disallow ClassVar and Final qualifiers in TypedDict and NamedTuple items #18220

@brianschubert

Description

@brianschubert

Both ClassVar and Final produce runtime errors when used in the body of a TypedDict or NamedTuple.

Mypy already emits an error for Final, but the error message could be clarified.

class TD(TypedDict):
    a: Final[int]     # E: Final can be only used as an outermost qualifier in a variable annotation
    b: ClassVar[int]  # Runtime error, no mypy error

class NT(NamedTuple):
    a: Final[int]     # E: Final name must be initialized with a value \
                      # E: Final can be only used as an outermost qualifier in a variable annotation
    b: ClassVar[int]  # Runtime error, no mypy error

Follows from

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions