Skip to content

Commit 1426daa

Browse files
tirkarthirhettinger
authored andcommitted
bpo-34127: Fix grammar in error message with respect to argument count (GH-8395)
1 parent c75c1e0 commit 1426daa

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Lib/test/test_call.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ def test_varargs3(self):
143143
msg = r"^from_bytes\(\) takes at most 2 positional arguments \(3 given\)"
144144
self.assertRaisesRegex(TypeError, msg, int.from_bytes, b'a', 'little', False)
145145

146+
def test_varargs4(self):
147+
msg = r"get expected at least 1 argument, got 0"
148+
self.assertRaisesRegex(TypeError, msg, {}.get)
149+
150+
def test_varargs5(self):
151+
msg = r"getattr expected at least 2 arguments, got 0"
152+
self.assertRaisesRegex(TypeError, msg, getattr)
153+
154+
def test_varargs6(self):
155+
msg = r"input expected at most 1 argument, got 2"
156+
self.assertRaisesRegex(TypeError, msg, input, 1, 2)
157+
158+
def test_varargs7(self):
159+
msg = r"get expected at most 2 arguments, got 3"
160+
self.assertRaisesRegex(TypeError, msg, {}.get, 1, 2, 3)
161+
146162
def test_varargs1_kw(self):
147163
msg = r"__contains__\(\) takes no keyword arguments"
148164
self.assertRaisesRegex(TypeError, msg, {}.__contains__, x=2)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Return grammatically correct error message based on argument count.
2+
Patch by Karthikeyan Singaravelan.

Python/getargs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,8 +2411,8 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
24112411
if (name != NULL)
24122412
PyErr_Format(
24132413
PyExc_TypeError,
2414-
"%.200s expected %s%zd arguments, got %zd",
2415-
name, (min == max ? "" : "at least "), min, nargs);
2414+
"%.200s expected %s%zd argument%s, got %zd",
2415+
name, (min == max ? "" : "at least "), min, min == 1 ? "" : "s", nargs);
24162416
else
24172417
PyErr_Format(
24182418
PyExc_TypeError,
@@ -2430,8 +2430,8 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
24302430
if (name != NULL)
24312431
PyErr_Format(
24322432
PyExc_TypeError,
2433-
"%.200s expected %s%zd arguments, got %zd",
2434-
name, (min == max ? "" : "at most "), max, nargs);
2433+
"%.200s expected %s%zd argument%s, got %zd",
2434+
name, (min == max ? "" : "at most "), max, max == 1 ? "" : "s", nargs);
24352435
else
24362436
PyErr_Format(
24372437
PyExc_TypeError,

0 commit comments

Comments
 (0)