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/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h
index 2a67674..6ffd4ff 100644
--- a/Modules/clinic/arraymodule.c.h
+++ b/Modules/clinic/arraymodule.c.h
@@ -76,12 +76,12 @@
PyObject *return_value = NULL;
Py_ssize_t i = -1;
- if (!_PyArg_ParseStack(args, nargs, "|n:pop",
- &i)) {
+ if (!_PyArg_NoStackKeywords("pop", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("pop", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "|n:pop",
+ &i)) {
goto exit;
}
return_value = array_array_pop_impl(self, i);
@@ -118,12 +118,12 @@
Py_ssize_t i;
PyObject *v;
- if (!_PyArg_ParseStack(args, nargs, "nO:insert",
- &i, &v)) {
+ if (!_PyArg_NoStackKeywords("insert", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("insert", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "nO:insert",
+ &i, &v)) {
goto exit;
}
return_value = array_array_insert_impl(self, i, v);
@@ -220,12 +220,12 @@
PyObject *f;
Py_ssize_t n;
- if (!_PyArg_ParseStack(args, nargs, "On:fromfile",
- &f, &n)) {
+ if (!_PyArg_NoStackKeywords("fromfile", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("fromfile", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "On:fromfile",
+ &f, &n)) {
goto exit;
}
return_value = array_array_fromfile_impl(self, f, n);
@@ -472,12 +472,12 @@
enum machine_format_code mformat_code;
PyObject *items;
- if (!_PyArg_ParseStack(args, nargs, "OCiO:_array_reconstructor",
- &arraytype, &typecode, &mformat_code, &items)) {
+ if (!_PyArg_NoStackKeywords("_array_reconstructor", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("_array_reconstructor", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "OCiO:_array_reconstructor",
+ &arraytype, &typecode, &mformat_code, &items)) {
goto exit;
}
return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items);
@@ -521,4 +521,4 @@
#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
{"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
-/*[clinic end generated code: output=d186a7553c1f1a41 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=fb4a67e697d7c0b0 input=a9049054013a1b77]*/