[New-bugs-announce] [issue38478] inspect.signature.bind does not correctly handle keyword argument with same name as positional-only parameter

Brian Shaginaw report at bugs.python.org
Mon Oct 14 22:26:32 EDT 2019


New submission from Brian Shaginaw <bshaginaw120 at gmail.com>:

>>> 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})>

----------
components: Library (Lib)
messages: 354683
nosy: brian.shaginaw
priority: normal
severity: normal
status: open
title: inspect.signature.bind does not correctly handle keyword argument with same name as positional-only parameter
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38478>
_______________________________________


More information about the New-bugs-announce mailing list