Skip to content

Commit f25f2e2

Browse files
authoredSep 19, 2021
Clean up initialization __class_getitem__ with Py_GenericAlias. (pythonGH-28450)
The cast to PyCFunction is redundant. Overuse of redundant casts can hide actual bugs.
1 parent a624177 commit f25f2e2

17 files changed

+21
-21
lines changed
 

‎Doc/c-api/typehints.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ two types exist -- :ref:`GenericAlias <types-genericalias>` and
3131
static PyMethodDef my_obj_methods[] = {
3232
// Other methods.
3333
...
34-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, "See PEP 585"}
34+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, "See PEP 585"}
3535
...
3636
}
3737

‎Modules/_collectionsmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ static PyMethodDef deque_methods[] = {
16361636
METH_FASTCALL, rotate_doc},
16371637
{"__sizeof__", (PyCFunction)deque_sizeof,
16381638
METH_NOARGS, sizeof_doc},
1639-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
1639+
{"__class_getitem__", Py_GenericAlias,
16401640
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
16411641
{NULL, NULL} /* sentinel */
16421642
};
@@ -2104,7 +2104,7 @@ static PyMethodDef defdict_methods[] = {
21042104
defdict_copy_doc},
21052105
{"__reduce__", (PyCFunction)defdict_reduce, METH_NOARGS,
21062106
reduce_doc},
2107-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS,
2107+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
21082108
PyDoc_STR("See PEP 585")},
21092109
{NULL}
21102110
};

‎Modules/_ctypes/_ctypes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4795,7 +4795,7 @@ Array_length(PyObject *myself)
47954795
}
47964796

47974797
static PyMethodDef Array_methods[] = {
4798-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
4798+
{"__class_getitem__", Py_GenericAlias,
47994799
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
48004800
{ NULL, NULL }
48014801
};

‎Modules/_functoolsmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ partial_setstate(partialobject *pto, PyObject *state)
465465
static PyMethodDef partial_methods[] = {
466466
{"__reduce__", (PyCFunction)partial_reduce, METH_NOARGS},
467467
{"__setstate__", (PyCFunction)partial_setstate, METH_O},
468-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
468+
{"__class_getitem__", Py_GenericAlias,
469469
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
470470
{NULL, NULL} /* sentinel */
471471
};

‎Modules/_queuemodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static PyMethodDef simplequeue_methods[] = {
356356
_QUEUE_SIMPLEQUEUE_PUT_METHODDEF
357357
_QUEUE_SIMPLEQUEUE_PUT_NOWAIT_METHODDEF
358358
_QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF
359-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
359+
{"__class_getitem__", Py_GenericAlias,
360360
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
361361
{NULL, NULL} /* sentinel */
362362
};

‎Modules/_sre.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,7 @@ static PyMethodDef pattern_methods[] = {
27082708
_SRE_SRE_PATTERN_SCANNER_METHODDEF
27092709
_SRE_SRE_PATTERN___COPY___METHODDEF
27102710
_SRE_SRE_PATTERN___DEEPCOPY___METHODDEF
2711-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS,
2711+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
27122712
PyDoc_STR("See PEP 585")},
27132713
{NULL, NULL}
27142714
};
@@ -2764,7 +2764,7 @@ static PyMethodDef match_methods[] = {
27642764
_SRE_SRE_MATCH_EXPAND_METHODDEF
27652765
_SRE_SRE_MATCH___COPY___METHODDEF
27662766
_SRE_SRE_MATCH___DEEPCOPY___METHODDEF
2767-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS,
2767+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
27682768
PyDoc_STR("See PEP 585")},
27692769
{NULL, NULL}
27702770
};

‎Modules/itertoolsmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ static PyMethodDef chain_methods[] = {
21652165
reduce_doc},
21662166
{"__setstate__", (PyCFunction)chain_setstate, METH_O,
21672167
setstate_doc},
2168-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
2168+
{"__class_getitem__", Py_GenericAlias,
21692169
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
21702170
{NULL, NULL} /* sentinel */
21712171
};

‎Modules/posixmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -13779,7 +13779,7 @@ static PyMethodDef DirEntry_methods[] = {
1377913779
OS_DIRENTRY_STAT_METHODDEF
1378013780
OS_DIRENTRY_INODE_METHODDEF
1378113781
OS_DIRENTRY___FSPATH___METHODDEF
13782-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
13782+
{"__class_getitem__", Py_GenericAlias,
1378313783
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
1378413784
{NULL}
1378513785
};

‎Objects/descrobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ static PyMethodDef mappingproxy_methods[] = {
11441144
PyDoc_STR("D.items() -> list of D's (key, value) pairs, as 2-tuples")},
11451145
{"copy", (PyCFunction)mappingproxy_copy, METH_NOARGS,
11461146
PyDoc_STR("D.copy() -> a shallow copy of D")},
1147-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS,
1147+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
11481148
PyDoc_STR("See PEP 585")},
11491149
{"__reversed__", (PyCFunction)mappingproxy_reversed, METH_NOARGS,
11501150
PyDoc_STR("D.__reversed__() -> reverse iterator")},

‎Objects/dictobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3294,7 +3294,7 @@ static PyMethodDef mapp_methods[] = {
32943294
{"copy", (PyCFunction)dict_copy, METH_NOARGS,
32953295
copy__doc__},
32963296
DICT___REVERSED___METHODDEF
3297-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
3297+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
32983298
{NULL, NULL} /* sentinel */
32993299
};
33003300

‎Objects/enumobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
213213

214214
static PyMethodDef enum_methods[] = {
215215
{"__reduce__", (PyCFunction)enum_reduce, METH_NOARGS, reduce_doc},
216-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
216+
{"__class_getitem__", Py_GenericAlias,
217217
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
218218
{NULL, NULL} /* sentinel */
219219
};

‎Objects/genobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ static PyMethodDef async_gen_methods[] = {
14991499
{"asend", (PyCFunction)async_gen_asend, METH_O, async_asend_doc},
15001500
{"athrow",(PyCFunction)async_gen_athrow, METH_VARARGS, async_athrow_doc},
15011501
{"aclose", (PyCFunction)async_gen_aclose, METH_NOARGS, async_aclose_doc},
1502-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
1502+
{"__class_getitem__", Py_GenericAlias,
15031503
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
15041504
{NULL, NULL} /* Sentinel */
15051505
};

‎Objects/listobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2843,7 +2843,7 @@ static PyMethodDef list_methods[] = {
28432843
LIST_COUNT_METHODDEF
28442844
LIST_REVERSE_METHODDEF
28452845
LIST_SORT_METHODDEF
2846-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
2846+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
28472847
{NULL, NULL} /* sentinel */
28482848
};
28492849

‎Objects/setobject.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ static PyMethodDef set_methods[] = {
20472047
union_doc},
20482048
{"update", (PyCFunction)set_update, METH_VARARGS,
20492049
update_doc},
2050-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
2050+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
20512051
{NULL, NULL} /* sentinel */
20522052
};
20532053

@@ -2161,7 +2161,7 @@ static PyMethodDef frozenset_methods[] = {
21612161
symmetric_difference_doc},
21622162
{"union", (PyCFunction)set_union, METH_VARARGS,
21632163
union_doc},
2164-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
2164+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
21652165
{NULL, NULL} /* sentinel */
21662166
};
21672167

‎Objects/tupleobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ static PyMethodDef tuple_methods[] = {
887887
TUPLE___GETNEWARGS___METHODDEF
888888
TUPLE_INDEX_METHODDEF
889889
TUPLE_COUNT_METHODDEF
890-
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
890+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
891891
{NULL, NULL} /* sentinel */
892892
};
893893

‎Objects/weakrefobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ static PyMemberDef weakref_members[] = {
363363
};
364364

365365
static PyMethodDef weakref_methods[] = {
366-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
366+
{"__class_getitem__", Py_GenericAlias,
367367
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
368368
{NULL} /* Sentinel */
369369
};

‎Python/context.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ static PyMethodDef PyContextVar_methods[] = {
10491049
_CONTEXTVARS_CONTEXTVAR_GET_METHODDEF
10501050
_CONTEXTVARS_CONTEXTVAR_SET_METHODDEF
10511051
_CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF
1052-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
1052+
{"__class_getitem__", Py_GenericAlias,
10531053
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
10541054
{NULL, NULL}
10551055
};
@@ -1190,7 +1190,7 @@ static PyGetSetDef PyContextTokenType_getsetlist[] = {
11901190
};
11911191

11921192
static PyMethodDef PyContextTokenType_methods[] = {
1193-
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
1193+
{"__class_getitem__", Py_GenericAlias,
11941194
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
11951195
{NULL}
11961196
};

0 commit comments

Comments
 (0)