def add(self, labels: LabelsType, value: NumericValueType) -> None:
''' Add will add the given value to the counter.
:raises: ValueError if the value is negative. Counters can only
increase.
'''
value = cast(Union[float, int], value) # typing check, no runtime behaviour.
if value < 0:
raise ValueError("Counters can't decrease")
try:
current = self.get_value(labels)
except KeyError:
current = 0
current = cast(Union[float, int], current) # typing check, no runtime behaviour.
self.set_value(labels, current + value)
评论列表
文章目录