f | from functools import wraps | f | from functools import wraps |
| | | |
| class Fix: | | class Fix: |
| | | |
| def __init__(self, n): | | def __init__(self, n): |
| self.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): |
t | fixed_args = list((round(arg, self.n) if isinstance(arg, flo | t | new_args = tuple((round(arg, self.n) if isinstance(arg, floa |
| at) else arg for arg in args)) | | t) else arg for arg in args)) |
| fixed_kwargs = {key: round(value, self.n) if isinstance(valu | | new_kwargs = {key: round(value, self.n) if isinstance(value, |
| e, float) else value for key, value in kwargs.items()} | | float) else value for key, value in kwargs.items()} |
| res = func(*fixed_args, **fixed_kwargs) | | result = func(*new_args, **new_kwargs) |
| if isinstance(res, float): | | if isinstance(result, float): |
| res = round(res, self.n) | | result = round(result, self.n) |
| return res | | return result |
| return wrapper | | return wrapper |