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/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h
index d93a45d..0e46f94 100644
--- a/Python/clinic/bltinmodule.c.h
+++ b/Python/clinic/bltinmodule.c.h
@@ -94,12 +94,12 @@
     PyObject *value;
     PyObject *format_spec = NULL;
 
-    if (!_PyArg_ParseStack(args, nargs, "O|U:format",
-        &value, &format_spec)) {
+    if (!_PyArg_NoStackKeywords("format", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("format", kwnames)) {
+    if (!_PyArg_ParseStack(args, nargs, "O|U:format",
+        &value, &format_spec)) {
         goto exit;
     }
     return_value = builtin_format_impl(module, value, format_spec);
@@ -203,13 +203,13 @@
     PyObject *x;
     PyObject *y;
 
-    if (!_PyArg_UnpackStack(args, nargs, "divmod",
-        2, 2,
-        &x, &y)) {
+    if (!_PyArg_NoStackKeywords("divmod", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("divmod", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "divmod",
+        2, 2,
+        &x, &y)) {
         goto exit;
     }
     return_value = builtin_divmod_impl(module, x, y);
@@ -245,13 +245,13 @@
     PyObject *globals = Py_None;
     PyObject *locals = Py_None;
 
-    if (!_PyArg_UnpackStack(args, nargs, "eval",
-        1, 3,
-        &source, &globals, &locals)) {
+    if (!_PyArg_NoStackKeywords("eval", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("eval", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "eval",
+        1, 3,
+        &source, &globals, &locals)) {
         goto exit;
     }
     return_value = builtin_eval_impl(module, source, globals, locals);
@@ -287,13 +287,13 @@
     PyObject *globals = Py_None;
     PyObject *locals = Py_None;
 
-    if (!_PyArg_UnpackStack(args, nargs, "exec",
-        1, 3,
-        &source, &globals, &locals)) {
+    if (!_PyArg_NoStackKeywords("exec", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("exec", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "exec",
+        1, 3,
+        &source, &globals, &locals)) {
         goto exit;
     }
     return_value = builtin_exec_impl(module, source, globals, locals);
@@ -344,13 +344,13 @@
     PyObject *obj;
     PyObject *name;
 
-    if (!_PyArg_UnpackStack(args, nargs, "hasattr",
-        2, 2,
-        &obj, &name)) {
+    if (!_PyArg_NoStackKeywords("hasattr", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("hasattr", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "hasattr",
+        2, 2,
+        &obj, &name)) {
         goto exit;
     }
     return_value = builtin_hasattr_impl(module, obj, name);
@@ -394,13 +394,13 @@
     PyObject *name;
     PyObject *value;
 
-    if (!_PyArg_UnpackStack(args, nargs, "setattr",
-        3, 3,
-        &obj, &name, &value)) {
+    if (!_PyArg_NoStackKeywords("setattr", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("setattr", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "setattr",
+        3, 3,
+        &obj, &name, &value)) {
         goto exit;
     }
     return_value = builtin_setattr_impl(module, obj, name, value);
@@ -430,13 +430,13 @@
     PyObject *obj;
     PyObject *name;
 
-    if (!_PyArg_UnpackStack(args, nargs, "delattr",
-        2, 2,
-        &obj, &name)) {
+    if (!_PyArg_NoStackKeywords("delattr", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("delattr", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "delattr",
+        2, 2,
+        &obj, &name)) {
         goto exit;
     }
     return_value = builtin_delattr_impl(module, obj, name);
@@ -544,13 +544,13 @@
     PyObject *y;
     PyObject *z = Py_None;
 
-    if (!_PyArg_UnpackStack(args, nargs, "pow",
-        2, 3,
-        &x, &y, &z)) {
+    if (!_PyArg_NoStackKeywords("pow", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("pow", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "pow",
+        2, 3,
+        &x, &y, &z)) {
         goto exit;
     }
     return_value = builtin_pow_impl(module, x, y, z);
@@ -583,13 +583,13 @@
     PyObject *return_value = NULL;
     PyObject *prompt = NULL;
 
-    if (!_PyArg_UnpackStack(args, nargs, "input",
-        0, 1,
-        &prompt)) {
+    if (!_PyArg_NoStackKeywords("input", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("input", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "input",
+        0, 1,
+        &prompt)) {
         goto exit;
     }
     return_value = builtin_input_impl(module, prompt);
@@ -632,13 +632,13 @@
     PyObject *iterable;
     PyObject *start = NULL;
 
-    if (!_PyArg_UnpackStack(args, nargs, "sum",
-        1, 2,
-        &iterable, &start)) {
+    if (!_PyArg_NoStackKeywords("sum", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("sum", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "sum",
+        1, 2,
+        &iterable, &start)) {
         goto exit;
     }
     return_value = builtin_sum_impl(module, iterable, start);
@@ -671,13 +671,13 @@
     PyObject *obj;
     PyObject *class_or_tuple;
 
-    if (!_PyArg_UnpackStack(args, nargs, "isinstance",
-        2, 2,
-        &obj, &class_or_tuple)) {
+    if (!_PyArg_NoStackKeywords("isinstance", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("isinstance", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "isinstance",
+        2, 2,
+        &obj, &class_or_tuple)) {
         goto exit;
     }
     return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
@@ -710,13 +710,13 @@
     PyObject *cls;
     PyObject *class_or_tuple;
 
-    if (!_PyArg_UnpackStack(args, nargs, "issubclass",
-        2, 2,
-        &cls, &class_or_tuple)) {
+    if (!_PyArg_NoStackKeywords("issubclass", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("issubclass", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "issubclass",
+        2, 2,
+        &cls, &class_or_tuple)) {
         goto exit;
     }
     return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
@@ -724,4 +724,4 @@
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=17fedd2dec148677 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e1a7417a7b33eeec input=a9049054013a1b77]*/
diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h
index 0165b7c..5f4bad2 100644
--- a/Python/clinic/import.c.h
+++ b/Python/clinic/import.c.h
@@ -88,12 +88,12 @@
     PyCodeObject *code;
     PyObject *path;
 
-    if (!_PyArg_ParseStack(args, nargs, "O!U:_fix_co_filename",
-        &PyCode_Type, &code, &path)) {
+    if (!_PyArg_NoStackKeywords("_fix_co_filename", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("_fix_co_filename", kwnames)) {
+    if (!_PyArg_ParseStack(args, nargs, "O!U:_fix_co_filename",
+        &PyCode_Type, &code, &path)) {
         goto exit;
     }
     return_value = _imp__fix_co_filename_impl(module, code, path);
@@ -285,13 +285,13 @@
     PyObject *spec;
     PyObject *file = NULL;
 
-    if (!_PyArg_UnpackStack(args, nargs, "create_dynamic",
-        1, 2,
-        &spec, &file)) {
+    if (!_PyArg_NoStackKeywords("create_dynamic", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("create_dynamic", kwnames)) {
+    if (!_PyArg_UnpackStack(args, nargs, "create_dynamic",
+        1, 2,
+        &spec, &file)) {
         goto exit;
     }
     return_value = _imp_create_dynamic_impl(module, spec, file);
@@ -369,4 +369,4 @@
 #ifndef _IMP_EXEC_DYNAMIC_METHODDEF
     #define _IMP_EXEC_DYNAMIC_METHODDEF
 #endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
-/*[clinic end generated code: output=c1d0e65d04114958 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b970357dbbe25ee4 input=a9049054013a1b77]*/
diff --git a/Python/clinic/marshal.c.h b/Python/clinic/marshal.c.h
index ae2c899..64504ba 100644
--- a/Python/clinic/marshal.c.h
+++ b/Python/clinic/marshal.c.h
@@ -34,12 +34,12 @@
     PyObject *file;
     int version = Py_MARSHAL_VERSION;
 
-    if (!_PyArg_ParseStack(args, nargs, "OO|i:dump",
-        &value, &file, &version)) {
+    if (!_PyArg_NoStackKeywords("dump", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("dump", kwnames)) {
+    if (!_PyArg_ParseStack(args, nargs, "OO|i:dump",
+        &value, &file, &version)) {
         goto exit;
     }
     return_value = marshal_dump_impl(module, value, file, version);
@@ -94,12 +94,12 @@
     PyObject *value;
     int version = Py_MARSHAL_VERSION;
 
-    if (!_PyArg_ParseStack(args, nargs, "O|i:dumps",
-        &value, &version)) {
+    if (!_PyArg_NoStackKeywords("dumps", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_NoStackKeywords("dumps", kwnames)) {
+    if (!_PyArg_ParseStack(args, nargs, "O|i:dumps",
+        &value, &version)) {
         goto exit;
     }
     return_value = marshal_dumps_impl(module, value, version);
@@ -142,4 +142,4 @@
 
     return return_value;
 }
-/*[clinic end generated code: output=9dec2158b8c5d975 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7b147a648614af7e input=a9049054013a1b77]*/