f | from functools import wraps | f | from functools import wraps |
| | | |
| class Fix: | | class Fix: |
| | | |
n | def __init__(self, precision): | n | def __init__(self, n): |
| self.precision = precision | | self.n = n |
| | | |
| def __call__(self, func): | | def __call__(self, func): |
| | | |
| @wraps(func) | | @wraps(func) |
n | def wrapped(*args, **kwargs): | n | def wrapper(*args, **kwargs): |
| processed_args = tuple((self._apply_rounding(arg) for arg in | | args = tuple((self._round(value) for value in args)) |
| args)) | | |
| processed_kwargs = {key: self._apply_rounding(value) if isin | | kwargs = {key: self._round(value) if isinstance(value, float |
| stance(value, float) else value for key, value in kwargs.items()} | | ) else value for key, value in kwargs.items()} |
| result = func(*processed_args, **processed_kwargs) | | result = func(*args, **kwargs) |
| return self._apply_rounding(result) | | return self._round(result) |
| return wrapped | | return wrapper |
| | | |
n | def _apply_rounding(self, value): | n | def _round(self, value): |
| if isinstance(value, float): | | if isinstance(value, float): |
t | return round(value, self.precision) | t | return round(value, self.n) |
| return value | | return value |