classification
Title: inspect.signature.bind does not correctly handle keyword argument with same name as positional-only parameter
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pablogsal Nosy List: brian.shaginaw, miss-islington, pablogsal
Priority: normal Keywords: patch

Created on 2019-10-15 02:26 by brian.shaginaw, last changed 2019-10-15 12:46 by pablogsal. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16800 merged pablogsal, 2019-10-15 10:40
PR 16801 merged miss-islington, 2019-10-15 11:40
Messages (4)
msg354683 - (view) Author: Brian Shaginaw (brian.shaginaw) Date: 2019-10-15 02:26
>>> import inspect
>>> def foo(bar, /, **kwargs):
...   print(bar, kwargs)
...
>>> foo(1, bar=2)
1 {'bar': 2}
>>> inspect.signature(foo).bind(1, bar=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 3025, in bind
    return self._bind(args, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 2964, in _bind
    raise TypeError(
TypeError: multiple values for argument 'bar'


Python 3.8 introduced positional-only parameters, which allow parameter names to remain available for use in **kwargs. It looks like `inspect.signature.bind` does not recognize this, and thinks the parameter is being passed twice, which causes the above TypeError.

Expected result: <BoundArguments (bar=1, kwargs={'bar': 2})>
msg354710 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-10-15 10:42
Thanks, Brian for the report!

I have a fix ready. When merged, this will be available in the next release.
msg354714 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-10-15 11:40
New changeset f3ef06a7cb347ab7bd3cc2b0b3dcebe4f9ff36f9 by Pablo Galindo in branch 'master':
bpo-38478: Correctly handle keyword argument with same name as positional-only parameter (GH-16800)
https://github.com/python/cpython/commit/f3ef06a7cb347ab7bd3cc2b0b3dcebe4f9ff36f9
msg354718 - (view) Author: miss-islington (miss-islington) Date: 2019-10-15 12:02
New changeset f705f8e9b58955d0d9083e98d71ba01b2e69798c by Miss Islington (bot) in branch '3.8':
bpo-38478: Correctly handle keyword argument with same name as positional-only parameter (GH-16800)
https://github.com/python/cpython/commit/f705f8e9b58955d0d9083e98d71ba01b2e69798c
History
Date User Action Args
2019-10-15 12:46:36pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-10-15 12:02:37miss-islingtonsetnosy: + miss-islington
messages: + msg354718
2019-10-15 11:40:26miss-islingtonsetpull_requests: + pull_request16357
2019-10-15 11:40:18pablogsalsetmessages: + msg354714
2019-10-15 10:42:19pablogsalsetversions: + Python 3.9
2019-10-15 10:42:08pablogsalsetmessages: + msg354710
2019-10-15 10:40:56pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request16356
2019-10-15 08:25:03pablogsalsetassignee: pablogsal
2019-10-15 03:28:50xtreaksetnosy: + pablogsal
2019-10-15 02:26:32brian.shaginawcreate