Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c437b6e

Browse filesBrowse files
RazerMmpage
authored andcommitted
pythonGH-83901: Improve Signature.bind error message for missing keyword-only params (python#95347)
Fixes pythonGH-83901
1 parent 864f9b9 commit c437b6e
Copy full SHA for c437b6e

File tree

3 files changed

+9
-3
lines changed
Filter options

3 files changed

+9
-3
lines changed

‎Lib/inspect.py

Copy file name to clipboardExpand all lines: Lib/inspect.py
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,8 +3102,12 @@ def _bind(self, args, kwargs, *, partial=False):
31023102
parameters_ex = (param,)
31033103
break
31043104
else:
3105-
msg = 'missing a required argument: {arg!r}'
3106-
msg = msg.format(arg=param.name)
3105+
if param.kind == _KEYWORD_ONLY:
3106+
argtype = ' keyword-only'
3107+
else:
3108+
argtype = ''
3109+
msg = 'missing a required{argtype} argument: {arg!r}'
3110+
msg = msg.format(arg=param.name, argtype=argtype)
31073111
raise TypeError(msg) from None
31083112
else:
31093113
# We have a positional argument to process

‎Lib/test/test_inspect.py

Copy file name to clipboardExpand all lines: Lib/test/test_inspect.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3898,7 +3898,8 @@ def test(foo, *, bar):
38983898
self.call(test, 1, bar=2, spam='ham')
38993899

39003900
with self.assertRaisesRegex(TypeError,
3901-
"missing a required argument: 'bar'"):
3901+
"missing a required keyword-only "
3902+
"argument: 'bar'"):
39023903
self.call(test, 1)
39033904

39043905
def test(foo, *, bar, **bin):
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve :meth:`Signature.bind <inspect.Signature.bind>` error message for missing keyword-only arguments.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.