diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2017-06-15 14:42:01 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-06-15 14:42:01 (GMT) |
commit | fb0825c2784f80689c4c00c3ede22958faaf512c (patch) | |
tree | a31eaa48daa4c2fd367f68101542e169d036bdea /Lib/inspect.py | |
parent | c5a6fb654a280c7b17f1d348e2e40d62ca04c5d3 (diff) | |
download | cpython-fb0825c2784f80689c4c00c3ede22958faaf512c.zip cpython-fb0825c2784f80689c4c00c3ede22958faaf512c.tar.gz cpython-fb0825c2784f80689c4c00c3ede22958faaf512c.tar.bz2 |
bpo-30149: Fix partialmethod without explicit self parameter (#1308) (#1663)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 4a11006..424c945 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2220,11 +2220,16 @@ def _signature_from_callable(obj, *, sigcls=sigcls) 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()) - - return sig.replace(parameters=new_params) + if first_wrapped_param.kind is Parameter.VAR_POSITIONAL: + # First argument of the wrapped callable is `*args`, as in + # `partialmethod(lambda *args)`. + return sig + else: + sig_params = tuple(sig.parameters.values()) + assert first_wrapped_param is not sig_params[0] + new_params = (first_wrapped_param,) + sig_params + return sig.replace(parameters=new_params) if isfunction(obj) or _signature_is_functionlike(obj): # If it's a pure Python function, or an object that is duck type |