Skip to content

Commit f9f1cca

Browse files
serhiy-storchakavstinner
authored andcommitted
Fix regression in error message introduced in bpo-29951. (python#2028)
* Fix regression in error message introduced in bpo-29951. * Add test. * Make the test more strong.
1 parent 57161aa commit f9f1cca

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/test/test_call.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def test_varargs2(self):
136136
msg = r"__contains__\(\) takes exactly one argument \(2 given\)"
137137
self.assertRaisesRegex(TypeError, msg, {}.__contains__, 0, 1)
138138

139+
def test_varargs3(self):
140+
msg = r"^from_bytes\(\) takes at most 2 positional arguments \(3 given\)"
141+
self.assertRaisesRegex(TypeError, msg, int.from_bytes, b'a', 'little', False)
142+
139143
def test_varargs1_kw(self):
140144
msg = r"__contains__\(\) takes no keyword arguments"
141145
self.assertRaisesRegex(TypeError, msg, {}.__contains__, x=2)

Python/getargs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,13 +2089,13 @@ vgetargskeywordsfast_impl(PyObject **args, Py_ssize_t nargs,
20892089
if (parser->max < nargs) {
20902090
if (parser->max == 0) {
20912091
PyErr_Format(PyExc_TypeError,
2092-
"%200s%s takes no positional arguments",
2092+
"%.200s%s takes no positional arguments",
20932093
(parser->fname == NULL) ? "function" : parser->fname,
20942094
(parser->fname == NULL) ? "" : "()");
20952095
}
20962096
else {
20972097
PyErr_Format(PyExc_TypeError,
2098-
"%200s%s takes %s %d positional arguments (%d given)",
2098+
"%.200s%s takes %s %d positional arguments (%d given)",
20992099
(parser->fname == NULL) ? "function" : parser->fname,
21002100
(parser->fname == NULL) ? "" : "()",
21012101
(parser->min != INT_MAX) ? "at most" : "exactly",

0 commit comments

Comments
 (0)