MCPcopy Index your code
hub / github.com/python/cpython / ClassVar

Function ClassVar

Lib/typing.py:723–742  ·  view source on GitHub ↗

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

(self, parameters)

Source from the content-addressed store, hash-verified

721
722@_SpecialForm
723def ClassVar(self, parameters):
724 """Special type construct to mark class variables.
725
726 An annotation wrapped in ClassVar indicates that a given
727 attribute is intended to be used as a class variable and
728 should not be set on instances of that class.
729
730 Usage::
731
732 class Starship:
733 stats: ClassVar[dict[str, int]] = {} # class variable
734 damage: int = 10 # instance variable
735
736 ClassVar accepts only types and cannot be further subscribed.
737
738 Note that ClassVar is not a class itself, and should not
739 be used with isinstance() or issubclass().
740 """
741 item = _type_check(parameters, f'{self} accepts only single type.', allow_special_forms=True)
742 return _GenericAlias(self, (item,))
743
744@_SpecialForm
745def Final(self, parameters):

Callers 1

test_cannot_initMethod · 0.90

Calls 2

_type_checkFunction · 0.85
_GenericAliasClass · 0.85

Tested by 1

test_cannot_initMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…