https://github.com/python/cpython/commit/061da44bacf347cc1fe82b03976e95f9c0992673
commit: 061da44bacf347cc1fe82b03976e95f9c0992673
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-03-12T17:42:07+01:00
summary:
gh-111178: Change Argument Clinic signature for `@classmethod` (#131157)
Use "PyObject*", instead of "PyTypeObject*", for `@classmethod`
functions to fix an undefined behavior.
files:
M Lib/test/clinic.test.c
M Modules/_datetimemodule.c
M Modules/_multiprocessing/clinic/semaphore.c.h
M Modules/clinic/_datetimemodule.c.h
M Modules/clinic/_zoneinfo.c.h
M Modules/clinic/itertoolsmodule.c.h
M Modules/clinic/selectmodule.c.h
M Modules/itertoolsmodule.c
M Objects/bytearrayobject.c
M Objects/bytesobject.c
M Objects/clinic/bytearrayobject.c.h
M Objects/clinic/bytesobject.c.h
M Objects/clinic/complexobject.c.h
M Objects/clinic/dictobject.c.h
M Objects/clinic/floatobject.c.h
M Objects/clinic/longobject.c.h
M Objects/clinic/memoryobject.c.h
M Objects/clinic/odictobject.c.h
M Objects/complexobject.c
M Objects/floatobject.c
M Tools/clinic/libclinic/converters.py
M Tools/clinic/libclinic/parse_args.py
diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c
index 2f843371ff9d7c..68330051771222 100644
--- a/Lib/test/clinic.test.c
+++ b/Lib/test/clinic.test.c
@@ -5235,14 +5235,14 @@ static PyObject *
Test_class_method_impl(PyTypeObject *type);
static PyObject *
-Test_class_method(PyTypeObject *type, PyObject *Py_UNUSED(ignored))
+Test_class_method(PyObject *type, PyObject *Py_UNUSED(ignored))
{
- return Test_class_method_impl(type);
+ return Test_class_method_impl((PyTypeObject *)type);
}
static PyObject *
Test_class_method_impl(PyTypeObject *type)
-/*[clinic end generated code: output=47fb7ecca1abcaaa input=43bc4a0494547b80]*/
+/*[clinic end generated code: output=64f93e6252bde409 input=43bc4a0494547b80]*/
/*[clinic input]
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 07d7089be09d20..83b92fe606984c 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -3290,8 +3290,8 @@ as local time.
[clinic start generated code]*/
static PyObject *
-datetime_date_fromtimestamp(PyTypeObject *type, PyObject *timestamp)
-/*[clinic end generated code: output=fd045fda58168869 input=eabb3fe7f40491fe]*/
+datetime_date_fromtimestamp_impl(PyTypeObject *type, PyObject *timestamp)
+/*[clinic end generated code: output=59def4e32c028fb6 input=eabb3fe7f40491fe]*/
{
return date_fromtimestamp((PyObject *) type, timestamp);
}
diff --git a/Modules/_multiprocessing/clinic/semaphore.c.h
b/Modules/_multiprocessing/clinic/semaphore.c.h
index e789137ec1e013..74a9daa3c67ad2 100644
--- a/Modules/_multiprocessing/clinic/semaphore.c.h
+++ b/Modules/_multiprocessing/clinic/semaphore.c.h
@@ -323,7 +323,7 @@ _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type,
SEM_HANDLE handle,
const char *name);
static PyObject *
-_multiprocessing_SemLock__rebuild(PyTypeObject *type, PyObject *const *args,
Py_ssize_t nargs)
+_multiprocessing_SemLock__rebuild(PyObject *type, PyObject *const *args,
Py_ssize_t nargs)
{
PyObject *return_value = NULL;
SEM_HANDLE handle;
@@ -335,7 +335,7 @@ _multiprocessing_SemLock__rebuild(PyTypeObject *type,
PyObject *const *args, Py_
&handle, &kind, &maxvalue, &name)) {
goto exit;
}
- return_value = _multiprocessing_SemLock__rebuild_impl(type, handle, kind,
maxvalue, name);
+ return_value = _multiprocessing_SemLock__rebuild_impl((PyTypeObject
*)type, handle, kind, maxvalue, name);
exit:
return return_value;
@@ -576,4 +576,4 @@ _multiprocessing_SemLock___exit__(PyObject *self, PyObject
*const *args, Py_ssiz
#ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
#define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
#endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */
-/*[clinic end generated code: output=e28d0fdbfefd1235 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=dddd8e989525f565 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_datetimemodule.c.h
b/Modules/clinic/_datetimemodule.c.h
index 8f33c9e7d4eae5..d200c9cfd1888b 100644
--- a/Modules/clinic/_datetimemodule.c.h
+++ b/Modules/clinic/_datetimemodule.c.h
@@ -20,6 +20,19 @@ PyDoc_STRVAR(datetime_date_fromtimestamp__doc__,
#define DATETIME_DATE_FROMTIMESTAMP_METHODDEF \
{"fromtimestamp", (PyCFunction)datetime_date_fromtimestamp,
METH_O|METH_CLASS, datetime_date_fromtimestamp__doc__},
+static PyObject *
+datetime_date_fromtimestamp_impl(PyTypeObject *type, PyObject *timestamp);
+
+static PyObject *
+datetime_date_fromtimestamp(PyObject *type, PyObject *timestamp)
+{
+ PyObject *return_value = NULL;
+
+ return_value = datetime_date_fromtimestamp_impl((PyTypeObject *)type,
timestamp);
+
+ return return_value;
+}
+
static PyObject *
iso_calendar_date_new_impl(PyTypeObject *type, int year, int week,
int weekday);
@@ -304,7 +317,7 @@ static PyObject *
datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz);
static PyObject *
-datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t
nargs, PyObject *kwnames)
+datetime_datetime_now(PyObject *type, PyObject *const *args, Py_ssize_t nargs,
PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -346,7 +359,7 @@ datetime_datetime_now(PyTypeObject *type, PyObject *const
*args, Py_ssize_t narg
}
tz = args[0];
skip_optional_pos:
- return_value = datetime_datetime_now_impl(type, tz);
+ return_value = datetime_datetime_now_impl((PyTypeObject *)type, tz);
exit:
return return_value;
@@ -501,4 +514,4 @@ datetime_datetime_replace(PyObject *self, PyObject *const
*args, Py_ssize_t narg
exit:
return return_value;
}
-/*[clinic end generated code: output=8acf62fbc7328f79 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7b55f2d9a4596b58 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_zoneinfo.c.h b/Modules/clinic/_zoneinfo.c.h
index dd72b5e663aea6..52ea3368ab12c7 100644
--- a/Modules/clinic/_zoneinfo.c.h
+++ b/Modules/clinic/_zoneinfo.c.h
@@ -80,7 +80,7 @@ zoneinfo_ZoneInfo_from_file_impl(PyTypeObject *type,
PyTypeObject *cls,
PyObject *file_obj, PyObject *key);
static PyObject *
-zoneinfo_ZoneInfo_from_file(PyTypeObject *type, PyTypeObject *cls, PyObject
*const *args, Py_ssize_t nargs, PyObject *kwnames)
+zoneinfo_ZoneInfo_from_file(PyObject *type, PyTypeObject *cls, PyObject *const
*args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -124,7 +124,7 @@ zoneinfo_ZoneInfo_from_file(PyTypeObject *type,
PyTypeObject *cls, PyObject *con
}
key = args[1];
skip_optional_pos:
- return_value = zoneinfo_ZoneInfo_from_file_impl(type, cls, file_obj, key);
+ return_value = zoneinfo_ZoneInfo_from_file_impl((PyTypeObject *)type, cls,
file_obj, key);
exit:
return return_value;
@@ -144,7 +144,7 @@ zoneinfo_ZoneInfo_no_cache_impl(PyTypeObject *type,
PyTypeObject *cls,
PyObject *key);
static PyObject *
-zoneinfo_ZoneInfo_no_cache(PyTypeObject *type, PyTypeObject *cls, PyObject
*const *args, Py_ssize_t nargs, PyObject *kwnames)
+zoneinfo_ZoneInfo_no_cache(PyObject *type, PyTypeObject *cls, PyObject *const
*args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -181,7 +181,7 @@ zoneinfo_ZoneInfo_no_cache(PyTypeObject *type, PyTypeObject
*cls, PyObject *cons
goto exit;
}
key = args[0];
- return_value = zoneinfo_ZoneInfo_no_cache_impl(type, cls, key);
+ return_value = zoneinfo_ZoneInfo_no_cache_impl((PyTypeObject *)type, cls,
key);
exit:
return return_value;
@@ -201,7 +201,7 @@ zoneinfo_ZoneInfo_clear_cache_impl(PyTypeObject *type,
PyTypeObject *cls,
PyObject *only_keys);
static PyObject *
-zoneinfo_ZoneInfo_clear_cache(PyTypeObject *type, PyTypeObject *cls, PyObject
*const *args, Py_ssize_t nargs, PyObject *kwnames)
+zoneinfo_ZoneInfo_clear_cache(PyObject *type, PyTypeObject *cls, PyObject
*const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -244,7 +244,7 @@ zoneinfo_ZoneInfo_clear_cache(PyTypeObject *type,
PyTypeObject *cls, PyObject *c
only_keys = args[0];
skip_optional_kwonly:
Py_BEGIN_CRITICAL_SECTION(type);
- return_value = zoneinfo_ZoneInfo_clear_cache_impl(type, cls, only_keys);
+ return_value = zoneinfo_ZoneInfo_clear_cache_impl((PyTypeObject *)type,
cls, only_keys);
Py_END_CRITICAL_SECTION();
exit:
@@ -399,7 +399,7 @@ zoneinfo_ZoneInfo__unpickle_impl(PyTypeObject *type,
PyTypeObject *cls,
PyObject *key, unsigned char from_cache);
static PyObject *
-zoneinfo_ZoneInfo__unpickle(PyTypeObject *type, PyTypeObject *cls, PyObject
*const *args, Py_ssize_t nargs, PyObject *kwnames)
+zoneinfo_ZoneInfo__unpickle(PyObject *type, PyTypeObject *cls, PyObject *const
*args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -434,9 +434,9 @@ zoneinfo_ZoneInfo__unpickle(PyTypeObject *type,
PyTypeObject *cls, PyObject *con
from_cache = (unsigned char) ival;
}
}
- return_value = zoneinfo_ZoneInfo__unpickle_impl(type, cls, key,
from_cache);
+ return_value = zoneinfo_ZoneInfo__unpickle_impl((PyTypeObject *)type, cls,
key, from_cache);
exit:
return return_value;
}
-/*[clinic end generated code: output=f8a4fb4ff634d6c9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=786e8579e58c2f1c input=a9049054013a1b77]*/
diff --git a/Modules/clinic/itertoolsmodule.c.h
b/Modules/clinic/itertoolsmodule.c.h
index ea0cc495ffb969..401c87e846f501 100644
--- a/Modules/clinic/itertoolsmodule.c.h
+++ b/Modules/clinic/itertoolsmodule.c.h
@@ -486,6 +486,19 @@ PyDoc_STRVAR(itertools_chain_from_iterable__doc__,
#define ITERTOOLS_CHAIN_FROM_ITERABLE_METHODDEF \
{"from_iterable", (PyCFunction)itertools_chain_from_iterable,
METH_O|METH_CLASS, itertools_chain_from_iterable__doc__},
+static PyObject *
+itertools_chain_from_iterable_impl(PyTypeObject *type, PyObject *arg);
+
+static PyObject *
+itertools_chain_from_iterable(PyObject *type, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+
+ return_value = itertools_chain_from_iterable_impl((PyTypeObject *)type,
arg);
+
+ return return_value;
+}
+
PyDoc_STRVAR(itertools_combinations__doc__,
"combinations(iterable, r)\n"
"--\n"
@@ -936,4 +949,4 @@ itertools_count(PyTypeObject *type, PyObject *args,
PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=199eeac2d17e8f23 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=688855b1dc77bf5a input=a9049054013a1b77]*/
diff --git a/Modules/clinic/selectmodule.c.h b/Modules/clinic/selectmodule.c.h
index d8bdd6f95f3d29..8ee291dcca8b16 100644
--- a/Modules/clinic/selectmodule.c.h
+++ b/Modules/clinic/selectmodule.c.h
@@ -693,7 +693,7 @@ static PyObject *
select_epoll_fromfd_impl(PyTypeObject *type, int fd);
static PyObject *
-select_epoll_fromfd(PyTypeObject *type, PyObject *arg)
+select_epoll_fromfd(PyObject *type, PyObject *arg)
{
PyObject *return_value = NULL;
int fd;
@@ -702,7 +702,7 @@ select_epoll_fromfd(PyTypeObject *type, PyObject *arg)
if (fd == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = select_epoll_fromfd_impl(type, fd);
+ return_value = select_epoll_fromfd_impl((PyTypeObject *)type, fd);
exit:
return return_value;
@@ -1196,7 +1196,7 @@ static PyObject *
select_kqueue_fromfd_impl(PyTypeObject *type, int fd);
static PyObject *
-select_kqueue_fromfd(PyTypeObject *type, PyObject *arg)
+select_kqueue_fromfd(PyObject *type, PyObject *arg)
{
PyObject *return_value = NULL;
int fd;
@@ -1205,7 +1205,7 @@ select_kqueue_fromfd(PyTypeObject *type, PyObject *arg)
if (fd == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = select_kqueue_fromfd_impl(type, fd);
+ return_value = select_kqueue_fromfd_impl((PyTypeObject *)type, fd);
exit:
return return_value;
@@ -1365,4 +1365,4 @@ select_kqueue_control(PyObject *self, PyObject *const
*args, Py_ssize_t nargs)
#ifndef SELECT_KQUEUE_CONTROL_METHODDEF
#define SELECT_KQUEUE_CONTROL_METHODDEF
#endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */
-/*[clinic end generated code: output=c18fd93efc5f4dce input=a9049054013a1b77]*/
+/*[clinic end generated code: output=60c3edb2745c9f33 input=a9049054013a1b77]*/
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 40e436a6717ba7..9c9a965ce74feb 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1843,8 +1843,8 @@ Alternative chain() constructor taking a single iterable
argument that evaluates
[clinic start generated code]*/
static PyObject *
-itertools_chain_from_iterable(PyTypeObject *type, PyObject *arg)
-/*[clinic end generated code: output=667ae7a7f7b68654 input=72c39e3a2ca3be85]*/
+itertools_chain_from_iterable_impl(PyTypeObject *type, PyObject *arg)
+/*[clinic end generated code: output=3d7ea7d46b9e43f5 input=72c39e3a2ca3be85]*/
{
PyObject *source;
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index f1c76664198abc..8f2d2dd02151c1 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -2543,8 +2543,8 @@ Example: bytearray.fromhex('B9 01EF') ->
bytearray(b'\\xb9\\x01\\xef')
[clinic start generated code]*/
static PyObject *
-bytearray_fromhex(PyTypeObject *type, PyObject *string)
-/*[clinic end generated code: output=da84dc708e9c4b36 input=7e314e5b2d7ab484]*/
+bytearray_fromhex_impl(PyTypeObject *type, PyObject *string)
+/*[clinic end generated code: output=8f0f0b6d30fb3ba0 input=7e314e5b2d7ab484]*/
{
PyObject *result = _PyBytes_FromHex(string, type == &PyByteArray_Type);
if (type != &PyByteArray_Type && result != NULL) {
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index ada0d0024827dc..1615571035853c 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -2494,8 +2494,8 @@ Example: bytes.fromhex('B9 01EF') -> b'\\xb9\\x01\\xef'.
[clinic start generated code]*/
static PyObject *
-bytes_fromhex(PyTypeObject *type, PyObject *string)
-/*[clinic end generated code: output=d458ec88195da6b3 input=f37d98ed51088a21]*/
+bytes_fromhex_impl(PyTypeObject *type, PyObject *string)
+/*[clinic end generated code: output=0973acc63661bb2e input=f37d98ed51088a21]*/
{
PyObject *result = _PyBytes_FromHex(string, 0);
if (type != &PyBytes_Type && result != NULL) {
diff --git a/Objects/clinic/bytearrayobject.c.h
b/Objects/clinic/bytearrayobject.c.h
index 8ed10d8ab5a8b2..5f41c53a365534 100644
--- a/Objects/clinic/bytearrayobject.c.h
+++ b/Objects/clinic/bytearrayobject.c.h
@@ -1601,6 +1601,19 @@ PyDoc_STRVAR(bytearray_fromhex__doc__,
#define BYTEARRAY_FROMHEX_METHODDEF \
{"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS,
bytearray_fromhex__doc__},
+static PyObject *
+bytearray_fromhex_impl(PyTypeObject *type, PyObject *string);
+
+static PyObject *
+bytearray_fromhex(PyObject *type, PyObject *string)
+{
+ PyObject *return_value = NULL;
+
+ return_value = bytearray_fromhex_impl((PyTypeObject *)type, string);
+
+ return return_value;
+}
+
PyDoc_STRVAR(bytearray_hex__doc__,
"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n"
"--\n"
@@ -1769,4 +1782,4 @@ bytearray_sizeof(PyObject *self, PyObject
*Py_UNUSED(ignored))
{
return bytearray_sizeof_impl((PyByteArrayObject *)self);
}
-/*[clinic end generated code: output=13a4231325b7d3c1 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b1dce6c12ad1a9e2 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h
index c0f61f1368ba2b..d50daeffd74ed2 100644
--- a/Objects/clinic/bytesobject.c.h
+++ b/Objects/clinic/bytesobject.c.h
@@ -1204,6 +1204,19 @@ PyDoc_STRVAR(bytes_fromhex__doc__,
#define BYTES_FROMHEX_METHODDEF \
{"fromhex", (PyCFunction)bytes_fromhex, METH_O|METH_CLASS,
bytes_fromhex__doc__},
+static PyObject *
+bytes_fromhex_impl(PyTypeObject *type, PyObject *string);
+
+static PyObject *
+bytes_fromhex(PyObject *type, PyObject *string)
+{
+ PyObject *return_value = NULL;
+
+ return_value = bytes_fromhex_impl((PyTypeObject *)type, string);
+
+ return return_value;
+}
+
PyDoc_STRVAR(bytes_hex__doc__,
"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n"
"--\n"
@@ -1384,4 +1397,4 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject
*kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=967aae4b46423586 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=60d6a9f1333b76f0 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/complexobject.c.h b/Objects/clinic/complexobject.c.h
index e00da1d960c54d..2988664317eede 100644
--- a/Objects/clinic/complexobject.c.h
+++ b/Objects/clinic/complexobject.c.h
@@ -170,4 +170,17 @@ PyDoc_STRVAR(complex_from_number__doc__,
#define COMPLEX_FROM_NUMBER_METHODDEF \
{"from_number", (PyCFunction)complex_from_number, METH_O|METH_CLASS,
complex_from_number__doc__},
-/*[clinic end generated code: output=252cddef7f9169a0 input=a9049054013a1b77]*/
+
+static PyObject *
+complex_from_number_impl(PyTypeObject *type, PyObject *number);
+
+static PyObject *
+complex_from_number(PyObject *type, PyObject *number)
+{
+ PyObject *return_value = NULL;
+
+ return_value = complex_from_number_impl((PyTypeObject *)type, number);
+
+ return return_value;
+}
+/*[clinic end generated code: output=307531cd6d6e7544 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h
index 36da98f7477d59..abf6b38449fcb0 100644
--- a/Objects/clinic/dictobject.c.h
+++ b/Objects/clinic/dictobject.c.h
@@ -18,7 +18,7 @@ static PyObject *
dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value);
static PyObject *
-dict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
+dict_fromkeys(PyObject *type, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *iterable;
@@ -33,7 +33,7 @@ dict_fromkeys(PyTypeObject *type, PyObject *const *args,
Py_ssize_t nargs)
}
value = args[1];
skip_optional:
- return_value = dict_fromkeys_impl(type, iterable, value);
+ return_value = dict_fromkeys_impl((PyTypeObject *)type, iterable, value);
exit:
return return_value;
@@ -323,4 +323,4 @@ dict_values(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return dict_values_impl((PyDictObject *)self);
}
-/*[clinic end generated code: output=8a104741e4676c76 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9007b74432217017 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h
index dd29135590a6a6..4051131f480ccb 100644
--- a/Objects/clinic/floatobject.c.h
+++ b/Objects/clinic/floatobject.c.h
@@ -165,6 +165,19 @@ PyDoc_STRVAR(float_fromhex__doc__,
#define FLOAT_FROMHEX_METHODDEF \
{"fromhex", (PyCFunction)float_fromhex, METH_O|METH_CLASS,
float_fromhex__doc__},
+static PyObject *
+float_fromhex_impl(PyTypeObject *type, PyObject *string);
+
+static PyObject *
+float_fromhex(PyObject *type, PyObject *string)
+{
+ PyObject *return_value = NULL;
+
+ return_value = float_fromhex_impl((PyTypeObject *)type, string);
+
+ return return_value;
+}
+
PyDoc_STRVAR(float_as_integer_ratio__doc__,
"as_integer_ratio($self, /)\n"
"--\n"
@@ -236,6 +249,19 @@ PyDoc_STRVAR(float_from_number__doc__,
#define FLOAT_FROM_NUMBER_METHODDEF \
{"from_number", (PyCFunction)float_from_number, METH_O|METH_CLASS,
float_from_number__doc__},
+static PyObject *
+float_from_number_impl(PyTypeObject *type, PyObject *number);
+
+static PyObject *
+float_from_number(PyObject *type, PyObject *number)
+{
+ PyObject *return_value = NULL;
+
+ return_value = float_from_number_impl((PyTypeObject *)type, number);
+
+ return return_value;
+}
+
PyDoc_STRVAR(float___getnewargs____doc__,
"__getnewargs__($self, /)\n"
"--\n"
@@ -275,7 +301,7 @@ static PyObject *
float___getformat___impl(PyTypeObject *type, const char *typestr);
static PyObject *
-float___getformat__(PyTypeObject *type, PyObject *arg)
+float___getformat__(PyObject *type, PyObject *arg)
{
PyObject *return_value = NULL;
const char *typestr;
@@ -293,7 +319,7 @@ float___getformat__(PyTypeObject *type, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = float___getformat___impl(type, typestr);
+ return_value = float___getformat___impl((PyTypeObject *)type, typestr);
exit:
return return_value;
@@ -327,4 +353,4 @@ float___format__(PyObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=366cea9463cc5bf6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=927035897ea3573f input=a9049054013a1b77]*/
diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h
index c025f74af5cb58..9043ab3d516ea0 100644
--- a/Objects/clinic/longobject.c.h
+++ b/Objects/clinic/longobject.c.h
@@ -394,7 +394,7 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
PyObject *byteorder, int is_signed);
static PyObject *
-int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs,
PyObject *kwnames)
+int_from_bytes(PyObject *type, PyObject *const *args, Py_ssize_t nargs,
PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -456,7 +456,7 @@ int_from_bytes(PyTypeObject *type, PyObject *const *args,
Py_ssize_t nargs, PyOb
goto exit;
}
skip_optional_kwonly:
- return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed);
+ return_value = int_from_bytes_impl((PyTypeObject *)type, bytes_obj,
byteorder, is_signed);
exit:
return return_value;
@@ -479,4 +479,4 @@ int_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return int_is_integer_impl(self);
}
-/*[clinic end generated code: output=fb96bd642a643f75 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=591cffa2b80b5184 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h
index 3d9a94665d6fc8..b3240c7e6c4363 100644
--- a/Objects/clinic/memoryobject.c.h
+++ b/Objects/clinic/memoryobject.c.h
@@ -76,7 +76,7 @@ static PyObject *
memoryview__from_flags_impl(PyTypeObject *type, PyObject *object, int flags);
static PyObject *
-memoryview__from_flags(PyTypeObject *type, PyObject *const *args, Py_ssize_t
nargs, PyObject *kwnames)
+memoryview__from_flags(PyObject *type, PyObject *const *args, Py_ssize_t
nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -118,7 +118,7 @@ memoryview__from_flags(PyTypeObject *type, PyObject *const
*args, Py_ssize_t nar
if (flags == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = memoryview__from_flags_impl(type, object, flags);
+ return_value = memoryview__from_flags_impl((PyTypeObject *)type, object,
flags);
exit:
return return_value;
@@ -486,4 +486,4 @@ memoryview_index(PyObject *self, PyObject *const *args,
Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=c0371164b68a6839 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ae3414e9311c02fb input=a9049054013a1b77]*/
diff --git a/Objects/clinic/odictobject.c.h b/Objects/clinic/odictobject.c.h
index 44d89c4e0ef2f7..65eee376457d5a 100644
--- a/Objects/clinic/odictobject.c.h
+++ b/Objects/clinic/odictobject.c.h
@@ -21,7 +21,7 @@ static PyObject *
OrderedDict_fromkeys_impl(PyTypeObject *type, PyObject *seq, PyObject *value);
static PyObject *
-OrderedDict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t
nargs, PyObject *kwnames)
+OrderedDict_fromkeys(PyObject *type, PyObject *const *args, Py_ssize_t nargs,
PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -65,7 +65,7 @@ OrderedDict_fromkeys(PyTypeObject *type, PyObject *const
*args, Py_ssize_t nargs
}
value = args[1];
skip_optional_pos:
- return_value = OrderedDict_fromkeys_impl(type, seq, value);
+ return_value = OrderedDict_fromkeys_impl((PyTypeObject *)type, seq, value);
exit:
return return_value;
@@ -337,4 +337,4 @@ OrderedDict_move_to_end(PyObject *self, PyObject *const
*args, Py_ssize_t nargs,
exit:
return return_value;
}
-/*[clinic end generated code: output=55bd390bb516e997 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6f84d0649fcd0c1f input=a9049054013a1b77]*/
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 5d9b3c9f0e3e76..c2dd320ae73988 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -1307,8 +1307,8 @@ Convert number to a complex floating-point number.
[clinic start generated code]*/
static PyObject *
-complex_from_number(PyTypeObject *type, PyObject *number)
-/*[clinic end generated code: output=658a7a5fb0de074d input=3f8bdd3a2bc3facd]*/
+complex_from_number_impl(PyTypeObject *type, PyObject *number)
+/*[clinic end generated code: output=7248bb593e1871e1 input=3f8bdd3a2bc3facd]*/
{
if (PyComplex_CheckExact(number) && type == &PyComplex_Type) {
Py_INCREF(number);
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 309b8ddcd23839..324abddcf2a46d 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1273,8 +1273,8 @@ Create a floating-point number from a hexadecimal string.
[clinic start generated code]*/
static PyObject *
-float_fromhex(PyTypeObject *type, PyObject *string)
-/*[clinic end generated code: output=46c0274d22b78e82 input=0407bebd354bca89]*/
+float_fromhex_impl(PyTypeObject *type, PyObject *string)
+/*[clinic end generated code: output=c54b4923552e5af5 input=0407bebd354bca89]*/
{
PyObject *result;
double x;
@@ -1687,8 +1687,8 @@ Convert real number to a floating-point number.
[clinic start generated code]*/
static PyObject *
-float_from_number(PyTypeObject *type, PyObject *number)
-/*[clinic end generated code: output=bbcf05529fe907a3 input=1f8424d9bc11866a]*/
+float_from_number_impl(PyTypeObject *type, PyObject *number)
+/*[clinic end generated code: output=dda7e4466ab7068d input=1f8424d9bc11866a]*/
{
if (PyFloat_CheckExact(number) && type == &PyFloat_Type) {
Py_INCREF(number);
diff --git a/Tools/clinic/libclinic/converters.py
b/Tools/clinic/libclinic/converters.py
index 29828c08af07b1..572768190ae121 100644
--- a/Tools/clinic/libclinic/converters.py
+++ b/Tools/clinic/libclinic/converters.py
@@ -1107,7 +1107,8 @@ def parse_arg(self, argname: str, displayname: str, *,
limited_capi: bool) -> st
def correct_name_for_self(
- f: Function
+ f: Function,
+ parser: bool = False
) -> tuple[str, str]:
if f.kind in {CALLABLE, METHOD_INIT, GETTER, SETTER}:
if f.cls:
@@ -1115,7 +1116,12 @@ def correct_name_for_self(
return "PyObject *", "module"
if f.kind is STATIC_METHOD:
return "void *", "null"
- if f.kind in (CLASS_METHOD, METHOD_NEW):
+ if f.kind == CLASS_METHOD:
+ if parser:
+ return "PyObject *", "type"
+ else:
+ return "PyTypeObject *", "type"
+ if f.kind == METHOD_NEW:
return "PyTypeObject *", "type"
raise AssertionError(f"Unhandled type of function f: {f.kind!r}")
@@ -1184,7 +1190,7 @@ def pre_render(self) -> None:
@property
def parser_type(self) -> str:
assert self.type is not None
- tp, _ = correct_name_for_self(self.function)
+ tp, _ = correct_name_for_self(self.function, parser=True)
return tp
def render(self, parameter: Parameter, data: CRenderData) -> None:
@@ -1229,6 +1235,13 @@ def set_template_dict(self, template_dict: TemplateDict)
-> None:
type_ptr = f'PyTypeObject *base_tp = {type_object};'
template_dict['base_type_ptr'] = type_ptr
+ def use_pyobject_self(self, func: Function) -> bool:
+ conv_type = self.type
+ if conv_type is None:
+ conv_type, _ = correct_name_for_self(func)
+ return (conv_type in ('PyObject *', None)
+ and self.specified_type in ('PyObject *', None))
+
# Converters for var-positional parameter.
diff --git a/Tools/clinic/libclinic/parse_args.py
b/Tools/clinic/libclinic/parse_args.py
index b3fb765e31af47..3a08f37afab796 100644
--- a/Tools/clinic/libclinic/parse_args.py
+++ b/Tools/clinic/libclinic/parse_args.py
@@ -296,9 +296,7 @@ def use_simple_return(self) -> bool:
and not self.func.critical_section)
def use_pyobject_self(self) -> bool:
- pyobject_types = ('PyObject *', None)
- return (self.self_parameter_converter.type in pyobject_types
- and self.self_parameter_converter.specified_type in
pyobject_types)
+ return self.self_parameter_converter.use_pyobject_self(self.func)
def select_prototypes(self) -> None:
self.docstring_prototype = ''
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]