Skip to content

Add conformance tests to disallow ClassVar/Final in NamedTuple and TypedDict - #2335

Merged
rchen152 merged 1 commit into
python:mainfrom
yangdanny97:final-classvar-tests
Aug 10, 2026
Merged

Add conformance tests to disallow ClassVar/Final in NamedTuple and TypedDict#2335
rchen152 merged 1 commit into
python:mainfrom
yangdanny97:final-classvar-tests

Conversation

@yangdanny97

@yangdanny97 yangdanny97 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

The spec for Final says:

Final cannot be used as a qualifier for a TypedDict item or a NamedTuple field. Such usage also generates an error at runtime.

https://typing.python.org/en/latest/spec/qualifiers.html#semantics-and-examples

The spec for ClassVar says

ClassVar cannot be used as a qualifier for a TypedDict item or a NamedTuple field. Such usage also generates an error at runtime.

https://typing.python.org/en/latest/spec/class-compat.html#classvar

I believe neither rule is currently exercised in the conformance tests. This PR adds tests exercising those rules and regenerates the conformance results.

This should be an easy one to review, the diff is just big because the new imports change the line numbers of a bunch of diagnostics

@yangdanny97

Copy link
Copy Markdown
Contributor Author

Every type checker implements the rule already, except for Pycroscope which seems to allow ClassVar in NamedTuple

@yangdanny97
yangdanny97 marked this pull request as ready for review August 9, 2026 22:10

@jorenham jorenham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Makes sense; thanks!

@rchen152
rchen152 merged commit 043e01d into python:main Aug 10, 2026
5 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.

4 participants