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, f): | n | def __call__(self, func): |
| | | |
n | @wraps(f) | n | @wraps(func) |
| def wrapper(*args, **kwargs): | | def wrapper(*args, **kwargs): |
t | round_args = [round(arg, self.n) if isinstance(arg, float) e | t | rounded_args = [round(arg, self.n) if isinstance(arg, float) |
| lse arg for arg in args] | | else arg for arg in args] |
| round_kwargs = {k: round(v, self.n) if isinstance(v, float) | | rounded_kwargs = {k: round(v, self.n) if isinstance(v, float |
| else v for k, v in kwargs.items()} | | ) else v for k, v in kwargs.items()} |
| ret = f(*round_args, **round_kwargs) | | result = func(*rounded_args, **rounded_kwargs) |
| return round(ret, self.n) if isinstance(ret, float) else ret | | return round(result, self.n) if isinstance(result, float) el |
| | | se result |
| return wrapper | | return wrapper |