I have this class:
class MetricInt(int):
"""Int wrapper that adds only during the observation window."""
def __new__(cls, _, initial):
return int.__new__(cls, initial)
def __init__(self, sim, initial):
int.__init__(initial)
self.sim = sim
def __add__(self, val):
if self.sim.in_observe_window():
self = MetricInt(self.sim, super(MetricInt, self).__add__(int(val)))
return self
Which basically overwrite the __add__
method in order to only to the addition if self.sim.in_observe_window()
returns True
.
However, if the initial value is too big, I have :
OverflowError: Python int too large to convert to C long.
What is the correct way to do what I'm trying to do and also handle big numbers?