gh-108635: Make parameters of some implementations of special methods positional-only (GH-108636)

This commit is contained in:
Serhiy Storchaka 2023-08-29 17:55:56 +03:00 committed by GitHub
parent f8be2e262c
commit 9205dfeca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 254 deletions

View File

@ -789,7 +789,6 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(aggregate_class));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(alias));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(append));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(arg));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(argdefs));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(args));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(arguments));

View File

@ -278,7 +278,6 @@ struct _Py_global_strings {
STRUCT_FOR_ID(aggregate_class)
STRUCT_FOR_ID(alias)
STRUCT_FOR_ID(append)
STRUCT_FOR_ID(arg)
STRUCT_FOR_ID(argdefs)
STRUCT_FOR_ID(args)
STRUCT_FOR_ID(arguments)

View File

@ -787,7 +787,6 @@ extern "C" {
INIT_ID(aggregate_class), \
INIT_ID(alias), \
INIT_ID(append), \
INIT_ID(arg), \
INIT_ID(argdefs), \
INIT_ID(args), \
INIT_ID(arguments), \

View File

@ -675,9 +675,6 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) {
string = &_Py_ID(append);
assert(_PyUnicode_CheckConsistency(string, 1));
_PyUnicode_InternInPlace(interp, &string);
string = &_Py_ID(arg);
assert(_PyUnicode_CheckConsistency(string, 1));
_PyUnicode_InternInPlace(interp, &string);
string = &_Py_ID(argdefs);
assert(_PyUnicode_CheckConsistency(string, 1));
_PyUnicode_InternInPlace(interp, &string);

View File

@ -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]*/

View File

@ -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(

37
PC/clinic/winreg.c.h generated
View File

@ -93,53 +93,26 @@ winreg_HKEYType___enter__(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
PyDoc_STRVAR(winreg_HKEYType___exit____doc__,
"__exit__($self, /, exc_type, exc_value, traceback)\n"
"__exit__($self, exc_type, exc_value, traceback, /)\n"
"--\n"
"\n");
#define WINREG_HKEYTYPE___EXIT___METHODDEF \
{"__exit__", _PyCFunction_CAST(winreg_HKEYType___exit__), METH_FASTCALL|METH_KEYWORDS, winreg_HKEYType___exit____doc__},
{"__exit__", _PyCFunction_CAST(winreg_HKEYType___exit__), METH_FASTCALL, winreg_HKEYType___exit____doc__},
static PyObject *
winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type,
PyObject *exc_value, PyObject *traceback);
static PyObject *
winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
winreg_HKEYType___exit__(PyHKEYObject *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 3
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(exc_type), &_Py_ID(exc_value), &_Py_ID(traceback), },
};
#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[] = {"exc_type", "exc_value", "traceback", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "__exit__",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
PyObject *argsbuf[3];
PyObject *exc_type;
PyObject *exc_value;
PyObject *traceback;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
if (!args) {
if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
goto exit;
}
exc_type = args[0];
@ -1789,4 +1762,4 @@ exit:
#ifndef WINREG_QUERYREFLECTIONKEY_METHODDEF
#define WINREG_QUERYREFLECTIONKEY_METHODDEF
#endif /* !defined(WINREG_QUERYREFLECTIONKEY_METHODDEF) */
/*[clinic end generated code: output=00343ee8da923da8 input=a9049054013a1b77]*/
/*[clinic end generated code: output=2431b1b06b148722 input=a9049054013a1b77]*/

View File

@ -324,12 +324,14 @@ winreg.HKEYType.__exit__
exc_type: object
exc_value: object
traceback: object
/
[clinic start generated code]*/
static PyObject *
winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type,
PyObject *exc_value, PyObject *traceback)
/*[clinic end generated code: output=923ebe7389e6a263 input=fb32489ee92403c7]*/
/*[clinic end generated code: output=923ebe7389e6a263 input=1eac83cd06962689]*/
{
winreg_state *st = _PyType_GetModuleState(Py_TYPE(self));
assert(st != NULL);