]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38478: Correctly handle keyword argument with same name as positional-only parame...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 15 Oct 2019 12:02:34 +0000 (05:02 -0700)
committerGitHub <noreply@github.com>
Tue, 15 Oct 2019 12:02:34 +0000 (05:02 -0700)
(cherry picked from commit f3ef06a7cb347ab7bd3cc2b0b3dcebe4f9ff36f9)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Lib/inspect.py
Lib/test/test_inspect.py
Misc/NEWS.d/next/Library/2019-10-15-11-37-57.bpo-38478.A87OPO.rst [new file with mode: 0644]

index c2a1ed4148e74922dd20966b02aa20bbeec4f7da..3ff395ca33377863607846bd07b77bf713e670ec 100644 (file)
@@ -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
index 1c516546f7684054519f8e497a5bea1249883cba..ad93f304827fbaf1aec2006652f459bc4f71375d 100644 (file)
@@ -3577,6 +3577,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 (file)
index 0000000..b19fa23
--- /dev/null
@@ -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.