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 |
| | | |
n | def __call__(self, fun): | n | def __call__(self, func): |
| | | |
n | @wraps(fun) | n | @wraps(func) |
| def wrapper(*args, **kwargs): | | def wrapper(*args, **kwargs): |
t | args = tuple((round(arg, self.n) if isinstance(arg, float) e | t | new_args = tuple((round(arg, self.n) if isinstance(arg, floa |
| lse arg for arg in args)) | | t) else arg for arg in args)) |
| kwargs = {key: round(val, self.n) if isinstance(val, float) | | new_kwargs = {key: round(value, self.n) if isinstance(value, |
| else val for key, val in kwargs.items()} | | float) else value for key, value in kwargs.items()} |
| res = fun(*args, **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 |