classification
Title: inspect.Signature.bind() inaccuracies
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: yselivanov Nosy List: epsy, ncoghlan, python-dev, yselivanov
Priority: normal Keywords: patch

Created on 2013-10-01 20:50 by epsy, last changed 2014-01-28 22:29 by yselivanov. This issue is now closed.

Files
File name Uploaded Description Edit
sig_bind_posodefa_varargs.patch epsy, 2013-10-01 20:50 review
Messages (3)
msg198806 - (view) Author: Yann Kaiser (epsy) Date: 2013-10-01 20:50
A pair of inconsistencies I've found using Signature.bind:

(<a>=0).bind() -*> TypeError
Letting the default value of a positional-only parameter be used raises a TypeError with message that 'a' was passed by name.

(a, *args).bind(a=0, args=1) -> BoundArguments({'a': 0, 'args': 1})
Should positional arguments not be enough for bind() to reach the parameter before *args, bind() will process the *args parameter while looking for named arguments, and eventually bind the *args parameter to any named argument for it, instead of leaving that named argument for **kwargs or erroring out.

I've attached a patch that tests and fixes both issues.

I've taken the liberty of extending test_inspect.TestSignatureBind.test_signature_bind_positional_only as it already did all the setup needed but overlooked to check the condition where a defaulted positional-only parameter is left out.
msg209596 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-01-28 22:28
New changeset 9cb32426d580 by Yury Selivanov in branch 'default':
inspect.Signature.bind: Fix pos-only params with defaults; fix *args in named args #19140
http://hg.python.org/cpython/rev/9cb32426d580
msg209597 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-28 22:29
Pushed in 3.4.
Yann, thank you for the bug report and the patch!
History
Date User Action Args
2014-01-28 22:29:28yselivanovsetstatus: open -> closed
resolution: fixed
messages: + msg209597
2014-01-28 22:28:59python-devsetnosy: + python-dev
messages: + msg209596
2014-01-28 21:45:01yselivanovsetassignee: yselivanov

nosy: + yselivanov
2013-10-01 20:58:58pitrousetnosy: + ncoghlan
2013-10-01 20:50:06epsycreate