[Python-checkins] bpo-34127: Fix grammar in error message with respect to argument count (GH-8395)
Raymond Hettinger
webhook-mailer at python.org
Sun Jul 22 16:13:29 EDT 2018
https://github.com/python/cpython/commit/1426daa4fe47d8f8be0d416f7cba7adae1d5839f
commit: 1426daa4fe47d8f8be0d416f7cba7adae1d5839f
branch: master
author: Xtreak <tirkarthi at users.noreply.github.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2018年07月22日T13:13:26-07:00
summary:
bpo-34127: Fix grammar in error message with respect to argument count (GH-8395)
files:
A Misc/NEWS.d/next/C API/2018-07-22-14-58-06.bpo-34127.qkfnHO.rst
M Lib/test/test_call.py
M Python/getargs.c
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py
index 3f9987c9e777..ec9697a444f0 100644
--- a/Lib/test/test_call.py
+++ b/Lib/test/test_call.py
@@ -143,6 +143,22 @@ def test_varargs3(self):
msg = r"^from_bytes\(\) takes at most 2 positional arguments \(3 given\)"
self.assertRaisesRegex(TypeError, msg, int.from_bytes, b'a', 'little', False)
+ def test_varargs4(self):
+ msg = r"get expected at least 1 argument, got 0"
+ self.assertRaisesRegex(TypeError, msg, {}.get)
+
+ def test_varargs5(self):
+ msg = r"getattr expected at least 2 arguments, got 0"
+ self.assertRaisesRegex(TypeError, msg, getattr)
+
+ def test_varargs6(self):
+ msg = r"input expected at most 1 argument, got 2"
+ self.assertRaisesRegex(TypeError, msg, input, 1, 2)
+
+ def test_varargs7(self):
+ msg = r"get expected at most 2 arguments, got 3"
+ self.assertRaisesRegex(TypeError, msg, {}.get, 1, 2, 3)
+
def test_varargs1_kw(self):
msg = r"__contains__\(\) takes no keyword arguments"
self.assertRaisesRegex(TypeError, msg, {}.__contains__, x=2)
diff --git a/Misc/NEWS.d/next/C API/2018-07-22-14-58-06.bpo-34127.qkfnHO.rst b/Misc/NEWS.d/next/C API/2018-07-22-14-58-06.bpo-34127.qkfnHO.rst
new file mode 100644
index 000000000000..c5b8c0746816
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2018-07-22-14-58-06.bpo-34127.qkfnHO.rst
@@ -0,0 +1,2 @@
+Return grammatically correct error message based on argument count.
+Patch by Karthikeyan Singaravelan.
diff --git a/Python/getargs.c b/Python/getargs.c
index 992cb216c257..98823f22ed4e 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -2411,8 +2411,8 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
if (name != NULL)
PyErr_Format(
PyExc_TypeError,
- "%.200s expected %s%zd arguments, got %zd",
- 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);
else
PyErr_Format(
PyExc_TypeError,
@@ -2430,8 +2430,8 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
if (name != NULL)
PyErr_Format(
PyExc_TypeError,
- "%.200s expected %s%zd arguments, got %zd",
- name, (min == max ? "" : "at most "), max, nargs);
+ "%.200s expected %s%zd argument%s, got %zd",
+ name, (min == max ? "" : "at most "), max, max == 1 ? "" : "s", nargs);
else
PyErr_Format(
PyExc_TypeError,
More information about the Python-checkins
mailing list