diff options
-rw-r--r-- | Lib/inspect.py | 2 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 10 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-10-15-11-37-57.bpo-38478.A87OPO.rst | 3 |
3 files changed, 14 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index c2a1ed4..3ff395c 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2960,7 +2960,7 @@ class Signature: arguments[param.name] = tuple(values) break - if param.name in kwargs: + if param.name in kwargs and param.kind != _POSITIONAL_ONLY: raise TypeError( 'multiple values for argument {arg!r}'.format( arg=param.name)) from None diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 9d28d5a..d95e742 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -3573,6 +3573,16 @@ class TestSignatureBind(unittest.TestCase): iterator = iter(range(5)) 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): def test_signature_bound_arguments_unhashable(self): diff --git a/Misc/NEWS.d/next/Library/2019-10-15-11-37-57.bpo-38478.A87OPO.rst b/Misc/NEWS.d/next/Library/2019-10-15-11-37-57.bpo-38478.A87OPO.rst new file mode 100644 index 0000000..b19fa23 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-10-15-11-37-57.bpo-38478.A87OPO.rst @@ -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. |