diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index 5c13897b8d9d4f..8d21ded45014ba 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -137,7 +137,9 @@ class BaseTest(unittest.TestCase): Future, _WorkItem, Morsel, DictReader, DictWriter, - array] + array, + staticmethod, + classmethod] if ctypes is not None: generic_types.extend((ctypes.Array, ctypes.LibraryLoader, ctypes.py_object)) if ValueProxy is not None: diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-04-13-01-50-40.gh-issue-132457.1q-1xz.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-13-01-50-40.gh-issue-132457.1q-1xz.rst new file mode 100644 index 00000000000000..5249ff8ef2dc16 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-13-01-50-40.gh-issue-132457.1q-1xz.rst @@ -0,0 +1 @@ +Make :func:`staticmethod` and :func:`classmethod` generic. diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 6d71dbb5a6affd..56df5730db0c55 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -1484,6 +1484,11 @@ static PyGetSetDef cm_getsetlist[] = { {NULL} /* Sentinel */ }; +static PyMethodDef cm_methodlist[] = { + {"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, NULL}, + {NULL} /* Sentinel */ +}; + static PyObject* cm_repr(PyObject *self) { @@ -1542,7 +1547,7 @@ PyTypeObject PyClassMethod_Type = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + cm_methodlist, /* tp_methods */ cm_memberlist, /* tp_members */ cm_getsetlist, /* tp_getset */ 0, /* tp_base */ @@ -1716,6 +1721,11 @@ static PyGetSetDef sm_getsetlist[] = { {NULL} /* Sentinel */ }; +static PyMethodDef sm_methodlist[] = { + {"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, NULL}, + {NULL} /* Sentinel */ +}; + static PyObject* sm_repr(PyObject *self) { @@ -1772,7 +1782,7 @@ PyTypeObject PyStaticMethod_Type = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + sm_methodlist, /* tp_methods */ sm_memberlist, /* tp_members */ sm_getsetlist, /* tp_getset */ 0, /* tp_base */