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 | new_args = tuple((round(elem, self.n) if isinstance(elem, fl | t | rounded_args = tuple((round(arg, self.n) if isinstance(arg, |
| oat) else elem for elem in args)) | | float) else arg for arg in args)) |
| new_kwargs = {key: round(value, self.n) if isinstance(value, | | rounded_kwargs = {k: round(v, self.n) if isinstance(v, float |
| float) else value for key, value in kwargs.items()} | | ) else v for k, v in kwargs.items()} |
| res = fun(*new_args, **new_kwargs) | | result = func(*rounded_args, **rounded_kwargs) |
| return round(res, self.n) if isinstance(res, float) else res | | return round(result, self.n) if isinstance(result, float) el |
| | | se result |
| return wrapper | | return wrapper |