bpo-38478: Correctly handle keyword argument with same name as positional-only parameter (GH-16800)
This commit is contained in:
parent
eb1dda2b56
commit
f3ef06a7cb
|
@ -2960,7 +2960,7 @@ class Signature:
|
||||||
arguments[param.name] = tuple(values)
|
arguments[param.name] = tuple(values)
|
||||||
break
|
break
|
||||||
|
|
||||||
if param.name in kwargs:
|
if param.name in kwargs and param.kind != _POSITIONAL_ONLY:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
'multiple values for argument {arg!r}'.format(
|
'multiple values for argument {arg!r}'.format(
|
||||||
arg=param.name)) from None
|
arg=param.name)) from None
|
||||||
|
|
|
@ -3573,6 +3573,16 @@ class TestSignatureBind(unittest.TestCase):
|
||||||
iterator = iter(range(5))
|
iterator = iter(range(5))
|
||||||
self.assertEqual(self.call(setcomp_func, iterator), {0, 1, 4, 9, 16})
|
self.assertEqual(self.call(setcomp_func, iterator), {0, 1, 4, 9, 16})
|
||||||
|
|
||||||
|
def test_signature_bind_posonly_kwargs(self):
|
||||||
|
def foo(bar, /, **kwargs):
|
||||||
|
return bar, kwargs.get(bar)
|
||||||
|
|
||||||
|
sig = inspect.signature(foo)
|
||||||
|
result = sig.bind("pos-only", bar="keyword")
|
||||||
|
|
||||||
|
self.assertEqual(result.kwargs, {"bar": "keyword"})
|
||||||
|
self.assertIn(("bar", "pos-only"), result.arguments.items())
|
||||||
|
|
||||||
|
|
||||||
class TestBoundArguments(unittest.TestCase):
|
class TestBoundArguments(unittest.TestCase):
|
||||||
def test_signature_bound_arguments_unhashable(self):
|
def test_signature_bound_arguments_unhashable(self):
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Fixed a bug in :meth:`inspect.signature.bind` that was causing it to fail
|
||||||
|
when handling a keyword argument with same name as positional-only parameter.
|
||||||
|
Patch by Pablo Galindo.
|
Loading…
Reference in New Issue