|
|
|
|
|
by ianandrich
1684 days ago
|
|
> It might be possible to implement function purity with a decorator. (Kind of like declaring something “safe” in Rust). Two parts to this.
1: Does it mutate variables.
2. Does the code have side effects. 1:
def no_mut(func):
@functools.wraps
def new_func(args, *kwargs):
new_args = tuple(copy.deepcopy(arg) for arg in args)
new_kwargs = {k, copy.deepcopy(v) for k, v in *kwargs
return func(new_args, *new_kwargs)
return new_func For the second point, gevent seemed to have a trick to identify side effecting code. |
|