mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
inspect.signature: Make Signature and Parameter picklable. Closes #20726
This commit is contained in:
parent
21e83a5564
commit
a5d63dd7b8
4 changed files with 78 additions and 0 deletions
|
|
@ -2106,6 +2106,18 @@ class Parameter:
|
|||
|
||||
self._partial_kwarg = _partial_kwarg
|
||||
|
||||
def __reduce__(self):
|
||||
return (type(self),
|
||||
(self._name, self._kind),
|
||||
{'_partial_kwarg': self._partial_kwarg,
|
||||
'_default': self._default,
|
||||
'_annotation': self._annotation})
|
||||
|
||||
def __setstate__(self, state):
|
||||
self._partial_kwarg = state['_partial_kwarg']
|
||||
self._default = state['_default']
|
||||
self._annotation = state['_annotation']
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
|
@ -2658,6 +2670,14 @@ class Signature:
|
|||
'''
|
||||
return args[0]._bind(args[1:], kwargs, partial=True)
|
||||
|
||||
def __reduce__(self):
|
||||
return (type(self),
|
||||
(tuple(self._parameters.values()),),
|
||||
{'_return_annotation': self._return_annotation})
|
||||
|
||||
def __setstate__(self, state):
|
||||
self._return_annotation = state['_return_annotation']
|
||||
|
||||
def __str__(self):
|
||||
result = []
|
||||
render_pos_only_separator = False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue