A decorator for creating a static property for Enum classes.
Source code in src\utils\properties.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 | class enum_class_prop:
"""A decorator for creating a static property for Enum classes."""
def __init__(self, method: Callable):
"""Initializes the property.
Args:
method: Class method being decorated.
"""
self._method = method
self._name = method.__name__
def __get__(self, instance: Any, owner: Any) -> Any:
"""Computes and caches the value of a property when accessed.
Args:
instance: Instance of the class where descriptor is accessed.
owner: The class that the descriptor exists on.
Returns:
The cached value.
"""
value = self._method(owner)
setattr(owner, self._name, value)
return value
|