f | from functools import wraps | f | from functools import wraps |
| | | |
| class Fix: | | class Fix: |
| | | |
| def __init__(self, n): | | def __init__(self, n): |
n | self.n = n | n | self._n = n |
| | | |
| def __call__(self, func): | | def __call__(self, func): |
| | | |
| @wraps(func) | | @wraps(func) |
| def wrapper(*args, **kwargs): | | def wrapper(*args, **kwargs): |
| | | |
n | def round_float(value): | n | def round_if_float(value): |
| if isinstance(value, float): | | if isinstance(value, float): |
t | return round(value, self.n) | t | return round(value, self._n) |
| | | else: |
| return value | | return value |
| new_args = tuple((round_float(arg) for arg in args)) | | rounded_args = tuple((round_if_float(arg) for arg in args)) |
| new_kwargs = {key: round_float(value) for key, value in kwar | | rounded_kwargs = {key: round_if_float(value) for key, value |
| gs.items()} | | in kwargs.items()} |
| result = func(*new_args, **new_kwargs) | | result = func(*rounded_args, **rounded_kwargs) |
| return round_float(result) | | return round_if_float(result) |
| return wrapper | | return wrapper |