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 |
| | | |
| def __call__(self, func): | | def __call__(self, func): |
| | | |
| @wraps(func) | | @wraps(func) |
n | def wrapped(*args, **kwargs): | n | def wrapper(*args, **kwargs): |
| args = tuple((round(arg, self.n) if isinstance(arg, float) e | | rounded_args = tuple((round(arg, self.n) if isinstance(arg, |
| lse arg for arg in args)) | | float) else arg for arg in args)) |
| kwargs = {key: round(value, self.n) if isinstance(value, flo | | rounded_kwargs = {k: round(v, self.n) if isinstance(v, float |
| at) else value for key, value in kwargs.items()} | | ) else v for k, v in kwargs.items()} |
| result = func(*args, **kwargs) | | result = func(*rounded_args, **rounded_kwargs) |
| return round(result, self.n) if isinstance(result, float) el | | return round(result, self.n) if isinstance(result, float) el |
| se result | | se result |
t | return wrapped | t | return wrapper |