f | from functools import wraps | f | from functools import wraps |
| | | |
| class Fix: | | class Fix: |
| | | |
| def __init__(self, n): | | def __init__(self, n): |
n | self._n = n | n | self.n = n |
| | | |
| def __call__(self, func): | | def __call__(self, func): |
| | | |
| @wraps(func) | | @wraps(func) |
| def wrapper(*args, **kwargs): | | def wrapper(*args, **kwargs): |
| | | |
n | def round_if_float(value): | n | def round_value(value): |
| if isinstance(value, float): | | if isinstance(value, float): |
n | return round(value, self._n) | n | return round(value, self.n) |
| else: | | |
| return value | | return value |
| rounded_args = tuple((round_if_float(arg) for arg in args)) | | rounded_args = tuple((round_value(arg) for arg in args)) |
| rounded_kwargs = {key: round_if_float(value) for key, value | | rounded_kwargs = {key: round_value(val) for key, val in kwar |
| in kwargs.items()} | | gs.items()} |
| result = func(*rounded_args, **rounded_kwargs) | | result = func(*rounded_args, **rounded_kwargs) |
t | return round_if_float(result) | t | return round_value(result) |
| return wrapper | | return wrapper |