Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brianschubert opened this issue Dec 1, 2024 · 0 comments · Fixed by #18281
Closed

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

brianschubert opened this issue Dec 1, 2024 · 0 comments · Fixed by #18281

Comments

@brianschubert
Copy link
Collaborator

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

@brianschubert brianschubert added feature topic-named-tuple topic-typed-dict topic-final PEP 591 topic-runtime-semantics mypy doesn't model runtime semantics correctly and removed topic-runtime-semantics mypy doesn't model runtime semantics correctly labels Dec 1, 2024
@sobolevn sobolevn self-assigned this Dec 11, 2024
JukkaL pushed a commit that referenced this issue Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants