From 8f42028b513eb2ef28f6844dbf38c51d8827bae2 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 20 Apr 2022 14:26:19 +0300 Subject: [PATCH 1/4] gh-91583: AC: Fix regression for functions with defining_class Argument Clinic now generates the same efficient code as before adding the defining_class parameter. --- ...2-04-20-14-26-14.gh-issue-91583.200qI0.rst | 2 + Modules/_sqlite/clinic/connection.c.h | 135 +++++++-- Modules/_sre/clinic/sre.c.h | 278 ++++++++++++++++-- Modules/cjkcodecs/clinic/multibytecodec.c.h | 25 +- Modules/clinic/_curses_panel.c.h | 72 +++-- Modules/clinic/_dbmmodule.c.h | 9 +- Modules/clinic/_gdbmmodule.c.h | 30 +- Modules/clinic/_lsprof.c.h | 9 +- Modules/clinic/_queuemodule.c.h | 31 +- Modules/clinic/_testmultiphase.c.h | 52 +++- Modules/clinic/arraymodule.c.h | 53 +++- Modules/clinic/md5module.c.h | 9 +- Modules/clinic/posixmodule.c.h | 57 +++- Modules/clinic/pyexpat.c.h | 83 +++++- Modules/clinic/sha1module.c.h | 9 +- Modules/clinic/sha256module.c.h | 9 +- Modules/clinic/sha512module.c.h | 9 +- Modules/clinic/zlibmodule.c.h | 129 ++++++-- Tools/clinic/clinic.py | 12 +- 19 files changed, 793 insertions(+), 220 deletions(-) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2022-04-20-14-26-14.gh-issue-91583.200qI0.rst diff --git a/Misc/NEWS.d/next/Tools-Demos/2022-04-20-14-26-14.gh-issue-91583.200qI0.rst b/Misc/NEWS.d/next/Tools-Demos/2022-04-20-14-26-14.gh-issue-91583.200qI0.rst new file mode 100644 index 00000000000000..bdfa71100f95ae --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2022-04-20-14-26-14.gh-issue-91583.200qI0.rst @@ -0,0 +1,2 @@ +Fix regression in the code generated by Argument Clinic for functions with +the ``defining_class`` parameter. diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h index d4597086f4c9a4..b012c4d4bbfa35 100644 --- a/Modules/_sqlite/clinic/connection.c.h +++ b/Modules/_sqlite/clinic/connection.c.h @@ -323,16 +323,44 @@ pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls { PyObject *return_value = NULL; static const char * const _keywords[] = {"name", "narg", "func", "deterministic", NULL}; - static _PyArg_Parser _parser = {"siO|$p:create_function", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "create_function", 0}; + PyObject *argsbuf[4]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; const char *name; int narg; PyObject *func; int deterministic = 0; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &name, &narg, &func, &deterministic)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); + if (!args) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]); + goto exit; + } + Py_ssize_t name_length; + name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + if (name == NULL) { + goto exit; + } + if (strlen(name) != (size_t)name_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + narg = _PyLong_AsInt(args[1]); + if (narg == -1 && PyErr_Occurred()) { + goto exit; + } + func = args[2]; + if (!noptargs) { + goto skip_optional_kwonly; + } + deterministic = PyObject_IsTrue(args[3]); + if (deterministic < 0) { goto exit; } +skip_optional_kwonly: return_value = pysqlite_connection_create_function_impl(self, cls, name, narg, func, deterministic); exit: @@ -369,15 +397,34 @@ create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *c { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "", "", NULL}; - static _PyArg_Parser _parser = {"siO:create_window_function", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "create_window_function", 0}; + PyObject *argsbuf[3]; const char *name; int num_params; PyObject *aggregate_class; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &name, &num_params, &aggregate_class)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); + if (!args) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("create_window_function", "argument 1", "str", args[0]); + goto exit; + } + Py_ssize_t name_length; + name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + if (name == NULL) { + goto exit; + } + if (strlen(name) != (size_t)name_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; } + num_params = _PyLong_AsInt(args[1]); + if (num_params == -1 && PyErr_Occurred()) { + goto exit; + } + aggregate_class = args[2]; return_value = create_window_function_impl(self, cls, name, num_params, aggregate_class); exit: @@ -406,15 +453,34 @@ pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cl { PyObject *return_value = NULL; static const char * const _keywords[] = {"name", "n_arg", "aggregate_class", NULL}; - static _PyArg_Parser _parser = {"siO:create_aggregate", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "create_aggregate", 0}; + PyObject *argsbuf[3]; const char *name; int n_arg; PyObject *aggregate_class; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &name, &n_arg, &aggregate_class)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); + if (!args) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]); + goto exit; + } + Py_ssize_t name_length; + name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + if (name == NULL) { + goto exit; + } + if (strlen(name) != (size_t)name_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + n_arg = _PyLong_AsInt(args[1]); + if (n_arg == -1 && PyErr_Occurred()) { goto exit; } + aggregate_class = args[2]; return_value = pysqlite_connection_create_aggregate_impl(self, cls, name, n_arg, aggregate_class); exit: @@ -440,13 +506,15 @@ pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyTypeObject *cls, { PyObject *return_value = NULL; static const char * const _keywords[] = {"authorizer_callback", NULL}; - static _PyArg_Parser _parser = {"O:set_authorizer", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "set_authorizer", 0}; + PyObject *argsbuf[1]; PyObject *callable; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &callable)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + callable = args[0]; return_value = pysqlite_connection_set_authorizer_impl(self, cls, callable); exit: @@ -472,12 +540,18 @@ pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyTypeObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"progress_handler", "n", NULL}; - static _PyArg_Parser _parser = {"Oi:set_progress_handler", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "set_progress_handler", 0}; + PyObject *argsbuf[2]; PyObject *callable; int n; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &callable, &n)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { + goto exit; + } + callable = args[0]; + n = _PyLong_AsInt(args[1]); + if (n == -1 && PyErr_Occurred()) { goto exit; } return_value = pysqlite_connection_set_progress_handler_impl(self, cls, callable, n); @@ -505,13 +579,15 @@ pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyTypeObject * { PyObject *return_value = NULL; static const char * const _keywords[] = {"trace_callback", NULL}; - static _PyArg_Parser _parser = {"O:set_trace_callback", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "set_trace_callback", 0}; + PyObject *argsbuf[1]; PyObject *callable; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &callable)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + callable = args[0]; return_value = pysqlite_connection_set_trace_callback_impl(self, cls, callable); exit: @@ -830,14 +906,29 @@ pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cl { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "", NULL}; - static _PyArg_Parser _parser = {"sO:create_collation", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "create_collation", 0}; + PyObject *argsbuf[2]; const char *name; PyObject *callable; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &name, &callable)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]); + goto exit; + } + Py_ssize_t name_length; + name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + if (name == NULL) { + goto exit; + } + if (strlen(name) != (size_t)name_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; } + callable = args[1]; return_value = pysqlite_connection_create_collation_impl(self, cls, name, callable); exit: @@ -1145,4 +1236,4 @@ getlimit(pysqlite_Connection *self, PyObject *arg) #ifndef DESERIALIZE_METHODDEF #define DESERIALIZE_METHODDEF #endif /* !defined(DESERIALIZE_METHODDEF) */ -/*[clinic end generated code: output=be2f526e78fa65b1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6c9432a9fe0a4f5e input=a9049054013a1b77]*/ diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h index 34cbe21f14071b..035ace78a95345 100644 --- a/Modules/_sre/clinic/sre.c.h +++ b/Modules/_sre/clinic/sre.c.h @@ -176,15 +176,51 @@ _sre_SRE_Pattern_match(PatternObject *self, PyTypeObject *cls, PyObject *const * { PyObject *return_value = NULL; static const char * const _keywords[] = {"string", "pos", "endpos", NULL}; - static _PyArg_Parser _parser = {"O|nn:match", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "match", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *string; Py_ssize_t pos = 0; Py_ssize_t endpos = PY_SSIZE_T_MAX; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &string, &pos, &endpos)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); + if (!args) { goto exit; } + string = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + if (args[1]) { + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + pos = ival; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + endpos = ival; + } +skip_optional_pos: return_value = _sre_SRE_Pattern_match_impl(self, cls, string, pos, endpos); exit: @@ -210,15 +246,51 @@ _sre_SRE_Pattern_fullmatch(PatternObject *self, PyTypeObject *cls, PyObject *con { PyObject *return_value = NULL; static const char * const _keywords[] = {"string", "pos", "endpos", NULL}; - static _PyArg_Parser _parser = {"O|nn:fullmatch", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "fullmatch", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *string; Py_ssize_t pos = 0; Py_ssize_t endpos = PY_SSIZE_T_MAX; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &string, &pos, &endpos)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); + if (!args) { goto exit; } + string = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + if (args[1]) { + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + pos = ival; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + endpos = ival; + } +skip_optional_pos: return_value = _sre_SRE_Pattern_fullmatch_impl(self, cls, string, pos, endpos); exit: @@ -246,15 +318,51 @@ _sre_SRE_Pattern_search(PatternObject *self, PyTypeObject *cls, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = {"string", "pos", "endpos", NULL}; - static _PyArg_Parser _parser = {"O|nn:search", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "search", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *string; Py_ssize_t pos = 0; Py_ssize_t endpos = PY_SSIZE_T_MAX; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &string, &pos, &endpos)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); + if (!args) { goto exit; } + string = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + if (args[1]) { + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + pos = ival; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + endpos = ival; + } +skip_optional_pos: return_value = _sre_SRE_Pattern_search_impl(self, cls, string, pos, endpos); exit: @@ -351,15 +459,51 @@ _sre_SRE_Pattern_finditer(PatternObject *self, PyTypeObject *cls, PyObject *cons { PyObject *return_value = NULL; static const char * const _keywords[] = {"string", "pos", "endpos", NULL}; - static _PyArg_Parser _parser = {"O|nn:finditer", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "finditer", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *string; Py_ssize_t pos = 0; Py_ssize_t endpos = PY_SSIZE_T_MAX; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &string, &pos, &endpos)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); + if (!args) { goto exit; } + string = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + if (args[1]) { + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + pos = ival; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + endpos = ival; + } +skip_optional_pos: return_value = _sre_SRE_Pattern_finditer_impl(self, cls, string, pos, endpos); exit: @@ -384,15 +528,51 @@ _sre_SRE_Pattern_scanner(PatternObject *self, PyTypeObject *cls, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = {"string", "pos", "endpos", NULL}; - static _PyArg_Parser _parser = {"O|nn:scanner", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "scanner", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *string; Py_ssize_t pos = 0; Py_ssize_t endpos = PY_SSIZE_T_MAX; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &string, &pos, &endpos)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); + if (!args) { goto exit; } + string = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + if (args[1]) { + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + pos = ival; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + endpos = ival; + } +skip_optional_pos: return_value = _sre_SRE_Pattern_scanner_impl(self, cls, string, pos, endpos); exit: @@ -468,15 +648,35 @@ _sre_SRE_Pattern_sub(PatternObject *self, PyTypeObject *cls, PyObject *const *ar { PyObject *return_value = NULL; static const char * const _keywords[] = {"repl", "string", "count", NULL}; - static _PyArg_Parser _parser = {"OO|n:sub", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "sub", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; PyObject *repl; PyObject *string; Py_ssize_t count = 0; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &repl, &string, &count)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); + if (!args) { goto exit; } + repl = args[0]; + string = args[1]; + if (!noptargs) { + goto skip_optional_pos; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + count = ival; + } +skip_optional_pos: return_value = _sre_SRE_Pattern_sub_impl(self, cls, repl, string, count); exit: @@ -502,15 +702,35 @@ _sre_SRE_Pattern_subn(PatternObject *self, PyTypeObject *cls, PyObject *const *a { PyObject *return_value = NULL; static const char * const _keywords[] = {"repl", "string", "count", NULL}; - static _PyArg_Parser _parser = {"OO|n:subn", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "subn", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; PyObject *repl; PyObject *string; Py_ssize_t count = 0; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &repl, &string, &count)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); + if (!args) { goto exit; } + repl = args[0]; + string = args[1]; + if (!noptargs) { + goto skip_optional_pos; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + count = ival; + } +skip_optional_pos: return_value = _sre_SRE_Pattern_subn_impl(self, cls, repl, string, count); exit: @@ -884,10 +1104,11 @@ _sre_SRE_Scanner_match(ScannerObject *self, PyTypeObject *cls, PyObject *const * { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":match", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "match", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _sre_SRE_Scanner_match_impl(self, cls); @@ -912,10 +1133,11 @@ _sre_SRE_Scanner_search(ScannerObject *self, PyTypeObject *cls, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":search", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "search", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _sre_SRE_Scanner_search_impl(self, cls); @@ -923,4 +1145,4 @@ _sre_SRE_Scanner_search(ScannerObject *self, PyTypeObject *cls, PyObject *const exit: return return_value; } -/*[clinic end generated code: output=9d7510a57a157a38 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ec64ab853f79cd46 input=a9049054013a1b77]*/ diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h index 1dfb9a12248275..0d019dafc50289 100644 --- a/Modules/cjkcodecs/clinic/multibytecodec.c.h +++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h @@ -493,13 +493,15 @@ _multibytecodec_MultibyteStreamWriter_write(MultibyteStreamWriterObject *self, P { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O:write", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "write", 0}; + PyObject *argsbuf[1]; PyObject *strobj; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &strobj)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + strobj = args[0]; return_value = _multibytecodec_MultibyteStreamWriter_write_impl(self, cls, strobj); exit: @@ -524,13 +526,15 @@ _multibytecodec_MultibyteStreamWriter_writelines(MultibyteStreamWriterObject *se { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O:writelines", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "writelines", 0}; + PyObject *argsbuf[1]; PyObject *lines; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &lines)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + lines = args[0]; return_value = _multibytecodec_MultibyteStreamWriter_writelines_impl(self, cls, lines); exit: @@ -554,10 +558,11 @@ _multibytecodec_MultibyteStreamWriter_reset(MultibyteStreamWriterObject *self, P { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":reset", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "reset", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _multibytecodec_MultibyteStreamWriter_reset_impl(self, cls); @@ -573,4 +578,4 @@ PyDoc_STRVAR(_multibytecodec___create_codec__doc__, #define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \ {"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__}, -/*[clinic end generated code: output=8813c05077580bda input=a9049054013a1b77]*/ +/*[clinic end generated code: output=55f6a328e1a03914 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_curses_panel.c.h b/Modules/clinic/_curses_panel.c.h index 45898070b1f543..937fdd95be3d28 100644 --- a/Modules/clinic/_curses_panel.c.h +++ b/Modules/clinic/_curses_panel.c.h @@ -19,10 +19,11 @@ _curses_panel_panel_bottom(PyCursesPanelObject *self, PyTypeObject *cls, PyObjec { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":bottom", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "bottom", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _curses_panel_panel_bottom_impl(self, cls); @@ -50,10 +51,11 @@ _curses_panel_panel_hide(PyCursesPanelObject *self, PyTypeObject *cls, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":hide", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "hide", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _curses_panel_panel_hide_impl(self, cls); @@ -79,10 +81,11 @@ _curses_panel_panel_show(PyCursesPanelObject *self, PyTypeObject *cls, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":show", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "show", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _curses_panel_panel_show_impl(self, cls); @@ -108,10 +111,11 @@ _curses_panel_panel_top(PyCursesPanelObject *self, PyTypeObject *cls, PyObject * { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":top", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "top", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _curses_panel_panel_top_impl(self, cls); @@ -192,12 +196,21 @@ _curses_panel_panel_move(PyCursesPanelObject *self, PyTypeObject *cls, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "", NULL}; - static _PyArg_Parser _parser = {"ii:move", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "move", 0}; + PyObject *argsbuf[2]; int y; int x; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &y, &x)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { + goto exit; + } + y = _PyLong_AsInt(args[0]); + if (y == -1 && PyErr_Occurred()) { + goto exit; + } + x = _PyLong_AsInt(args[1]); + if (x == -1 && PyErr_Occurred()) { goto exit; } return_value = _curses_panel_panel_move_impl(self, cls, y, x); @@ -243,13 +256,19 @@ _curses_panel_panel_replace(PyCursesPanelObject *self, PyTypeObject *cls, PyObje { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O!:replace", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0}; + PyObject *argsbuf[1]; PyCursesWindowObject *win; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &PyCursesWindow_Type, &win)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (!PyObject_TypeCheck(args[0], &PyCursesWindow_Type)) { + _PyArg_BadArgument("replace", "argument 1", (&PyCursesWindow_Type)->tp_name, args[0]); goto exit; } + win = (PyCursesWindowObject *)args[0]; return_value = _curses_panel_panel_replace_impl(self, cls, win); exit: @@ -274,13 +293,15 @@ _curses_panel_panel_set_userptr(PyCursesPanelObject *self, PyTypeObject *cls, Py { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O:set_userptr", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "set_userptr", 0}; + PyObject *argsbuf[1]; PyObject *obj; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &obj)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + obj = args[0]; return_value = _curses_panel_panel_set_userptr_impl(self, cls, obj); exit: @@ -305,10 +326,11 @@ _curses_panel_panel_userptr(PyCursesPanelObject *self, PyTypeObject *cls, PyObje { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":userptr", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "userptr", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _curses_panel_panel_userptr_impl(self, cls); @@ -401,4 +423,4 @@ _curses_panel_update_panels(PyObject *module, PyObject *Py_UNUSED(ignored)) { return _curses_panel_update_panels_impl(module); } -/*[clinic end generated code: output=3081ef24e5560cb0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b56a4f39ac8e2bd6 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h index f0b8220e7fee25..5f14c69311051a 100644 --- a/Modules/clinic/_dbmmodule.c.h +++ b/Modules/clinic/_dbmmodule.c.h @@ -37,10 +37,11 @@ _dbm_dbm_keys(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssiz { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":keys", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "keys", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _dbm_dbm_keys_impl(self, cls); @@ -179,4 +180,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=32ef6c0f8f2d3db9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3016d0c11f940ef6 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h index a40e80d8e1a7b9..4524f7adc9ae0a 100644 --- a/Modules/clinic/_gdbmmodule.c.h +++ b/Modules/clinic/_gdbmmodule.c.h @@ -106,10 +106,11 @@ _gdbm_gdbm_keys(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_s { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":keys", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "keys", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _gdbm_gdbm_keys_impl(self, cls); @@ -139,10 +140,11 @@ _gdbm_gdbm_firstkey(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":firstkey", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "firstkey", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _gdbm_gdbm_firstkey_impl(self, cls); @@ -214,10 +216,11 @@ _gdbm_gdbm_reorganize(gdbmobject *self, PyTypeObject *cls, PyObject *const *args { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":reorganize", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "reorganize", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _gdbm_gdbm_reorganize_impl(self, cls); @@ -246,10 +249,11 @@ _gdbm_gdbm_sync(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_s { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":sync", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "sync", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _gdbm_gdbm_sync_impl(self, cls); @@ -333,4 +337,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=63c507f93d84a3a4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=55d0054e5ca52c1e input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_lsprof.c.h b/Modules/clinic/_lsprof.c.h index 5d9c209eab8563..b133365abb6fa0 100644 --- a/Modules/clinic/_lsprof.c.h +++ b/Modules/clinic/_lsprof.c.h @@ -41,10 +41,11 @@ _lsprof_Profiler_getstats(ProfilerObject *self, PyTypeObject *cls, PyObject *con { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":getstats", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "getstats", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _lsprof_Profiler_getstats_impl(self, cls); @@ -52,4 +53,4 @@ _lsprof_Profiler_getstats(ProfilerObject *self, PyTypeObject *cls, PyObject *con exit: return return_value; } -/*[clinic end generated code: output=b4727cfebecdd22d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=25026d0a70f67826 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_queuemodule.c.h b/Modules/clinic/_queuemodule.c.h index 22d2e992b6398d..afb1e4b948782c 100644 --- a/Modules/clinic/_queuemodule.c.h +++ b/Modules/clinic/_queuemodule.c.h @@ -146,14 +146,30 @@ _queue_SimpleQueue_get(simplequeueobject *self, PyTypeObject *cls, PyObject *con { PyObject *return_value = NULL; static const char * const _keywords[] = {"block", "timeout", NULL}; - static _PyArg_Parser _parser = {"|pO:get", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "get", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int block = 1; PyObject *timeout_obj = Py_None; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &block, &timeout_obj)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { goto exit; } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + block = PyObject_IsTrue(args[0]); + if (block < 0) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + timeout_obj = args[1]; +skip_optional_pos: return_value = _queue_SimpleQueue_get_impl(self, cls, block, timeout_obj); exit: @@ -181,10 +197,11 @@ _queue_SimpleQueue_get_nowait(simplequeueobject *self, PyTypeObject *cls, PyObje { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":get_nowait", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "get_nowait", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _queue_SimpleQueue_get_nowait_impl(self, cls); @@ -248,4 +265,4 @@ _queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored)) exit: return return_value; } -/*[clinic end generated code: output=acfaf0191d8935db input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0c95174a416aa3a0 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testmultiphase.c.h b/Modules/clinic/_testmultiphase.c.h index b8ee93c6e19eaa..9839c176f20d9a 100644 --- a/Modules/clinic/_testmultiphase.c.h +++ b/Modules/clinic/_testmultiphase.c.h @@ -23,10 +23,11 @@ _testmultiphase_StateAccessType_get_defining_module(StateAccessTypeObject *self, { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":get_defining_module", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "get_defining_module", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _testmultiphase_StateAccessType_get_defining_module_impl(self, cls); @@ -53,10 +54,11 @@ _testmultiphase_StateAccessType_getmodulebydef_bad_def(StateAccessTypeObject *se { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":getmodulebydef_bad_def", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "getmodulebydef_bad_def", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(self, cls); @@ -88,14 +90,37 @@ _testmultiphase_StateAccessType_increment_count_clinic(StateAccessTypeObject *se { PyObject *return_value = NULL; static const char * const _keywords[] = {"n", "twice", NULL}; - static _PyArg_Parser _parser = {"|i$p:increment_count_clinic", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "increment_count_clinic", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int n = 1; int twice = 0; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &n, &twice)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { goto exit; } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + n = _PyLong_AsInt(args[0]); + if (n == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } +skip_optional_pos: + if (!noptargs) { + goto skip_optional_kwonly; + } + twice = PyObject_IsTrue(args[1]); + if (twice < 0) { + goto exit; + } +skip_optional_kwonly: return_value = _testmultiphase_StateAccessType_increment_count_clinic_impl(self, cls, n, twice); exit: @@ -120,10 +145,11 @@ _testmultiphase_StateAccessType_get_count(StateAccessTypeObject *self, PyTypeObj { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":get_count", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "get_count", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = _testmultiphase_StateAccessType_get_count_impl(self, cls); @@ -131,4 +157,4 @@ _testmultiphase_StateAccessType_get_count(StateAccessTypeObject *self, PyTypeObj exit: return return_value; } -/*[clinic end generated code: output=e8d074b4e6437438 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=59cb7bab76e7a411 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index 583ff28bf3287e..e8d7a6e3a37ae3 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -155,13 +155,15 @@ array_array_extend(arrayobject *self, PyTypeObject *cls, PyObject *const *args, { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O:extend", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "extend", 0}; + PyObject *argsbuf[1]; PyObject *bb; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &bb)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + bb = args[0]; return_value = array_array_extend_impl(self, cls, bb); exit: @@ -296,14 +298,28 @@ array_array_fromfile(arrayobject *self, PyTypeObject *cls, PyObject *const *args { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "", NULL}; - static _PyArg_Parser _parser = {"On:fromfile", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "fromfile", 0}; + PyObject *argsbuf[2]; PyObject *f; Py_ssize_t n; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &f, &n)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { goto exit; } + f = args[0]; + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + n = ival; + } return_value = array_array_fromfile_impl(self, cls, f, n); exit: @@ -327,13 +343,15 @@ array_array_tofile(arrayobject *self, PyTypeObject *cls, PyObject *const *args, { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O:tofile", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "tofile", 0}; + PyObject *argsbuf[1]; PyObject *f; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &f)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + f = args[0]; return_value = array_array_tofile_impl(self, cls, f); exit: @@ -567,13 +585,15 @@ array_array___reduce_ex__(arrayobject *self, PyTypeObject *cls, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O:__reduce_ex__", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "__reduce_ex__", 0}; + PyObject *argsbuf[1]; PyObject *value; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &value)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + value = args[0]; return_value = array_array___reduce_ex___impl(self, cls, value); exit: @@ -597,10 +617,11 @@ array_arrayiterator___reduce__(arrayiterobject *self, PyTypeObject *cls, PyObjec { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":__reduce__", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "__reduce__", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = array_arrayiterator___reduce___impl(self, cls); @@ -617,4 +638,4 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__, #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, -/*[clinic end generated code: output=1db6decd8492bf91 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d878182d18e48dad input=a9049054013a1b77]*/ diff --git a/Modules/clinic/md5module.c.h b/Modules/clinic/md5module.c.h index 4762f2800d4b82..147f516a31d8c1 100644 --- a/Modules/clinic/md5module.c.h +++ b/Modules/clinic/md5module.c.h @@ -19,10 +19,11 @@ MD5Type_copy(MD5object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":copy", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = MD5Type_copy_impl(self, cls); @@ -126,4 +127,4 @@ _md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw exit: return return_value; } -/*[clinic end generated code: output=53ff7f22dbaaea36 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=878f112d71c3d55f input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 282a5410f70206..84115116813e27 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -8291,11 +8291,12 @@ os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *c { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":is_symlink", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "is_symlink", 0}; + PyObject *argsbuf[0]; int _return_value; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } _return_value = os_DirEntry_is_symlink_impl(self, defining_class); @@ -8326,13 +8327,23 @@ os_DirEntry_stat(DirEntry *self, PyTypeObject *defining_class, PyObject *const * { PyObject *return_value = NULL; static const char * const _keywords[] = {"follow_symlinks", NULL}; - static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "stat", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int follow_symlinks = 1; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &follow_symlinks)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_kwonly; + } + follow_symlinks = PyObject_IsTrue(args[0]); + if (follow_symlinks < 0) { goto exit; } +skip_optional_kwonly: return_value = os_DirEntry_stat_impl(self, defining_class, follow_symlinks); exit: @@ -8357,14 +8368,24 @@ os_DirEntry_is_dir(DirEntry *self, PyTypeObject *defining_class, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = {"follow_symlinks", NULL}; - static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "is_dir", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int follow_symlinks = 1; int _return_value; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &follow_symlinks)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } + if (!noptargs) { + goto skip_optional_kwonly; + } + follow_symlinks = PyObject_IsTrue(args[0]); + if (follow_symlinks < 0) { + goto exit; + } +skip_optional_kwonly: _return_value = os_DirEntry_is_dir_impl(self, defining_class, follow_symlinks); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -8393,14 +8414,24 @@ os_DirEntry_is_file(DirEntry *self, PyTypeObject *defining_class, PyObject *cons { PyObject *return_value = NULL; static const char * const _keywords[] = {"follow_symlinks", NULL}; - static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "is_file", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int follow_symlinks = 1; int _return_value; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &follow_symlinks)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } + if (!noptargs) { + goto skip_optional_kwonly; + } + follow_symlinks = PyObject_IsTrue(args[0]); + if (follow_symlinks < 0) { + goto exit; + } +skip_optional_kwonly: _return_value = os_DirEntry_is_file_impl(self, defining_class, follow_symlinks); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -9303,4 +9334,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=d95ba7b0b9c52685 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b475160fab3f93c0 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/pyexpat.c.h b/Modules/clinic/pyexpat.c.h index 7c56d6a8b25910..bee2ee66950a5a 100644 --- a/Modules/clinic/pyexpat.c.h +++ b/Modules/clinic/pyexpat.c.h @@ -22,14 +22,24 @@ pyexpat_xmlparser_Parse(xmlparseobject *self, PyTypeObject *cls, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "", NULL}; - static _PyArg_Parser _parser = {"O|i:Parse", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "Parse", 0}; + PyObject *argsbuf[2]; PyObject *data; int isfinal = 0; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &data, &isfinal)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { + goto exit; + } + data = args[0]; + if (nargs < 2) { + goto skip_optional_posonly; + } + isfinal = _PyLong_AsInt(args[1]); + if (isfinal == -1 && PyErr_Occurred()) { goto exit; } +skip_optional_posonly: return_value = pyexpat_xmlparser_Parse_impl(self, cls, data, isfinal); exit: @@ -54,13 +64,15 @@ pyexpat_xmlparser_ParseFile(xmlparseobject *self, PyTypeObject *cls, PyObject *c { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O:ParseFile", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "ParseFile", 0}; + PyObject *argsbuf[1]; PyObject *file; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &file)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + file = args[0]; return_value = pyexpat_xmlparser_ParseFile_impl(self, cls, file); exit: @@ -164,14 +176,50 @@ pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyTypeObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "", NULL}; - static _PyArg_Parser _parser = {"z|s:ExternalEntityParserCreate", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "ExternalEntityParserCreate", 0}; + PyObject *argsbuf[2]; const char *context; const char *encoding = NULL; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &context, &encoding)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (args[0] == Py_None) { + context = NULL; + } + else if (PyUnicode_Check(args[0])) { + Py_ssize_t context_length; + context = PyUnicode_AsUTF8AndSize(args[0], &context_length); + if (context == NULL) { + goto exit; + } + if (strlen(context) != (size_t)context_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("ExternalEntityParserCreate", "argument 1", "str or None", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional_posonly; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("ExternalEntityParserCreate", "argument 2", "str", args[1]); goto exit; } + Py_ssize_t encoding_length; + encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); + if (encoding == NULL) { + goto exit; + } + if (strlen(encoding) != (size_t)encoding_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } +skip_optional_posonly: return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl(self, cls, context, encoding); exit: @@ -235,13 +283,22 @@ pyexpat_xmlparser_UseForeignDTD(xmlparseobject *self, PyTypeObject *cls, PyObjec { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"|p:UseForeignDTD", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "UseForeignDTD", 0}; + PyObject *argsbuf[1]; int flag = 1; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &flag)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (nargs < 1) { + goto skip_optional_posonly; + } + flag = PyObject_IsTrue(args[0]); + if (flag < 0) { goto exit; } +skip_optional_posonly: return_value = pyexpat_xmlparser_UseForeignDTD_impl(self, cls, flag); exit: @@ -368,4 +425,4 @@ pyexpat_ErrorString(PyObject *module, PyObject *arg) #ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */ -/*[clinic end generated code: output=612b9d6a17a679a7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5d60049d385d5d56 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha1module.c.h b/Modules/clinic/sha1module.c.h index 3a3ab58c1233cf..a3ee328aba5e31 100644 --- a/Modules/clinic/sha1module.c.h +++ b/Modules/clinic/sha1module.c.h @@ -19,10 +19,11 @@ SHA1Type_copy(SHA1object *self, PyTypeObject *cls, PyObject *const *args, Py_ssi { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":copy", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = SHA1Type_copy_impl(self, cls); @@ -126,4 +127,4 @@ _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * exit: return return_value; } -/*[clinic end generated code: output=abf1ab2545cea5a2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=018b0f112b4ec5b7 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha256module.c.h b/Modules/clinic/sha256module.c.h index 89205c4f14f4e4..7a2cd8a3bba8e0 100644 --- a/Modules/clinic/sha256module.c.h +++ b/Modules/clinic/sha256module.c.h @@ -19,10 +19,11 @@ SHA256Type_copy(SHAobject *self, PyTypeObject *cls, PyObject *const *args, Py_ss { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":copy", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = SHA256Type_copy_impl(self, cls); @@ -177,4 +178,4 @@ _sha256_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje exit: return return_value; } -/*[clinic end generated code: output=b7283f75c9d08f30 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5b96ad8f557a2b1f input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha512module.c.h b/Modules/clinic/sha512module.c.h index f1192d74f9a1ab..26326b024edb83 100644 --- a/Modules/clinic/sha512module.c.h +++ b/Modules/clinic/sha512module.c.h @@ -19,10 +19,11 @@ SHA512Type_copy(SHAobject *self, PyTypeObject *cls, PyObject *const *args, Py_ss { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":copy", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = SHA512Type_copy_impl(self, cls); @@ -177,4 +178,4 @@ _sha512_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje exit: return return_value; } -/*[clinic end generated code: output=9ff9f11937fabf35 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=320fff8cca7125a2 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h index 71136d31db0e09..bac2acfdd8178c 100644 --- a/Modules/clinic/zlibmodule.c.h +++ b/Modules/clinic/zlibmodule.c.h @@ -352,11 +352,19 @@ zlib_Compress_compress(compobject *self, PyTypeObject *cls, PyObject *const *arg { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"y*:compress", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "compress", 0}; + PyObject *argsbuf[1]; Py_buffer data = {NULL, NULL}; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &data)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("compress", "argument 1", "contiguous buffer", args[0]); goto exit; } return_value = zlib_Compress_compress_impl(self, cls, &data); @@ -399,14 +407,39 @@ zlib_Decompress_decompress(compobject *self, PyTypeObject *cls, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "max_length", NULL}; - static _PyArg_Parser _parser = {"y*|n:decompress", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "decompress", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; Py_buffer data = {NULL, NULL}; Py_ssize_t max_length = 0; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &data, &max_length)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { goto exit; } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("decompress", "argument 1", "contiguous buffer", args[0]); + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + max_length = ival; + } +skip_optional_pos: return_value = zlib_Decompress_decompress_impl(self, cls, &data, max_length); exit: @@ -441,13 +474,22 @@ zlib_Compress_flush(compobject *self, PyTypeObject *cls, PyObject *const *args, { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"|i:flush", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "flush", 0}; + PyObject *argsbuf[1]; int mode = Z_FINISH; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &mode)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { goto exit; } + if (nargs < 1) { + goto skip_optional_posonly; + } + mode = _PyLong_AsInt(args[0]); + if (mode == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_posonly: return_value = zlib_Compress_flush_impl(self, cls, mode); exit: @@ -473,10 +515,11 @@ zlib_Compress_copy(compobject *self, PyTypeObject *cls, PyObject *const *args, P { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":copy", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = zlib_Compress_copy_impl(self, cls); @@ -505,10 +548,11 @@ zlib_Compress___copy__(compobject *self, PyTypeObject *cls, PyObject *const *arg { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":__copy__", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "__copy__", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = zlib_Compress___copy___impl(self, cls); @@ -538,13 +582,15 @@ zlib_Compress___deepcopy__(compobject *self, PyTypeObject *cls, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O:__deepcopy__", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "__deepcopy__", 0}; + PyObject *argsbuf[1]; PyObject *memo; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &memo)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + memo = args[0]; return_value = zlib_Compress___deepcopy___impl(self, cls, memo); exit: @@ -572,10 +618,11 @@ zlib_Decompress_copy(compobject *self, PyTypeObject *cls, PyObject *const *args, { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":copy", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = zlib_Decompress_copy_impl(self, cls); @@ -604,10 +651,11 @@ zlib_Decompress___copy__(compobject *self, PyTypeObject *cls, PyObject *const *a { PyObject *return_value = NULL; static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":__copy__", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "__copy__", 0}; + PyObject *argsbuf[0]; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } return_value = zlib_Decompress___copy___impl(self, cls); @@ -637,13 +685,15 @@ zlib_Decompress___deepcopy__(compobject *self, PyTypeObject *cls, PyObject *cons { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"O:__deepcopy__", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "__deepcopy__", 0}; + PyObject *argsbuf[1]; PyObject *memo; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &memo)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + memo = args[0]; return_value = zlib_Decompress___deepcopy___impl(self, cls, memo); exit: @@ -673,13 +723,30 @@ zlib_Decompress_flush(compobject *self, PyTypeObject *cls, PyObject *const *args { PyObject *return_value = NULL; static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {"|n:flush", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "flush", 0}; + PyObject *argsbuf[1]; Py_ssize_t length = DEF_BUF_SIZE; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &length)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { goto exit; } + if (nargs < 1) { + goto skip_optional_posonly; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + length = ival; + } +skip_optional_posonly: return_value = zlib_Decompress_flush_impl(self, cls, length); exit: @@ -820,4 +887,4 @@ zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs) #ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */ -/*[clinic end generated code: output=f009d194565416d1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d47e757e8b4f487f input=a9049054013a1b77]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 14252b2514ea87..ffbd935a8ae0e6 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -639,6 +639,10 @@ def output_templates(self, f): assert parameters assert isinstance(parameters[0].converter, self_converter) del parameters[0] + requires_defining_class = False + if parameters and isinstance(parameters[0].converter, defining_class_converter): + requires_defining_class = True + del parameters[0] converters = [p.converter for p in parameters] has_option_groups = parameters and (parameters[0].group or parameters[-1].group) @@ -667,10 +671,6 @@ def output_templates(self, f): if not p.is_optional(): min_pos = i - requires_defining_class = any( - isinstance(p.converter, defining_class_converter) - for p in parameters) - meth_o = (len(parameters) == 1 and parameters[0].is_positional_only() and not converters[0].is_optional() and @@ -772,7 +772,7 @@ def parser_body(prototype, *fields, declarations=''): add(field) return linear_format(output(), parser_declarations=declarations) - if not parameters: + if not parameters and not requires_defining_class: # no parameters, METH_NOARGS flags = "METH_NOARGS" @@ -993,6 +993,8 @@ def parser_body(prototype, *fields, declarations=''): add_label = None for i, p in enumerate(parameters): + if isinstance(p.converter, defining_class_converter): + raise ValueError("defining_class should be the first parameter (after self)") displayname = p.get_displayname(i+1) parsearg = p.converter.parse_arg(argname_fmt % i, displayname) if parsearg is None: From 886ad89260edc42694dc4addcb68fdd0103e504a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 20 Apr 2022 16:12:18 +0300 Subject: [PATCH 2/4] Fix functions without parameters. --- Modules/_sre/clinic/sre.c.h | 34 +++------ Modules/cjkcodecs/clinic/multibytecodec.c.h | 18 ++--- Modules/clinic/_curses_panel.c.h | 82 ++++++--------------- Modules/clinic/_dbmmodule.c.h | 18 ++--- Modules/clinic/_gdbmmodule.c.h | 66 +++++------------ Modules/clinic/_lsprof.c.h | 18 ++--- Modules/clinic/_queuemodule.c.h | 18 ++--- Modules/clinic/_testmultiphase.c.h | 50 ++++--------- Modules/clinic/arraymodule.c.h | 18 ++--- Modules/clinic/md5module.c.h | 18 ++--- Modules/clinic/posixmodule.c.h | 11 +-- Modules/clinic/sha1module.c.h | 18 ++--- Modules/clinic/sha256module.c.h | 18 ++--- Modules/clinic/sha512module.c.h | 18 ++--- Modules/clinic/zlibmodule.c.h | 66 +++++------------ Tools/clinic/clinic.py | 45 +++++++---- 16 files changed, 156 insertions(+), 360 deletions(-) diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h index 035ace78a95345..c1b247ef7e9ddf 100644 --- a/Modules/_sre/clinic/sre.c.h +++ b/Modules/_sre/clinic/sre.c.h @@ -1102,19 +1102,11 @@ _sre_SRE_Scanner_match_impl(ScannerObject *self, PyTypeObject *cls); static PyObject * _sre_SRE_Scanner_match(ScannerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "match", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "match() takes no arguments"); + return NULL; } - return_value = _sre_SRE_Scanner_match_impl(self, cls); - -exit: - return return_value; + return _sre_SRE_Scanner_match_impl(self, cls); } PyDoc_STRVAR(_sre_SRE_Scanner_search__doc__, @@ -1131,18 +1123,10 @@ _sre_SRE_Scanner_search_impl(ScannerObject *self, PyTypeObject *cls); static PyObject * _sre_SRE_Scanner_search(ScannerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "search", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "search() takes no arguments"); + return NULL; } - return_value = _sre_SRE_Scanner_search_impl(self, cls); - -exit: - return return_value; + return _sre_SRE_Scanner_search_impl(self, cls); } -/*[clinic end generated code: output=ec64ab853f79cd46 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8d8200b2177cd667 input=a9049054013a1b77]*/ diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h index 0d019dafc50289..60515245490f74 100644 --- a/Modules/cjkcodecs/clinic/multibytecodec.c.h +++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h @@ -556,19 +556,11 @@ _multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *se static PyObject * _multibytecodec_MultibyteStreamWriter_reset(MultibyteStreamWriterObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "reset", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "reset() takes no arguments"); + return NULL; } - return_value = _multibytecodec_MultibyteStreamWriter_reset_impl(self, cls); - -exit: - return return_value; + return _multibytecodec_MultibyteStreamWriter_reset_impl(self, cls); } PyDoc_STRVAR(_multibytecodec___create_codec__doc__, @@ -578,4 +570,4 @@ PyDoc_STRVAR(_multibytecodec___create_codec__doc__, #define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \ {"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__}, -/*[clinic end generated code: output=55f6a328e1a03914 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0ee00c9f6883afe9 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_curses_panel.c.h b/Modules/clinic/_curses_panel.c.h index 937fdd95be3d28..e4642b58332de0 100644 --- a/Modules/clinic/_curses_panel.c.h +++ b/Modules/clinic/_curses_panel.c.h @@ -17,19 +17,11 @@ _curses_panel_panel_bottom_impl(PyCursesPanelObject *self, PyTypeObject *cls); static PyObject * _curses_panel_panel_bottom(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "bottom", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "bottom() takes no arguments"); + return NULL; } - return_value = _curses_panel_panel_bottom_impl(self, cls); - -exit: - return return_value; + return _curses_panel_panel_bottom_impl(self, cls); } PyDoc_STRVAR(_curses_panel_panel_hide__doc__, @@ -49,19 +41,11 @@ _curses_panel_panel_hide_impl(PyCursesPanelObject *self, PyTypeObject *cls); static PyObject * _curses_panel_panel_hide(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "hide", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "hide() takes no arguments"); + return NULL; } - return_value = _curses_panel_panel_hide_impl(self, cls); - -exit: - return return_value; + return _curses_panel_panel_hide_impl(self, cls); } PyDoc_STRVAR(_curses_panel_panel_show__doc__, @@ -79,19 +63,11 @@ _curses_panel_panel_show_impl(PyCursesPanelObject *self, PyTypeObject *cls); static PyObject * _curses_panel_panel_show(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "show", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "show() takes no arguments"); + return NULL; } - return_value = _curses_panel_panel_show_impl(self, cls); - -exit: - return return_value; + return _curses_panel_panel_show_impl(self, cls); } PyDoc_STRVAR(_curses_panel_panel_top__doc__, @@ -109,19 +85,11 @@ _curses_panel_panel_top_impl(PyCursesPanelObject *self, PyTypeObject *cls); static PyObject * _curses_panel_panel_top(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "top", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "top() takes no arguments"); + return NULL; } - return_value = _curses_panel_panel_top_impl(self, cls); - -exit: - return return_value; + return _curses_panel_panel_top_impl(self, cls); } PyDoc_STRVAR(_curses_panel_panel_above__doc__, @@ -324,19 +292,11 @@ _curses_panel_panel_userptr_impl(PyCursesPanelObject *self, static PyObject * _curses_panel_panel_userptr(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "userptr", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "userptr() takes no arguments"); + return NULL; } - return_value = _curses_panel_panel_userptr_impl(self, cls); - -exit: - return return_value; + return _curses_panel_panel_userptr_impl(self, cls); } PyDoc_STRVAR(_curses_panel_bottom_panel__doc__, @@ -423,4 +383,4 @@ _curses_panel_update_panels(PyObject *module, PyObject *Py_UNUSED(ignored)) { return _curses_panel_update_panels_impl(module); } -/*[clinic end generated code: output=b56a4f39ac8e2bd6 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c552457e8067bb0a input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h index 5f14c69311051a..a8b41607221f6f 100644 --- a/Modules/clinic/_dbmmodule.c.h +++ b/Modules/clinic/_dbmmodule.c.h @@ -35,19 +35,11 @@ _dbm_dbm_keys_impl(dbmobject *self, PyTypeObject *cls); static PyObject * _dbm_dbm_keys(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "keys", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "keys() takes no arguments"); + return NULL; } - return_value = _dbm_dbm_keys_impl(self, cls); - -exit: - return return_value; + return _dbm_dbm_keys_impl(self, cls); } PyDoc_STRVAR(_dbm_dbm_get__doc__, @@ -180,4 +172,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=3016d0c11f940ef6 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=492be70729515fe3 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h index 4524f7adc9ae0a..ced48b99ed3250 100644 --- a/Modules/clinic/_gdbmmodule.c.h +++ b/Modules/clinic/_gdbmmodule.c.h @@ -104,19 +104,11 @@ _gdbm_gdbm_keys_impl(gdbmobject *self, PyTypeObject *cls); static PyObject * _gdbm_gdbm_keys(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "keys", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "keys() takes no arguments"); + return NULL; } - return_value = _gdbm_gdbm_keys_impl(self, cls); - -exit: - return return_value; + return _gdbm_gdbm_keys_impl(self, cls); } PyDoc_STRVAR(_gdbm_gdbm_firstkey__doc__, @@ -138,19 +130,11 @@ _gdbm_gdbm_firstkey_impl(gdbmobject *self, PyTypeObject *cls); static PyObject * _gdbm_gdbm_firstkey(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "firstkey", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "firstkey() takes no arguments"); + return NULL; } - return_value = _gdbm_gdbm_firstkey_impl(self, cls); - -exit: - return return_value; + return _gdbm_gdbm_firstkey_impl(self, cls); } PyDoc_STRVAR(_gdbm_gdbm_nextkey__doc__, @@ -214,19 +198,11 @@ _gdbm_gdbm_reorganize_impl(gdbmobject *self, PyTypeObject *cls); static PyObject * _gdbm_gdbm_reorganize(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "reorganize", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "reorganize() takes no arguments"); + return NULL; } - return_value = _gdbm_gdbm_reorganize_impl(self, cls); - -exit: - return return_value; + return _gdbm_gdbm_reorganize_impl(self, cls); } PyDoc_STRVAR(_gdbm_gdbm_sync__doc__, @@ -247,19 +223,11 @@ _gdbm_gdbm_sync_impl(gdbmobject *self, PyTypeObject *cls); static PyObject * _gdbm_gdbm_sync(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "sync", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "sync() takes no arguments"); + return NULL; } - return_value = _gdbm_gdbm_sync_impl(self, cls); - -exit: - return return_value; + return _gdbm_gdbm_sync_impl(self, cls); } PyDoc_STRVAR(dbmopen__doc__, @@ -337,4 +305,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=55d0054e5ca52c1e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fe7a0812eb560b23 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_lsprof.c.h b/Modules/clinic/_lsprof.c.h index b133365abb6fa0..b0adb746974ab3 100644 --- a/Modules/clinic/_lsprof.c.h +++ b/Modules/clinic/_lsprof.c.h @@ -39,18 +39,10 @@ _lsprof_Profiler_getstats_impl(ProfilerObject *self, PyTypeObject *cls); static PyObject * _lsprof_Profiler_getstats(ProfilerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "getstats", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "getstats() takes no arguments"); + return NULL; } - return_value = _lsprof_Profiler_getstats_impl(self, cls); - -exit: - return return_value; + return _lsprof_Profiler_getstats_impl(self, cls); } -/*[clinic end generated code: output=25026d0a70f67826 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=57c7b6b0b8666429 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_queuemodule.c.h b/Modules/clinic/_queuemodule.c.h index afb1e4b948782c..056a8ef52e00fe 100644 --- a/Modules/clinic/_queuemodule.c.h +++ b/Modules/clinic/_queuemodule.c.h @@ -195,19 +195,11 @@ _queue_SimpleQueue_get_nowait_impl(simplequeueobject *self, static PyObject * _queue_SimpleQueue_get_nowait(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "get_nowait", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "get_nowait() takes no arguments"); + return NULL; } - return_value = _queue_SimpleQueue_get_nowait_impl(self, cls); - -exit: - return return_value; + return _queue_SimpleQueue_get_nowait_impl(self, cls); } PyDoc_STRVAR(_queue_SimpleQueue_empty__doc__, @@ -265,4 +257,4 @@ _queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored)) exit: return return_value; } -/*[clinic end generated code: output=0c95174a416aa3a0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=36301c405a858f39 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testmultiphase.c.h b/Modules/clinic/_testmultiphase.c.h index 9839c176f20d9a..753670934bf81d 100644 --- a/Modules/clinic/_testmultiphase.c.h +++ b/Modules/clinic/_testmultiphase.c.h @@ -21,19 +21,11 @@ _testmultiphase_StateAccessType_get_defining_module_impl(StateAccessTypeObject * static PyObject * _testmultiphase_StateAccessType_get_defining_module(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "get_defining_module", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "get_defining_module() takes no arguments"); + return NULL; } - return_value = _testmultiphase_StateAccessType_get_defining_module_impl(self, cls); - -exit: - return return_value; + return _testmultiphase_StateAccessType_get_defining_module_impl(self, cls); } PyDoc_STRVAR(_testmultiphase_StateAccessType_getmodulebydef_bad_def__doc__, @@ -52,19 +44,11 @@ _testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(StateAccessTypeObjec static PyObject * _testmultiphase_StateAccessType_getmodulebydef_bad_def(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "getmodulebydef_bad_def", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "getmodulebydef_bad_def() takes no arguments"); + return NULL; } - return_value = _testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(self, cls); - -exit: - return return_value; + return _testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(self, cls); } PyDoc_STRVAR(_testmultiphase_StateAccessType_increment_count_clinic__doc__, @@ -143,18 +127,10 @@ _testmultiphase_StateAccessType_get_count_impl(StateAccessTypeObject *self, static PyObject * _testmultiphase_StateAccessType_get_count(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "get_count", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "get_count() takes no arguments"); + return NULL; } - return_value = _testmultiphase_StateAccessType_get_count_impl(self, cls); - -exit: - return return_value; + return _testmultiphase_StateAccessType_get_count_impl(self, cls); } -/*[clinic end generated code: output=59cb7bab76e7a411 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b41a400ef84f50af input=a9049054013a1b77]*/ diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index e8d7a6e3a37ae3..030c6e7e1a4870 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -615,19 +615,11 @@ array_arrayiterator___reduce___impl(arrayiterobject *self, PyTypeObject *cls); static PyObject * array_arrayiterator___reduce__(arrayiterobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "__reduce__", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "__reduce__() takes no arguments"); + return NULL; } - return_value = array_arrayiterator___reduce___impl(self, cls); - -exit: - return return_value; + return array_arrayiterator___reduce___impl(self, cls); } PyDoc_STRVAR(array_arrayiterator___setstate____doc__, @@ -638,4 +630,4 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__, #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, -/*[clinic end generated code: output=d878182d18e48dad input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7f48d1691fa27442 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/md5module.c.h b/Modules/clinic/md5module.c.h index 147f516a31d8c1..0ff09b0050a562 100644 --- a/Modules/clinic/md5module.c.h +++ b/Modules/clinic/md5module.c.h @@ -17,19 +17,11 @@ MD5Type_copy_impl(MD5object *self, PyTypeObject *cls); static PyObject * MD5Type_copy(MD5object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "copy() takes no arguments"); + return NULL; } - return_value = MD5Type_copy_impl(self, cls); - -exit: - return return_value; + return MD5Type_copy_impl(self, cls); } PyDoc_STRVAR(MD5Type_digest__doc__, @@ -127,4 +119,4 @@ _md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw exit: return return_value; } -/*[clinic end generated code: output=878f112d71c3d55f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3061297a669c645c input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 84115116813e27..01834a1888c4cd 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -8290,14 +8290,11 @@ static PyObject * os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "is_symlink", 0}; - PyObject *argsbuf[0]; int _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments"); + return NULL; } _return_value = os_DirEntry_is_symlink_impl(self, defining_class); if ((_return_value == -1) && PyErr_Occurred()) { @@ -9334,4 +9331,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=b475160fab3f93c0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=94df188372283341 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha1module.c.h b/Modules/clinic/sha1module.c.h index a3ee328aba5e31..d9a2e150f6d417 100644 --- a/Modules/clinic/sha1module.c.h +++ b/Modules/clinic/sha1module.c.h @@ -17,19 +17,11 @@ SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls); static PyObject * SHA1Type_copy(SHA1object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "copy() takes no arguments"); + return NULL; } - return_value = SHA1Type_copy_impl(self, cls); - -exit: - return return_value; + return SHA1Type_copy_impl(self, cls); } PyDoc_STRVAR(SHA1Type_digest__doc__, @@ -127,4 +119,4 @@ _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * exit: return return_value; } -/*[clinic end generated code: output=018b0f112b4ec5b7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=93ced3c8f8fa4f21 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha256module.c.h b/Modules/clinic/sha256module.c.h index 7a2cd8a3bba8e0..619fab1a6fe2fb 100644 --- a/Modules/clinic/sha256module.c.h +++ b/Modules/clinic/sha256module.c.h @@ -17,19 +17,11 @@ SHA256Type_copy_impl(SHAobject *self, PyTypeObject *cls); static PyObject * SHA256Type_copy(SHAobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "copy() takes no arguments"); + return NULL; } - return_value = SHA256Type_copy_impl(self, cls); - -exit: - return return_value; + return SHA256Type_copy_impl(self, cls); } PyDoc_STRVAR(SHA256Type_digest__doc__, @@ -178,4 +170,4 @@ _sha256_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje exit: return return_value; } -/*[clinic end generated code: output=5b96ad8f557a2b1f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4f9fe3ca546b0c58 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/sha512module.c.h b/Modules/clinic/sha512module.c.h index 26326b024edb83..fada35eff22614 100644 --- a/Modules/clinic/sha512module.c.h +++ b/Modules/clinic/sha512module.c.h @@ -17,19 +17,11 @@ SHA512Type_copy_impl(SHAobject *self, PyTypeObject *cls); static PyObject * SHA512Type_copy(SHAobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "copy() takes no arguments"); + return NULL; } - return_value = SHA512Type_copy_impl(self, cls); - -exit: - return return_value; + return SHA512Type_copy_impl(self, cls); } PyDoc_STRVAR(SHA512Type_digest__doc__, @@ -178,4 +170,4 @@ _sha512_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje exit: return return_value; } -/*[clinic end generated code: output=320fff8cca7125a2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=26d2fe27b9673ac2 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h index bac2acfdd8178c..deadf872d0cf7c 100644 --- a/Modules/clinic/zlibmodule.c.h +++ b/Modules/clinic/zlibmodule.c.h @@ -513,19 +513,11 @@ zlib_Compress_copy_impl(compobject *self, PyTypeObject *cls); static PyObject * zlib_Compress_copy(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "copy() takes no arguments"); + return NULL; } - return_value = zlib_Compress_copy_impl(self, cls); - -exit: - return return_value; + return zlib_Compress_copy_impl(self, cls); } #endif /* defined(HAVE_ZLIB_COPY) */ @@ -546,19 +538,11 @@ zlib_Compress___copy___impl(compobject *self, PyTypeObject *cls); static PyObject * zlib_Compress___copy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "__copy__", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "__copy__() takes no arguments"); + return NULL; } - return_value = zlib_Compress___copy___impl(self, cls); - -exit: - return return_value; + return zlib_Compress___copy___impl(self, cls); } #endif /* defined(HAVE_ZLIB_COPY) */ @@ -616,19 +600,11 @@ zlib_Decompress_copy_impl(compobject *self, PyTypeObject *cls); static PyObject * zlib_Decompress_copy(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "copy", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "copy() takes no arguments"); + return NULL; } - return_value = zlib_Decompress_copy_impl(self, cls); - -exit: - return return_value; + return zlib_Decompress_copy_impl(self, cls); } #endif /* defined(HAVE_ZLIB_COPY) */ @@ -649,19 +625,11 @@ zlib_Decompress___copy___impl(compobject *self, PyTypeObject *cls); static PyObject * zlib_Decompress___copy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "__copy__", 0}; - PyObject *argsbuf[0]; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; + if (nargs) { + PyErr_SetString(PyExc_TypeError, "__copy__() takes no arguments"); + return NULL; } - return_value = zlib_Decompress___copy___impl(self, cls); - -exit: - return return_value; + return zlib_Decompress___copy___impl(self, cls); } #endif /* defined(HAVE_ZLIB_COPY) */ @@ -887,4 +855,4 @@ zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs) #ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */ -/*[clinic end generated code: output=d47e757e8b4f487f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bb1e27d8b2198a86 input=a9049054013a1b77]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index ffbd935a8ae0e6..031385945d8563 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -772,25 +772,39 @@ def parser_body(prototype, *fields, declarations=''): add(field) return linear_format(output(), parser_declarations=declarations) - if not parameters and not requires_defining_class: - # no parameters, METH_NOARGS + if not parameters: + if not requires_defining_class: + # no parameters, METH_NOARGS + flags = "METH_NOARGS" - flags = "METH_NOARGS" + parser_prototype = normalize_snippet(""" + static PyObject * + {c_basename}({self_type}{self_name}, PyObject *Py_UNUSED(ignored)) + """) + parser_code = [] - parser_prototype = normalize_snippet(""" - static PyObject * - {c_basename}({self_type}{self_name}, PyObject *Py_UNUSED(ignored)) - """) - parser_definition = parser_prototype + elif not parameters: + assert not new_or_init - if default_return_converter: - parser_definition = parser_prototype + '\n' + normalize_snippet(""" - {{ - return {c_basename}_impl({impl_arguments}); + flags = "METH_METHOD|METH_FASTCALL|METH_KEYWORDS" + + parser_prototype = parser_prototype_def_class + parser_code = [normalize_snippet(""" + if (nargs) {{ + PyErr_SetString(PyExc_TypeError, "{name}() takes no arguments"); + return NULL; }} - """) + """, indent=4)] + + if default_return_converter: + parser_definition = '\n'.join([ + parser_prototype, + '{{', + *parser_code, + ' return {c_basename}_impl({impl_arguments});', + '}}']) else: - parser_definition = parser_body(parser_prototype) + parser_definition = parser_body(parser_prototype, *parser_code) elif meth_o: flags = "METH_O" @@ -994,7 +1008,8 @@ def parser_body(prototype, *fields, declarations=''): add_label = None for i, p in enumerate(parameters): if isinstance(p.converter, defining_class_converter): - raise ValueError("defining_class should be the first parameter (after self)") + raise ValueError("defining_class should be the first " + "parameter (after self)") displayname = p.get_displayname(i+1) parsearg = p.converter.parse_arg(argname_fmt % i, displayname) if parsearg is None: From 8cd709a16d67f21220070797a1ed97ab0d135708 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 20 Apr 2022 16:45:58 +0300 Subject: [PATCH 3/4] Fix functions with defining_class and without parameters --- Modules/clinic/posixmodule.c.h | 4 ++-- Tools/clinic/clinic.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 01834a1888c4cd..352dadc9b56270 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -8294,7 +8294,7 @@ os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *c if (nargs) { PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments"); - return NULL; + goto exit; } _return_value = os_DirEntry_is_symlink_impl(self, defining_class); if ((_return_value == -1) && PyErr_Occurred()) { @@ -9331,4 +9331,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=94df188372283341 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c8c5b148b96068b4 input=a9049054013a1b77]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 031385945d8563..92d990a0ab4fae 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -789,12 +789,14 @@ def parser_body(prototype, *fields, declarations=''): flags = "METH_METHOD|METH_FASTCALL|METH_KEYWORDS" parser_prototype = parser_prototype_def_class + return_error = ('return NULL;' if default_return_converter + else 'goto exit;') parser_code = [normalize_snippet(""" if (nargs) {{ PyErr_SetString(PyExc_TypeError, "{name}() takes no arguments"); - return NULL; + %s }} - """, indent=4)] + """ % return_error, indent=4)] if default_return_converter: parser_definition = '\n'.join([ From e0521568878de602f21df5cc2627f08b14acfaec Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 21 Apr 2022 10:12:29 +0300 Subject: [PATCH 4/4] Cleanup. --- Tools/clinic/clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 92d990a0ab4fae..f660474da94a02 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -783,7 +783,7 @@ def parser_body(prototype, *fields, declarations=''): """) parser_code = [] - elif not parameters: + else: assert not new_or_init flags = "METH_METHOD|METH_FASTCALL|METH_KEYWORDS"