Visitar URL original
gh-87106: Fix `inspect.signature.bind` handling of positional-only arguments with `**kwargs` by jacobtylerwalls · Pull Request #103404 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor to avoid pop-and-maybe-put-back pattern
  • Loading branch information
jacobtylerwalls committed May 5, 2024
commit 2ecde833fe273703ff40573491099f5cb544626d
10 changes: 4 additions & 6 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,9 @@ def _bind(self, args, kwargs, *, partial=False):
# before reaching the last parameter before *args.
continue

if param.kind == _POSITIONAL_ONLY:
continue
Comment thread
jacobtylerwalls marked this conversation as resolved.
Outdated

param_name = param.name
try:
arg_val = kwargs.pop(param_name)
Expand All @@ -3283,13 +3286,8 @@ def _bind(self, args, kwargs, *, partial=False):
param.default is _empty):
raise TypeError('missing a required argument: {arg!r}'. \
format(arg=param_name)) from None

else:
if param.kind == _POSITIONAL_ONLY:
# Restore the param in case there is a kwargs_param
kwargs[param_name] = arg_val
else:
arguments[param_name] = arg_val
arguments[param_name] = arg_val

if kwargs:
if kwargs_param is not None:
Expand Down