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, f): |
| | | |
t | @wraps(fun) | t | @wraps(f) |
| def wrapper(*args, **kwds): | | def wrapper(*args, **kwargs): |
| new_args = [round(arg, self.n) if isinstance(arg, float) els | | round_args = [round(arg, self.n) if isinstance(arg, float) e |
| e arg for arg in args] | | lse arg for arg in args] |
| new_kwds = {k: round(w, self.n) if isinstance(w, float) else | | round_kwargs = {k: round(v, self.n) if isinstance(v, float) |
| w for k, w in kwds.items()} | | else v for k, v in kwargs.items()} |
| res = fun(*new_args, **new_kwds) | | ret = f(*round_args, **round_kwargs) |
| return round(res, self.n) if isinstance(res, float) else res | | return round(ret, self.n) if isinstance(ret, float) else ret |
| return wrapper | | return wrapper |