diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2014-01-29 17:18:59 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2014-01-29 17:18:59 (GMT) |
commit | 0486f819c93de81120ad75570df5d6837017c03d (patch) | |
tree | 452ef5711eb8c11a3a19b0993f84d2d11523018d /Lib/inspect.py | |
parent | c45873e4349fcec76870757b43fe24a85b443755 (diff) | |
download | cpython-0486f819c93de81120ad75570df5d6837017c03d.zip cpython-0486f819c93de81120ad75570df5d6837017c03d.tar.gz cpython-0486f819c93de81120ad75570df5d6837017c03d.tar.bz2 |
inspect.signature: Make sure that if a callable object has '_patialmethod'
attribute, that attribute is an instance of 'functools.partialmethod'.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index fbea3df..3ad4a82 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1651,20 +1651,21 @@ def signature(obj): except AttributeError: pass else: - # Unbound partialmethod (see functools.partialmethod) - # This means, that we need to calculate the signature - # as if it's a regular partial object, but taking into - # account that the first positional argument - # (usually `self`, or `cls`) will not be passed - # automatically (as for boundmethods) + if isinstance(partialmethod, functools.partialmethod): + # Unbound partialmethod (see functools.partialmethod) + # This means, that we need to calculate the signature + # as if it's a regular partial object, but taking into + # account that the first positional argument + # (usually `self`, or `cls`) will not be passed + # automatically (as for boundmethods) - wrapped_sig = signature(partialmethod.func) - sig = _signature_get_partial(wrapped_sig, partialmethod, (None,)) + wrapped_sig = signature(partialmethod.func) + sig = _signature_get_partial(wrapped_sig, partialmethod, (None,)) - first_wrapped_param = tuple(wrapped_sig.parameters.values())[0] - new_params = (first_wrapped_param,) + tuple(sig.parameters.values()) + first_wrapped_param = tuple(wrapped_sig.parameters.values())[0] + new_params = (first_wrapped_param,) + tuple(sig.parameters.values()) - return sig.replace(parameters=new_params) + return sig.replace(parameters=new_params) if _signature_is_builtin(obj): return Signature.from_builtin(obj) |