f | from numbers import Real | f | from numbers import Real |
| from types import FunctionType | | from types import FunctionType |
| | | |
| class fixed(type): | | class fixed(type): |
| | | |
n | def __new__(metaclass, name, parents, ns, ndigits=3): | n | def __new__(metacls, name, parents, ns, ndigits=3): |
| for (i, j) in ns.items(): | | for (i, j) in ns.items(): |
| if isinstance(j, FunctionType): | | if isinstance(j, FunctionType): |
| | | |
| def new(*args, _fun=j, **kwargs): | | def new(*args, _fun=j, **kwargs): |
n | res = _fun(*args, **kwargs) | n | ans = _fun(*args, **kwargs) |
| if isinstance(res, Real): | | if isinstance(ans, Real): |
| return round(res, ndigits) | | return round(ans, ndigits) |
| else: | | else: |
n | return res | n | return ans |
| ns[i] = new | | ns[i] = new |
t | return super().__new__(metaclass, name, parents, ns) | t | return super().__new__(metacls, name, parents, ns) |