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