]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111178: Change Argument Clinic signature for `@classmethod` (#131157)
authorVictor Stinner <vstinner@python.org>
Wed, 12 Mar 2025 16:42:07 +0000 (17:42 +0100)
committerGitHub <noreply@github.com>
Wed, 12 Mar 2025 16:42:07 +0000 (17:42 +0100)
Use "PyObject*", instead of "PyTypeObject*", for `@classmethod`
functions to fix an undefined behavior.

22 files changed:
Lib/test/clinic.test.c
Modules/_datetimemodule.c
Modules/_multiprocessing/clinic/semaphore.c.h
Modules/clinic/_datetimemodule.c.h
Modules/clinic/_zoneinfo.c.h
Modules/clinic/itertoolsmodule.c.h
Modules/clinic/selectmodule.c.h
Modules/itertoolsmodule.c
Objects/bytearrayobject.c
Objects/bytesobject.c
Objects/clinic/bytearrayobject.c.h
Objects/clinic/bytesobject.c.h
Objects/clinic/complexobject.c.h
Objects/clinic/dictobject.c.h
Objects/clinic/floatobject.c.h
Objects/clinic/longobject.c.h
Objects/clinic/memoryobject.c.h
Objects/clinic/odictobject.c.h
Objects/complexobject.c
Objects/floatobject.c
Tools/clinic/libclinic/converters.py
Tools/clinic/libclinic/parse_args.py

index 2f843371ff9d7c83a8017b1ed7539a577797c054..6833005177122287c814f1b090d990a06784b966 100644 (file)
@@ -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]
index 07d7089be09d2058facd29deb881e1de8ccc97e0..83b92fe606984c8063ffca9efb2b4a4f65b522b7 100644 (file)
@@ -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);
 }
index e789137ec1e013cde8eb8568b016d56c66af3edc..74a9daa3c67ad210c3f8754c50bf6499036354f4 100644 (file)
@@ -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 @@ exit:
 #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]*/
index 8f33c9e7d4eae5f96b16807ae598858589f7ac84..d200c9cfd1888be5622fab3e733ee0ec24edd70d 100644 (file)
@@ -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 @@ skip_optional_kwonly:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=8acf62fbc7328f79 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7b55f2d9a4596b58 input=a9049054013a1b77]*/
index dd72b5e663aea6e4d20428739622be1023606c91..52ea3368ab12c7e016762c037fc8962a993b9e64 100644 (file)
@@ -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]*/
index ea0cc495ffb969b2bb167bde47d3df5cf0410306..401c87e846f501e963ea973a75310eb7dfd626fe 100644 (file)
@@ -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 @@ skip_optional_pos:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=199eeac2d17e8f23 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=688855b1dc77bf5a input=a9049054013a1b77]*/
index d8bdd6f95f3d29aa811dc0c426b043a2c0032dc1..8ee291dcca8b165688638d17aebe9e1d4f22d39a 100644 (file)
@@ -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 @@ exit:
 #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]*/
index 40e436a6717ba7f4198ccda6b296dc1ea983d359..9c9a965ce74feb548d31d66926f8aba85e47bac6 100644 (file)
@@ -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;
 
index f1c76664198abc957050c172616b524d66462c78..8f2d2dd02151c14e0646eb58662d082d660e5c78 100644 (file)
@@ -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) {
index ada0d0024827dc7661a0dbbf940788739c271a01..1615571035853c4cd2d52b95b260b5fb9353b415 100644 (file)
@@ -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) {
index 8ed10d8ab5a8b215af18917664a53a943e0d5327..5f41c53a365534de1d8f004ab1f0c6b831c6ea67 100644 (file)
@@ -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]*/
index c0f61f1368ba2b8015df989d8b5865aef432b2f8..d50daeffd74ed2d2b0f768c7c6005a709e45fbea 100644 (file)
@@ -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 @@ skip_optional_pos:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=967aae4b46423586 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=60d6a9f1333b76f0 input=a9049054013a1b77]*/
index e00da1d960c54ddb62b02a0c75fe9c6a77738507..2988664317eedea2ae6360009023887b81f39e70 100644 (file)
@@ -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]*/
index 36da98f7477d595cf88f85445535319d4295274e..abf6b38449fcb0db572da6cc466ce7d609704898 100644 (file)
@@ -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]*/
index dd29135590a6a67cc03e27cebd5acea8ed056fc6..4051131f480ccb604e3ba156b30588809fb1f46a 100644 (file)
@@ -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]*/
index c025f74af5cb58366b51eeb9e094c1d38ce25f2b..9043ab3d516ea048f985003b0faec3a6e7bcbe53 100644 (file)
@@ -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 @@ skip_optional_pos:
         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]*/
index 3d9a94665d6fc8b68fe2ffc34440b96ffcc8c473..b3240c7e6c43633b97ffbf5f5d3e0278121e8b0b 100644 (file)
@@ -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 @@ skip_optional:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=c0371164b68a6839 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ae3414e9311c02fb input=a9049054013a1b77]*/
index 44d89c4e0ef2f7332890bdf2060570266cf005e0..65eee376457d5a945cf65109cc4cf6426f427c05 100644 (file)
@@ -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 @@ skip_optional_pos:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=55bd390bb516e997 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6f84d0649fcd0c1f input=a9049054013a1b77]*/
index 5d9b3c9f0e3e7638e484bb43d9f8163733695323..c2dd320ae73988f5681046fc84a16961a2609821 100644 (file)
@@ -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);
index 309b8ddcd23839dcb1dd6de4e589754049dc29a1..324abddcf2a46d465cbbf055edc030bf766fa451 100644 (file)
@@ -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);
index 29828c08af07b1996d34cfd67c2d74e7b89e2977..572768190ae121233dfcc6a8812414dcc0886de5 100644 (file)
@@ -1107,7 +1107,8 @@ class Py_buffer_converter(CConverter):
 
 
 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 @@ class self_converter(CConverter):
     @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 @@ class self_converter(CConverter):
             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.
 
index b3fb765e31af47af26eb5c53bec3f44080b96882..3a08f37afab796588c4bb116a541c796a96d2642 100644 (file)
@@ -296,9 +296,7 @@ class ParseArgsCodeGen:
                 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 = ''