We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c75c1e0 commit 1426daaCopy full SHA for 1426daa
3 files changed
Lib/test/test_call.py
@@ -143,6 +143,22 @@ def test_varargs3(self):
143
msg = r"^from_bytes\(\) takes at most 2 positional arguments \(3 given\)"
144
self.assertRaisesRegex(TypeError, msg, int.from_bytes, b'a', 'little', False)
145
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
162
def test_varargs1_kw(self):
163
msg = r"__contains__\(\) takes no keyword arguments"
164
self.assertRaisesRegex(TypeError, msg, {}.__contains__, x=2)
Misc/NEWS.d/next/C API/2018-07-22-14-58-06.bpo-34127.qkfnHO.rst
@@ -0,0 +1,2 @@
1
+Return grammatically correct error message based on argument count.
2
+Patch by Karthikeyan Singaravelan.
Python/getargs.c
@@ -2411,8 +2411,8 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
2411
if (name != NULL)
2412
PyErr_Format(
2413
PyExc_TypeError,
2414
- "%.200s expected %s%zd arguments, got %zd",
2415
- name, (min == max ? "" : "at least "), min, nargs);
+ "%.200s expected %s%zd argument%s, got %zd",
+ name, (min == max ? "" : "at least "), min, min == 1 ? "" : "s", nargs);
2416
else
2417
2418
@@ -2430,8 +2430,8 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
2430
2431
2432
2433
2434
- name, (min == max ? "" : "at most "), max, nargs);
+ name, (min == max ? "" : "at most "), max, max == 1 ? "" : "s", nargs);
2435
2436
2437
0 commit comments