bpo-30600: Fix error messages (condition order in Argument Clinic) (#2051)
The function '_PyArg_ParseStack()' and
'_PyArg_UnpackStack' were failing (with error
"XXX() takes Y argument (Z given)") before
the function '_PyArg_NoStackKeywords()' was called.
Thus, the latter did not raise its more meaningful
error : "XXX() takes no keyword arguments".
diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h
index c73b560..da17cf8 100644
--- a/Objects/clinic/bytesobject.c.h
+++ b/Objects/clinic/bytesobject.c.h
@@ -195,13 +195,13 @@
PyObject *return_value = NULL;
PyObject *bytes = Py_None;
- if (!_PyArg_UnpackStack(args, nargs, "strip",
- 0, 1,
- &bytes)) {
+ if (!_PyArg_NoStackKeywords("strip", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("strip", kwnames)) {
+ if (!_PyArg_UnpackStack(args, nargs, "strip",
+ 0, 1,
+ &bytes)) {
goto exit;
}
return_value = bytes_strip_impl(self, bytes);
@@ -230,13 +230,13 @@
PyObject *return_value = NULL;
PyObject *bytes = Py_None;
- if (!_PyArg_UnpackStack(args, nargs, "lstrip",
- 0, 1,
- &bytes)) {
+ if (!_PyArg_NoStackKeywords("lstrip", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("lstrip", kwnames)) {
+ if (!_PyArg_UnpackStack(args, nargs, "lstrip",
+ 0, 1,
+ &bytes)) {
goto exit;
}
return_value = bytes_lstrip_impl(self, bytes);
@@ -265,13 +265,13 @@
PyObject *return_value = NULL;
PyObject *bytes = Py_None;
- if (!_PyArg_UnpackStack(args, nargs, "rstrip",
- 0, 1,
- &bytes)) {
+ if (!_PyArg_NoStackKeywords("rstrip", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("rstrip", kwnames)) {
+ if (!_PyArg_UnpackStack(args, nargs, "rstrip",
+ 0, 1,
+ &bytes)) {
goto exit;
}
return_value = bytes_rstrip_impl(self, bytes);
@@ -342,12 +342,12 @@
Py_buffer frm = {NULL, NULL};
Py_buffer to = {NULL, NULL};
- if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans",
- &frm, &to)) {
+ if (!_PyArg_NoStackKeywords("maketrans", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("maketrans", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans",
+ &frm, &to)) {
goto exit;
}
return_value = bytes_maketrans_impl(&frm, &to);
@@ -393,12 +393,12 @@
Py_buffer new = {NULL, NULL};
Py_ssize_t count = -1;
- if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace",
- &old, &new, &count)) {
+ if (!_PyArg_NoStackKeywords("replace", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("replace", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace",
+ &old, &new, &count)) {
goto exit;
}
return_value = bytes_replace_impl(self, &old, &new, count);
@@ -519,4 +519,4 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=2504c1225108d348 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a82999760469bbec input=a9049054013a1b77]*/