MCPcopy Index your code
hub / github.com/RustPython/RustPython / ClassVar

Function ClassVar

Lib/typing.py:700–719  ·  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

698
699@_SpecialForm
700def ClassVar(self, parameters):
701 """Special type construct to mark class variables.
702
703 An annotation wrapped in ClassVar indicates that a given
704 attribute is intended to be used as a class variable and
705 should not be set on instances of that class.
706
707 Usage::
708
709 class Starship:
710 stats: ClassVar[dict[str, int]] = {} # class variable
711 damage: int = 10 # instance variable
712
713 ClassVar accepts only types and cannot be further subscribed.
714
715 Note that ClassVar is not a class itself, and should not
716 be used with isinstance() or issubclass().
717 """
718 item = _type_check(parameters, f'{self} accepts only single type.', allow_special_forms=True)
719 return _GenericAlias(self, (item,))
720
721@_SpecialForm
722def 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