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/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h
index a9089ca..20e7f2a 100644
--- a/Modules/clinic/zlibmodule.c.h
+++ b/Modules/clinic/zlibmodule.c.h
@@ -301,12 +301,12 @@
PyObject *return_value = NULL;
int mode = Z_FINISH;
- if (!_PyArg_ParseStack(args, nargs, "|i:flush",
- &mode)) {
+ if (!_PyArg_NoStackKeywords("flush", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("flush", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "|i:flush",
+ &mode)) {
goto exit;
}
return_value = zlib_Compress_flush_impl(self, mode);
@@ -380,12 +380,12 @@
PyObject *return_value = NULL;
Py_ssize_t length = DEF_BUF_SIZE;
- if (!_PyArg_ParseStack(args, nargs, "|O&:flush",
- ssize_t_converter, &length)) {
+ if (!_PyArg_NoStackKeywords("flush", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("flush", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "|O&:flush",
+ ssize_t_converter, &length)) {
goto exit;
}
return_value = zlib_Decompress_flush_impl(self, length);
@@ -418,12 +418,12 @@
Py_buffer data = {NULL, NULL};
unsigned int value = 1;
- if (!_PyArg_ParseStack(args, nargs, "y*|I:adler32",
- &data, &value)) {
+ if (!_PyArg_NoStackKeywords("adler32", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("adler32", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "y*|I:adler32",
+ &data, &value)) {
goto exit;
}
return_value = zlib_adler32_impl(module, &data, value);
@@ -461,12 +461,12 @@
Py_buffer data = {NULL, NULL};
unsigned int value = 0;
- if (!_PyArg_ParseStack(args, nargs, "y*|I:crc32",
- &data, &value)) {
+ if (!_PyArg_NoStackKeywords("crc32", kwnames)) {
goto exit;
}
- if (!_PyArg_NoStackKeywords("crc32", kwnames)) {
+ if (!_PyArg_ParseStack(args, nargs, "y*|I:crc32",
+ &data, &value)) {
goto exit;
}
return_value = zlib_crc32_impl(module, &data, value);
@@ -483,4 +483,4 @@
#ifndef ZLIB_COMPRESS_COPY_METHODDEF
#define ZLIB_COMPRESS_COPY_METHODDEF
#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
-/*[clinic end generated code: output=fa1b5f4a6208c342 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c7abf02e091bcad3 input=a9049054013a1b77]*/