codekingpro/portable-devtools
114k
1import collections2import functools3 4 5# from jaraco.functools 4.0.26def save_method_args(method):7 """8 Wrap a method such that when it is called, the args and kwargs are9 saved on the method.10 """11 args_and_kwargs = collections.namedtuple('args_and_kwargs', 'args kwargs') # noqa: PYI02412 13 @functools.wraps(method)14 def wrapper(self, /, *args, **kwargs):15 attr_name = '_saved_' + method.__name__16 attr = args_and_kwargs(args, kwargs)17 setattr(self, attr_name, attr)18 return method(self, *args, **kwargs)19 20 return wrapper21 