PyDocs

Nav

Development Tools

ClassVar

typing

data · Added in 3.5.3
Special type construct to mark class variables.

An annotation wrapped in ClassVar indicates that a given
attribute is intended to be used as a class variable and
should not be set on instances of that class.

Usage::

    class Starship:
        stats: ClassVar[dict[str, int]] = {} # class variable
        damage: int = 10                     # instance variable

ClassVar accepts only types and cannot be further subscribed.

Note that ClassVar is not a class itself, and cannot
be used with isinstance() or issubclass().
Changed in 3.13
  • 3.13: ClassVar can now be nested in Final and vice versa.
0 Examples
No examples for typing/ClassVar.
See Also
No see-alsos for typing/ClassVar
0 Notes
No notes for ClassVar