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__(metacls, name, parents, ns, ndigits=3): | n | def __new__(metaclass, 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 | ans = _fun(*args, **kwargs) | n | res = _fun(*args, **kwargs) |
| if isinstance(ans, Real): | | if isinstance(res, Real): |
| return round(ans, ndigits) | | return round(res, ndigits) |
| else: | | else: |
n | return ans | n | return res |
| ns[i] = new | | ns[i] = new |
t | return super().__new__(metacls, name, parents, ns) | t | return super().__new__(metaclass, name, parents, ns) |