Skip to content
Discussion options

You must be logged in to vote

ClassVar should not be used outside of a variable declaration within a class. ClassVar is not an annotation that describes the type of a variable, but it describes a (non-type) attribute of a variable. Most other languages offer keywords for such attributes, but Python overloads the type annotation mechanism to handle these cases. Other examples include Final, InitVar, Required, and NotRequired. These special forms should not be used within type aliases because they are not type annotations.

The use of ClassVar should be flagged as an error when used in a type alias like this. When I implemented support for ClassVar in pyright, it never occurred to me that someone would attempt to use it …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@erictraut
Comment options

@bzoracler
Comment options

@erictraut
Comment options

Answer selected by bzoracler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants