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)
| 698 | |
| 699 | @_SpecialForm |
| 700 | def 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 |
| 722 | def Final(self, parameters): |