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 Sep 13, 2024
1 parent e23cbba commit b93c977
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from .compat.py310 import text_encoding
from .glob import Translator

from ._functools import save_method_args


__all__ = ['Path']


Expand Down Expand Up @@ -86,13 +89,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 b93c977

Please sign in to comment.