]> granicus.if.org Git - python/commitdiff
Fix regression in error message introduced in bpo-29951. (#2028)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 9 Jun 2017 16:27:06 +0000 (19:27 +0300)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 9 Jun 2017 16:27:06 +0000 (18:27 +0200)
* Fix regression in error message introduced in bpo-29951.

* Add test.

* Make the test more strong.

Lib/test/test_call.py
Python/getargs.c

index d929cfc0887ba8dc3c71d6d4af97074aef5cab4b..1e84b525f70c1223181414b4beb6a14fef0b5256 100644 (file)
@@ -136,6 +136,10 @@ class CFunctionCallsErrorMessages(unittest.TestCase):
         msg = r"__contains__\(\) takes exactly one argument \(2 given\)"
         self.assertRaisesRegex(TypeError, msg, {}.__contains__, 0, 1)
 
+    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_varargs1_kw(self):
         msg = r"__contains__\(\) takes no keyword arguments"
         self.assertRaisesRegex(TypeError, msg, {}.__contains__, x=2)
index af1f2a2a24d47410257a15128685d1b5bfc2b4c2..f555870f7e0a79683840f9ad9db011806a372939 100644 (file)
@@ -2089,13 +2089,13 @@ vgetargskeywordsfast_impl(PyObject **args, Py_ssize_t nargs,
     if (parser->max < nargs) {
         if (parser->max == 0) {
             PyErr_Format(PyExc_TypeError,
-                         "%200s%s takes no positional arguments",
+                         "%.200s%s takes no positional arguments",
                          (parser->fname == NULL) ? "function" : parser->fname,
                          (parser->fname == NULL) ? "" : "()");
         }
         else {
             PyErr_Format(PyExc_TypeError,
-                         "%200s%s takes %s %d positional arguments (%d given)",
+                         "%.200s%s takes %s %d positional arguments (%d given)",
                          (parser->fname == NULL) ? "function" : parser->fname,
                          (parser->fname == NULL) ? "" : "()",
                          (parser->min != INT_MAX) ? "at most" : "exactly",