mirror of https://github.com/python/cpython.git
GH-83901: Improve Signature.bind error message for missing keyword-only params (#95347)
Fixes GH-83901
This commit is contained in:
parent
5eaf4d6101
commit
f4f8133387
|
@ -3102,8 +3102,12 @@ def _bind(self, args, kwargs, *, partial=False):
|
|||
parameters_ex = (param,)
|
||||
break
|
||||
else:
|
||||
msg = 'missing a required argument: {arg!r}'
|
||||
msg = msg.format(arg=param.name)
|
||||
if param.kind == _KEYWORD_ONLY:
|
||||
argtype = ' keyword-only'
|
||||
else:
|
||||
argtype = ''
|
||||
msg = 'missing a required{argtype} argument: {arg!r}'
|
||||
msg = msg.format(arg=param.name, argtype=argtype)
|
||||
raise TypeError(msg) from None
|
||||
else:
|
||||
# We have a positional argument to process
|
||||
|
|
|
@ -3898,7 +3898,8 @@ def test(foo, *, bar):
|
|||
self.call(test, 1, bar=2, spam='ham')
|
||||
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
"missing a required argument: 'bar'"):
|
||||
"missing a required keyword-only "
|
||||
"argument: 'bar'"):
|
||||
self.call(test, 1)
|
||||
|
||||
def test(foo, *, bar, **bin):
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Improve :meth:`Signature.bind <inspect.Signature.bind>` error message for missing keyword-only arguments.
|
Loading…
Reference in New Issue