f | from functools import wraps | f | from functools import wraps |
| | | |
| class Fix: | | class Fix: |
| | | |
n | def __init__(self, precision): | n | def __init__(self, n): |
| self.precision = precision | | self.n = n |
| | | |
n | def __call__(self, target_function): | n | def __call__(self, f): |
| | | |
t | @wraps(target_function) | t | @wraps(f) |
| def decorated_function(*args, **kwargs): | | def wrapper(*args, **kwargs): |
| processed_args = [round(arg, self.precision) if isinstance(a | | round_args = [round(arg, self.n) if isinstance(arg, float) e |
| rg, float) else arg for arg in args] | | lse arg for arg in args] |
| processed_kwargs = {key: round(value, self.precision) if isi | | round_kwargs = {k: round(v, self.n) if isinstance(v, float) |
| nstance(value, float) else value for key, value in kwargs.items()} | | else v for k, v in kwargs.items()} |
| result = target_function(*processed_args, **processed_kwargs | | ret = f(*round_args, **round_kwargs) |
| ) | | |
| return round(result, self.precision) if isinstance(result, f | | return round(ret, self.n) if isinstance(ret, float) else ret |
| loat) else result | | |
| return decorated_function | | return wrapper |