FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-38478: Correctly handle keyword argument with same name as positional-only parameter by pablogsal · Pull Request #16800 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Lib/inspect.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2960,7 +2960,7 @@ def _bind(self, args, kwargs, *, partial=False):
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
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_inspect.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,16 @@ def make_set():
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):
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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.

Back | FazBrowse Home | New Git URL