diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2019-10-15 11:40:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-15 11:40:02 (GMT) |
commit | f3ef06a7cb347ab7bd3cc2b0b3dcebe4f9ff36f9 (patch) | |
tree | 14fd293892933aadf389040db8e2be63cab4abf6 /Lib | |
parent | eb1dda2b56f67f09352c303588c28880c471ae87 (diff) | |
download | cpython-f3ef06a7cb347ab7bd3cc2b0b3dcebe4f9ff36f9.zip cpython-f3ef06a7cb347ab7bd3cc2b0b3dcebe4f9ff36f9.tar.gz cpython-f3ef06a7cb347ab7bd3cc2b0b3dcebe4f9ff36f9.tar.bz2 |
bpo-38478: Correctly handle keyword argument with same name as positional-only parameter (GH-16800)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/inspect.py | 2 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 10 |
2 files changed, 11 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): |