diff --git a/funcsigs/__init__.py b/funcsigs/__init__.py index fd2f47b..7b1e7d7 100644 --- a/funcsigs/__init__.py +++ b/funcsigs/__init__.py @@ -263,6 +263,14 @@ def __init__(self, name, kind, default=_empty, annotation=_empty, self._partial_kwarg = _partial_kwarg + + def __getstate__(self): + return tuple(getattr(self, k) for k in self.__slots__) + + def __setstate__(self, items): + for k, item in zip(self.__slots__, items): + setattr(self, k, item) + @property def name(self): return self._name @@ -509,6 +517,13 @@ def __init__(self, parameters=None, return_annotation=_empty, self._parameters = params self._return_annotation = return_annotation + def __getstate__(self): + return tuple(getattr(self, k) for k in self.__slots__) + + def __setstate__(self, items): + for k, item in zip(self.__slots__, items): + setattr(self, k, item) + @classmethod def from_function(cls, func): '''Constructs Signature for the given python function''' diff --git a/tests/test_inspect.py b/tests/test_inspect.py index 323c323..8c5ab94 100644 --- a/tests/test_inspect.py +++ b/tests/test_inspect.py @@ -1,6 +1,7 @@ # Copyright 2001-2013 Python Software Foundation; All Rights Reserved from __future__ import absolute_import, division, print_function import collections +import pickle import sys try: @@ -65,6 +66,13 @@ def test(po, pk, *args, ko, **kwargs): S((po, pk, args, kwargs2, ko)) """) + def test_signature_pickling(self): + def foo(a): pass + + sig = inspect.signature(foo) + + self.assertEqual(sig, pickle.loads(pickle.dumps(sig))) + def test_signature_immutability(self): def test(a): pass