Skip to content

Commit a363675

Browse files
gh-132457: make staticmethod and classmethod generic (#132460)
Co-authored-by: sobolevn <[email protected]>
1 parent c8f233c commit a363675

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Lib/test/test_genericalias.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ class BaseTest(unittest.TestCase):
137137
Future, _WorkItem,
138138
Morsel,
139139
DictReader, DictWriter,
140-
array]
140+
array,
141+
staticmethod,
142+
classmethod]
141143
if ctypes is not None:
142144
generic_types.extend((ctypes.Array, ctypes.LibraryLoader, ctypes.py_object))
143145
if ValueProxy is not None:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make :func:`staticmethod` and :func:`classmethod` generic.

Objects/funcobject.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,11 @@ static PyGetSetDef cm_getsetlist[] = {
14841484
{NULL} /* Sentinel */
14851485
};
14861486

1487+
static PyMethodDef cm_methodlist[] = {
1488+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, NULL},
1489+
{NULL} /* Sentinel */
1490+
};
1491+
14871492
static PyObject*
14881493
cm_repr(PyObject *self)
14891494
{
@@ -1542,7 +1547,7 @@ PyTypeObject PyClassMethod_Type = {
15421547
0, /* tp_weaklistoffset */
15431548
0, /* tp_iter */
15441549
0, /* tp_iternext */
1545-
0, /* tp_methods */
1550+
cm_methodlist, /* tp_methods */
15461551
cm_memberlist, /* tp_members */
15471552
cm_getsetlist, /* tp_getset */
15481553
0, /* tp_base */
@@ -1716,6 +1721,11 @@ static PyGetSetDef sm_getsetlist[] = {
17161721
{NULL} /* Sentinel */
17171722
};
17181723

1724+
static PyMethodDef sm_methodlist[] = {
1725+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, NULL},
1726+
{NULL} /* Sentinel */
1727+
};
1728+
17191729
static PyObject*
17201730
sm_repr(PyObject *self)
17211731
{
@@ -1772,7 +1782,7 @@ PyTypeObject PyStaticMethod_Type = {
17721782
0, /* tp_weaklistoffset */
17731783
0, /* tp_iter */
17741784
0, /* tp_iternext */
1775-
0, /* tp_methods */
1785+
sm_methodlist, /* tp_methods */
17761786
sm_memberlist, /* tp_members */
17771787
sm_getsetlist, /* tp_getset */
17781788
0, /* tp_base */

0 commit comments

Comments
 (0)