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

Specs clarification: Forbid ClassVar and Final within TypedDict body #1890

Merged
merged 4 commits into from
Dec 8, 2024

Conversation

InSyncWithFoo
Copy link
Contributor

@InSyncWithFoo InSyncWithFoo commented Dec 1, 2024

At runtime, both ClassVar and Final are not recognized as valid qualifiers for TypedDict items:

>>> from typing import TypedDict, ClassVar, Final
>>> class D(TypedDict):
...     a: ClassVar[int]
...
[truncated]
TypeError: typing.ClassVar[int] is not valid as type argument
>>> class D(TypedDict):
...     a: Final[int]
...
[truncated]
TypeError: typing.Final[int] is not valid as type argument

@JelleZijlstra
Copy link
Member

I'd prefer to approach this by being precise about where ClassVar and Final are allowed, as opposed to saying something specific to TypedDicts. For example, are they allowed in NamedTuple bodies?

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this could still be phrased in a more general way, but we can change that later.

@InSyncWithFoo
Copy link
Contributor Author

Is there anything else need to be done here?

@carljm carljm merged commit 6dd6fe4 into python:main Dec 8, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants