Skip to content

Commit 68ec454

Browse files
gh-135160: Fix the use of the terms "argument" and "parameter" in error messages for invalid function calls
1 parent 3d396ab commit 68ec454

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

Lib/inspect.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ def _missing_arguments(f_name, argnames, pos, values):
13911391
s = ", ".join(names) + tail
13921392
raise TypeError("%s() missing %i required %s argument%s: %s" %
13931393
(f_name, missing,
1394-
"positional" if pos else "keyword-only",
1394+
"positional" if pos else "keyword",
13951395
"" if missing == 1 else "s", s))
13961396

13971397
def _too_many(f_name, args, kwonly, varargs, defcount, given, values):
@@ -1408,7 +1408,7 @@ def _too_many(f_name, args, kwonly, varargs, defcount, given, values):
14081408
sig = str(len(args))
14091409
kwonly_sig = ""
14101410
if kwonly_given:
1411-
msg = " positional argument%s (and %d keyword-only argument%s)"
1411+
msg = " positional argument%s (and %d keyword argument%s)"
14121412
kwonly_sig = (msg % ("s" if given != 1 else "", kwonly_given,
14131413
"s" if kwonly_given != 1 else ""))
14141414
raise TypeError("%s() takes %s positional argument%s but %d%s %s given" %
@@ -3107,7 +3107,7 @@ def _bind(self, args, kwargs, *, partial=False):
31073107
elif param.name in kwargs:
31083108
if param.kind == _POSITIONAL_ONLY:
31093109
if param.default is _empty:
3110-
msg = f'missing a required positional-only argument: {param.name!r}'
3110+
msg = f'missing a required positional argument: {param.name!r}'
31113111
raise TypeError(msg)
31123112
# Raise a TypeError once we are sure there is no
31133113
# **kwargs param later.
@@ -3130,7 +3130,7 @@ def _bind(self, args, kwargs, *, partial=False):
31303130
break
31313131
else:
31323132
if param.kind == _KEYWORD_ONLY:
3133-
argtype = ' keyword-only'
3133+
argtype = ' keyword'
31343134
else:
31353135
argtype = ''
31363136
msg = 'missing a required{argtype} argument: {arg!r}'

Lib/test/test_extcall.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@
401401
>>> s3(**md)
402402
Traceback (most recent call last):
403403
...
404-
TypeError: s3() missing 1 required keyword-only argument: 'n'
404+
TypeError: s3() missing 1 required keyword argument: 'n'
405405
406406
Another helper function
407407
@@ -487,17 +487,17 @@
487487
>>> f(1, kw=3)
488488
Traceback (most recent call last):
489489
...
490-
TypeError: f() takes 0 positional arguments but 1 positional argument (and 1 keyword-only argument) were given
490+
TypeError: f() takes 0 positional arguments but 1 positional argument (and 1 keyword argument) were given
491491
>>> def f(*, kw, b): pass
492492
>>> f(1, 2, 3, b=3, kw=3)
493493
Traceback (most recent call last):
494494
...
495-
TypeError: f() takes 0 positional arguments but 3 positional arguments (and 2 keyword-only arguments) were given
495+
TypeError: f() takes 0 positional arguments but 3 positional arguments (and 2 keyword arguments) were given
496496
>>> def f(a, b=2, *, kw): pass
497497
>>> f(2, 3, 4, kw=4)
498498
Traceback (most recent call last):
499499
...
500-
TypeError: f() takes from 1 to 2 positional arguments but 3 positional arguments (and 1 keyword-only argument) were given
500+
TypeError: f() takes from 1 to 2 positional arguments but 3 positional arguments (and 1 keyword argument) were given
501501
502502
Too few and missing arguments:
503503
@@ -533,12 +533,12 @@
533533
>>> f()
534534
Traceback (most recent call last):
535535
...
536-
TypeError: f() missing 1 required keyword-only argument: 'w'
536+
TypeError: f() missing 1 required keyword argument: 'w'
537537
>>> def f(*, a, b, c, d, e): pass
538538
>>> f()
539539
Traceback (most recent call last):
540540
...
541-
TypeError: f() missing 5 required keyword-only arguments: 'a', 'b', 'c', 'd', and 'e'
541+
TypeError: f() missing 5 required keyword arguments: 'a', 'b', 'c', 'd', and 'e'
542542
543543
"""
544544

Lib/test/test_inspect/test_inspect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,7 @@ def test_errors(self):
22432243
# kwonlydefaults and raises a wrong TypeError
22442244
def f5(*, a): pass
22452245
with self.assertRaisesRegex(TypeError,
2246-
'missing 1 required keyword-only'):
2246+
'missing 1 required keyword argument'):
22472247
inspect.getcallargs(f5)
22482248

22492249

@@ -5405,7 +5405,7 @@ def test(foo, *, bar):
54055405
self.call(test, 1, bar=2, spam='ham')
54065406

54075407
with self.assertRaisesRegex(TypeError,
5408-
"missing a required keyword-only "
5408+
"missing a required keyword "
54095409
"argument: 'bar'"):
54105410
self.call(test, 1)
54115411

@@ -5462,7 +5462,7 @@ def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs):
54625462
self.assertEqual(self.call(test, 1, 2, c_po=4),
54635463
(1, 2, 3, 42, 50, {'c_po': 4}))
54645464

5465-
with self.assertRaisesRegex(TypeError, "missing a required positional-only argument: 'a_po'"):
5465+
with self.assertRaisesRegex(TypeError, "missing a required positional argument: 'a_po'"):
54665466
self.call(test, a_po=1, b_po=2)
54675467

54685468
def without_var_kwargs(c_po=3, d_po=4, /):

Lib/test/test_positional_only_arg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ def test_positional_only_and_kwonlyargs_invalid_calls(self):
166166
def f(a, b, /, c, *, d, e):
167167
pass
168168
f(1, 2, 3, d=1, e=2) # does not raise
169-
with self.assertRaisesRegex(TypeError, r"missing 1 required keyword-only argument: 'd'"):
169+
with self.assertRaisesRegex(TypeError, r"missing 1 required keyword argument: 'd'"):
170170
f(1, 2, 3, e=2)
171-
with self.assertRaisesRegex(TypeError, r"missing 2 required keyword-only arguments: 'd' and 'e'"):
171+
with self.assertRaisesRegex(TypeError, r"missing 2 required keyword arguments: 'd' and 'e'"):
172172
f(1, 2, 3)
173173
with self.assertRaisesRegex(TypeError, r"f\(\) missing 1 required positional argument: 'c'"):
174174
f(1, 2)
@@ -177,7 +177,7 @@ def f(a, b, /, c, *, d, e):
177177
with self.assertRaisesRegex(TypeError, r" missing 3 required positional arguments: 'a', 'b', and 'c'"):
178178
f()
179179
with self.assertRaisesRegex(TypeError, r"f\(\) takes 3 positional arguments but 6 positional arguments "
180-
r"\(and 2 keyword-only arguments\) were given"):
180+
r"\(and 2 keyword arguments\) were given"):
181181
f(1, 2, 3, 4, 5, 6, d=7, e=8)
182182
with self.assertRaisesRegex(TypeError, r"f\(\) got an unexpected keyword argument 'f'"):
183183
f(1, 2, 3, d=1, e=4, f=56)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the use of the terms "argument" and "parameter" in error messages for
2+
invalid function calls.

Python/ceval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ missing_arguments(PyThreadState *tstate, PyCodeObject *co,
13181318
Py_ssize_t i, j = 0;
13191319
Py_ssize_t start, end;
13201320
int positional = (defcount != -1);
1321-
const char *kind = positional ? "positional" : "keyword-only";
1321+
const char *kind = positional ? "positional" : "keyword";
13221322
PyObject *missing_names;
13231323

13241324
/* Compute the names of the arguments that are missing. */
@@ -1380,7 +1380,7 @@ too_many_positional(PyThreadState *tstate, PyCodeObject *co,
13801380
if (sig == NULL)
13811381
return;
13821382
if (kwonly_given) {
1383-
const char *format = " positional argument%s (and %zd keyword-only argument%s)";
1383+
const char *format = " positional argument%s (and %zd keyword argument%s)";
13841384
kwonly_sig = PyUnicode_FromFormat(format,
13851385
given != 1 ? "s" : "",
13861386
kwonly_given,

0 commit comments

Comments
 (0)