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)
| 721 | |
| 722 | @_SpecialForm |
| 723 | def 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 |
| 745 | def Final(self, parameters): |
searching dependent graphs…