CKTIS / Python
typing.ClassVar
Označuje atribút triedy, ktorého priradenie cez inštanciu kontrolór odmietne.
Verzia: Python 3.14; repository image, production runtime not attested
Syntax
class_count: ClassVar[int] = 0Označuje atribút triedy, ktorého priradenie cez inštanciu kontrolór odmietne.
Dátové triedy ho nezahŕňajú medzi polia.
Za behu ho bežná inštancia môže zatieniť a zmenu triedy potom vidí len druhá inštancia.
Príklady
from dataclasses import dataclass, fields
from typing import ClassVar
@dataclass
class Device:
label: str
zone: ClassVar[str] = "west"
a, b = Device("A"), Device("B")
a.zone = "local"
Device.zone = "east"
print([f.name for f in fields(Device)])
print(a.zone, b.zone, Device.zone)
Výsledok
['label'] local east east
Za behu ho bežná inštancia môže zatieniť a zmenu triedy potom vidí len druhá inštancia.