-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rely on save_method_args to save method args.
- Loading branch information
Showing
3 changed files
with
26 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Rely on save_method_args to save method args. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import collections | ||
import functools | ||
|
||
|
||
# from jaraco.functools 4.0.2 | ||
def save_method_args(method): | ||
""" | ||
Wrap a method such that when it is called, the args and kwargs are | ||
saved on the method. | ||
""" | ||
args_and_kwargs = collections.namedtuple('args_and_kwargs', 'args kwargs') | ||
|
||
@functools.wraps(method) | ||
def wrapper(self, /, *args, **kwargs): | ||
attr_name = '_saved_' + method.__name__ | ||
attr = args_and_kwargs(args, kwargs) | ||
setattr(self, attr_name, attr) | ||
return method(self, *args, **kwargs) | ||
|
||
return wrapper |