Skip to content

Commit

Permalink
Rely on save_method_args to save method args.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 5, 2023
1 parent 1067f1f commit 578fc8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from .py310compat import text_encoding
from .glob import translate

from ._functools import save_method_args


__all__ = ['Path']

Expand Down Expand Up @@ -71,13 +73,12 @@ class InitializedState:
Mix-in to save the initialization state for pickling.
"""

@save_method_args
def __init__(self, *args, **kwargs):
self.__args = args
self.__kwargs = kwargs
super().__init__(*args, **kwargs)

def __getstate__(self):
return self.__args, self.__kwargs
return self._saved___init__.args, self._saved___init__.kwargs

def __setstate__(self, state):
args, kwargs = state
Expand Down
16 changes: 16 additions & 0 deletions zipp/_functools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import collections
import functools


# from jaraco.functools 3.5.2
def save_method_args(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

0 comments on commit 578fc8e

Please sign in to comment.