f | def fix(n): | f | def fix(n): |
| | | |
n | def decorator(fun): | n | def dec(fun): |
| | | |
| def newfun(*args, **kwargs): | | def newfun(*args, **kwargs): |
n | new_args = [round(item, n) if isinstance(item, float) else item for item in args] | n | pos_args = [round(_, n) if isinstance(_, float) else _ for _ in args] |
| new_kwargs = {k: round(v, n) if isinstance(v, float) else v for (k, v) in kwargs.items()} | | named_args = {key: round(value, n) if isinstance(value, float) else value for (key, value) in kwargs.items()} |
| ret = fun(*new_args, **new_kwargs) | | res = fun(*pos_args, **named_args) |
| return round(ret, n) if isinstance(ret, float) else ret | | return round(res, n) if isinstance(res, float) else res |
| return newfun | | return newfun |
t | return decorator | t | return dec |