diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-08-29 14:55:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-29 14:55:56 (GMT) |
commit | 9205dfeca54cb24aa9a984c12a6419d71635be9f (patch) | |
tree | f731411be71e4ba7128b2dc0d28af2543aba3ca4 /Objects | |
parent | f8be2e262c5c2fdbc9721210ae1cb46edc16db82 (diff) | |
download | cpython-9205dfeca54cb24aa9a984c12a6419d71635be9f.zip cpython-9205dfeca54cb24aa9a984c12a6419d71635be9f.tar.gz cpython-9205dfeca54cb24aa9a984c12a6419d71635be9f.tar.bz2 |
gh-108635: Make parameters of some implementations of special methods positional-only (GH-108636)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/clinic/typevarobject.c.h | 222 | ||||
-rw-r--r-- | Objects/typevarobject.c | 21 |
2 files changed, 28 insertions, 215 deletions
diff --git a/Objects/clinic/typevarobject.c.h b/Objects/clinic/typevarobject.c.h index 54189b9..5d12be5 100644 --- a/Objects/clinic/typevarobject.c.h +++ b/Objects/clinic/typevarobject.c.h @@ -110,58 +110,12 @@ exit: } PyDoc_STRVAR(typevar_typing_subst__doc__, -"__typing_subst__($self, /, arg)\n" +"__typing_subst__($self, arg, /)\n" "--\n" "\n"); #define TYPEVAR_TYPING_SUBST_METHODDEF \ - {"__typing_subst__", _PyCFunction_CAST(typevar_typing_subst), METH_FASTCALL|METH_KEYWORDS, typevar_typing_subst__doc__}, - -static PyObject * -typevar_typing_subst_impl(typevarobject *self, PyObject *arg); - -static PyObject * -typevar_typing_subst(typevarobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { &_Py_ID(arg), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"arg", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "__typing_subst__", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; - PyObject *arg; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); - if (!args) { - goto exit; - } - arg = args[0]; - return_value = typevar_typing_subst_impl(self, arg); - -exit: - return return_value; -} + {"__typing_subst__", (PyCFunction)typevar_typing_subst, METH_O, typevar_typing_subst__doc__}, PyDoc_STRVAR(typevar_reduce__doc__, "__reduce__($self, /)\n" @@ -386,106 +340,33 @@ exit: } PyDoc_STRVAR(paramspec_typing_subst__doc__, -"__typing_subst__($self, /, arg)\n" +"__typing_subst__($self, arg, /)\n" "--\n" "\n"); #define PARAMSPEC_TYPING_SUBST_METHODDEF \ - {"__typing_subst__", _PyCFunction_CAST(paramspec_typing_subst), METH_FASTCALL|METH_KEYWORDS, paramspec_typing_subst__doc__}, - -static PyObject * -paramspec_typing_subst_impl(paramspecobject *self, PyObject *arg); - -static PyObject * -paramspec_typing_subst(paramspecobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { &_Py_ID(arg), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"arg", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "__typing_subst__", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; - PyObject *arg; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); - if (!args) { - goto exit; - } - arg = args[0]; - return_value = paramspec_typing_subst_impl(self, arg); - -exit: - return return_value; -} + {"__typing_subst__", (PyCFunction)paramspec_typing_subst, METH_O, paramspec_typing_subst__doc__}, PyDoc_STRVAR(paramspec_typing_prepare_subst__doc__, -"__typing_prepare_subst__($self, /, alias, args)\n" +"__typing_prepare_subst__($self, alias, args, /)\n" "--\n" "\n"); #define PARAMSPEC_TYPING_PREPARE_SUBST_METHODDEF \ - {"__typing_prepare_subst__", _PyCFunction_CAST(paramspec_typing_prepare_subst), METH_FASTCALL|METH_KEYWORDS, paramspec_typing_prepare_subst__doc__}, + {"__typing_prepare_subst__", _PyCFunction_CAST(paramspec_typing_prepare_subst), METH_FASTCALL, paramspec_typing_prepare_subst__doc__}, static PyObject * paramspec_typing_prepare_subst_impl(paramspecobject *self, PyObject *alias, PyObject *args); static PyObject * -paramspec_typing_prepare_subst(paramspecobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +paramspec_typing_prepare_subst(paramspecobject *self, PyObject *const *args, Py_ssize_t nargs) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 2 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { &_Py_ID(alias), &_Py_ID(args), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"alias", "args", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "__typing_prepare_subst__", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[2]; PyObject *alias; PyObject *__clinic_args; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); - if (!args) { + if (!_PyArg_CheckPositional("__typing_prepare_subst__", nargs, 2, 2)) { goto exit; } alias = args[0]; @@ -572,106 +453,33 @@ exit: } PyDoc_STRVAR(typevartuple_typing_subst__doc__, -"__typing_subst__($self, /, arg)\n" +"__typing_subst__($self, arg, /)\n" "--\n" "\n"); #define TYPEVARTUPLE_TYPING_SUBST_METHODDEF \ - {"__typing_subst__", _PyCFunction_CAST(typevartuple_typing_subst), METH_FASTCALL|METH_KEYWORDS, typevartuple_typing_subst__doc__}, - -static PyObject * -typevartuple_typing_subst_impl(typevartupleobject *self, PyObject *arg); - -static PyObject * -typevartuple_typing_subst(typevartupleobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { &_Py_ID(arg), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"arg", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "__typing_subst__", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; - PyObject *arg; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); - if (!args) { - goto exit; - } - arg = args[0]; - return_value = typevartuple_typing_subst_impl(self, arg); - -exit: - return return_value; -} + {"__typing_subst__", (PyCFunction)typevartuple_typing_subst, METH_O, typevartuple_typing_subst__doc__}, PyDoc_STRVAR(typevartuple_typing_prepare_subst__doc__, -"__typing_prepare_subst__($self, /, alias, args)\n" +"__typing_prepare_subst__($self, alias, args, /)\n" "--\n" "\n"); #define TYPEVARTUPLE_TYPING_PREPARE_SUBST_METHODDEF \ - {"__typing_prepare_subst__", _PyCFunction_CAST(typevartuple_typing_prepare_subst), METH_FASTCALL|METH_KEYWORDS, typevartuple_typing_prepare_subst__doc__}, + {"__typing_prepare_subst__", _PyCFunction_CAST(typevartuple_typing_prepare_subst), METH_FASTCALL, typevartuple_typing_prepare_subst__doc__}, static PyObject * typevartuple_typing_prepare_subst_impl(typevartupleobject *self, PyObject *alias, PyObject *args); static PyObject * -typevartuple_typing_prepare_subst(typevartupleobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +typevartuple_typing_prepare_subst(typevartupleobject *self, PyObject *const *args, Py_ssize_t nargs) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 2 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { &_Py_ID(alias), &_Py_ID(args), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"alias", "args", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "__typing_prepare_subst__", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[2]; PyObject *alias; PyObject *__clinic_args; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); - if (!args) { + if (!_PyArg_CheckPositional("__typing_prepare_subst__", nargs, 2, 2)) { goto exit; } alias = args[0]; @@ -783,4 +591,4 @@ skip_optional_kwonly: exit: return return_value; } -/*[clinic end generated code: output=807bcd30ebd10ac3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d614edf64f28e346 input=a9049054013a1b77]*/ diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c index ef1803d..3adae3e 100644 --- a/Objects/typevarobject.c +++ b/Objects/typevarobject.c @@ -402,12 +402,13 @@ typevar_new_impl(PyTypeObject *type, PyObject *name, PyObject *constraints, typevar.__typing_subst__ as typevar_typing_subst arg: object + / [clinic start generated code]*/ static PyObject * -typevar_typing_subst_impl(typevarobject *self, PyObject *arg) -/*[clinic end generated code: output=c76ced134ed8f4e1 input=6b70a4bb2da838de]*/ +typevar_typing_subst(typevarobject *self, PyObject *arg) +/*[clinic end generated code: output=0773735e8ce18968 input=9e87b57f0fc59b92]*/ { PyObject *args[2] = {(PyObject *)self, arg}; PyObject *result = call_typing_func_object("_typevar_subst", args, 2); @@ -884,12 +885,13 @@ paramspec_new_impl(PyTypeObject *type, PyObject *name, PyObject *bound, paramspec.__typing_subst__ as paramspec_typing_subst arg: object + / [clinic start generated code]*/ static PyObject * -paramspec_typing_subst_impl(paramspecobject *self, PyObject *arg) -/*[clinic end generated code: output=803e1ade3f13b57d input=4e0005d24023e896]*/ +paramspec_typing_subst(paramspecobject *self, PyObject *arg) +/*[clinic end generated code: output=4c5b4aaada1c5814 input=2d5b5e3d4a717189]*/ { PyObject *args[2] = {(PyObject *)self, arg}; PyObject *result = call_typing_func_object("_paramspec_subst", args, 2); @@ -901,13 +903,14 @@ paramspec.__typing_prepare_subst__ as paramspec_typing_prepare_subst alias: object args: object + / [clinic start generated code]*/ static PyObject * paramspec_typing_prepare_subst_impl(paramspecobject *self, PyObject *alias, PyObject *args) -/*[clinic end generated code: output=95449d630a2adb9a input=4375e2ffcb2ad635]*/ +/*[clinic end generated code: output=95449d630a2adb9a input=6df6f9fef3e150da]*/ { PyObject *args_array[3] = {(PyObject *)self, alias, args}; PyObject *result = call_typing_func_object( @@ -1106,12 +1109,13 @@ typevartuple_impl(PyTypeObject *type, PyObject *name) typevartuple.__typing_subst__ as typevartuple_typing_subst arg: object + / [clinic start generated code]*/ static PyObject * -typevartuple_typing_subst_impl(typevartupleobject *self, PyObject *arg) -/*[clinic end generated code: output=814316519441cd76 input=670c4e0a36e5d8c0]*/ +typevartuple_typing_subst(typevartupleobject *self, PyObject *arg) +/*[clinic end generated code: output=237054c6d7484eea input=3fcf2dfd9eee7945]*/ { PyErr_SetString(PyExc_TypeError, "Substitution of bare TypeVarTuple is not supported"); return NULL; @@ -1122,13 +1126,14 @@ typevartuple.__typing_prepare_subst__ as typevartuple_typing_prepare_subst alias: object args: object + / [clinic start generated code]*/ static PyObject * typevartuple_typing_prepare_subst_impl(typevartupleobject *self, PyObject *alias, PyObject *args) -/*[clinic end generated code: output=ff999bc5b02036c1 input=a211b05f2eeb4306]*/ +/*[clinic end generated code: output=ff999bc5b02036c1 input=685b149b0fc47556]*/ { PyObject *args_array[3] = {(PyObject *)self, alias, args}; PyObject *result = call_typing_func_object( |