Skip to content

Commit edbf7fb

Browse files
authored
gh-111178: remove redundant casts for functions with correct signatures (#131673)
1 parent 8cd29c2 commit edbf7fb

30 files changed

+96
-101
lines changed

Modules/_asynciomodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,7 +2956,7 @@ static PyType_Slot Task_slots[] = {
29562956
{Py_tp_iter, future_new_iter},
29572957
{Py_tp_methods, TaskType_methods},
29582958
{Py_tp_getset, TaskType_getsetlist},
2959-
{Py_tp_init, (initproc)_asyncio_Task___init__},
2959+
{Py_tp_init, _asyncio_Task___init__},
29602960
{Py_tp_new, PyType_GenericNew},
29612961
{Py_tp_finalize, TaskObj_finalize},
29622962

@@ -4396,7 +4396,7 @@ static struct PyModuleDef _asynciomodule = {
43964396
.m_slots = module_slots,
43974397
.m_traverse = module_traverse,
43984398
.m_clear = module_clear,
4399-
.m_free = (freefunc)module_free,
4399+
.m_free = module_free,
44004400
};
44014401

44024402
PyMODINIT_FUNC

Modules/_cursesmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,7 @@ static PyMethodDef PyCursesWindow_methods[] = {
27092709
_CURSES_WINDOW_SETSCRREG_METHODDEF
27102710
{"standend", PyCursesWindow_wstandend, METH_NOARGS},
27112711
{"standout", PyCursesWindow_wstandout, METH_NOARGS},
2712-
{"subpad", (PyCFunction)_curses_window_subwin, METH_VARARGS, _curses_window_subwin__doc__},
2712+
{"subpad", _curses_window_subwin, METH_VARARGS, _curses_window_subwin__doc__},
27132713
_CURSES_WINDOW_SUBWIN_METHODDEF
27142714
{"syncdown", PyCursesWindow_wsyncdown, METH_NOARGS},
27152715
#ifdef HAVE_CURSES_SYNCOK

Modules/_functoolsmodule.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,19 +1634,19 @@ _functools__lru_cache_wrapper_cache_clear_impl(PyObject *self)
16341634
}
16351635

16361636
static PyObject *
1637-
lru_cache_reduce(PyObject *self, PyObject *unused)
1637+
lru_cache_reduce(PyObject *self, PyObject *Py_UNUSED(dummy))
16381638
{
16391639
return PyObject_GetAttrString(self, "__qualname__");
16401640
}
16411641

16421642
static PyObject *
1643-
lru_cache_copy(PyObject *self, PyObject *unused)
1643+
lru_cache_copy(PyObject *self, PyObject *Py_UNUSED(args))
16441644
{
16451645
return Py_NewRef(self);
16461646
}
16471647

16481648
static PyObject *
1649-
lru_cache_deepcopy(PyObject *self, PyObject *unused)
1649+
lru_cache_deepcopy(PyObject *self, PyObject *Py_UNUSED(args))
16501650
{
16511651
return Py_NewRef(self);
16521652
}
@@ -1693,9 +1693,9 @@ cache_info_type: namedtuple class with the fields:\n\
16931693
static PyMethodDef lru_cache_methods[] = {
16941694
_FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_INFO_METHODDEF
16951695
_FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_CLEAR_METHODDEF
1696-
{"__reduce__", (PyCFunction)lru_cache_reduce, METH_NOARGS},
1697-
{"__copy__", (PyCFunction)lru_cache_copy, METH_VARARGS},
1698-
{"__deepcopy__", (PyCFunction)lru_cache_deepcopy, METH_VARARGS},
1696+
{"__reduce__", lru_cache_reduce, METH_NOARGS},
1697+
{"__copy__", lru_cache_copy, METH_VARARGS},
1698+
{"__deepcopy__", lru_cache_deepcopy, METH_VARARGS},
16991699
{NULL}
17001700
};
17011701

Modules/_interpchannelsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3595,7 +3595,7 @@ static struct PyModuleDef moduledef = {
35953595
.m_slots = module_slots,
35963596
.m_traverse = module_traverse,
35973597
.m_clear = module_clear,
3598-
.m_free = (freefunc)module_free,
3598+
.m_free = module_free,
35993599
};
36003600

36013601
PyMODINIT_FUNC

Modules/_io/textio.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,8 +3386,6 @@ static PyMemberDef textiowrapper_members[] = {
33863386
static PyGetSetDef textiowrapper_getset[] = {
33873387
_IO_TEXTIOWRAPPER_NAME_GETSETDEF
33883388
_IO_TEXTIOWRAPPER_CLOSED_GETSETDEF
3389-
/* {"mode", (getter)TextIOWrapper_mode_get, NULL, NULL},
3390-
*/
33913389
_IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF
33923390
_IO_TEXTIOWRAPPER_ERRORS_GETSETDEF
33933391
_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF

Modules/_io/winconsoleio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ static PyMethodDef winconsoleio_methods[] = {
11951195
_IO__WINDOWSCONSOLEIO_WRITABLE_METHODDEF
11961196
_IO__WINDOWSCONSOLEIO_FILENO_METHODDEF
11971197
_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
1198-
{"_isatty_open_only", (PyCFunction)_io__WindowsConsoleIO_isatty, METH_NOARGS},
1198+
{"_isatty_open_only", _io__WindowsConsoleIO_isatty, METH_NOARGS},
11991199
{NULL, NULL} /* sentinel */
12001200
};
12011201

Modules/_lzmamodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ PyDoc_STRVAR(_lzma__encode_filter_properties__doc__,
14101410
"The result does not include the filter ID itself, only the options.");
14111411

14121412
#define _LZMA__ENCODE_FILTER_PROPERTIES_METHODDEF \
1413-
{"_encode_filter_properties", (PyCFunction)_lzma__encode_filter_properties, METH_O, _lzma__encode_filter_properties__doc__},
1413+
{"_encode_filter_properties", _lzma__encode_filter_properties, METH_O, _lzma__encode_filter_properties__doc__},
14141414

14151415
static PyObject *
14161416
_lzma__encode_filter_properties_impl(PyObject *module, lzma_filter filter);

Modules/_testcapi/docstring.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,42 @@ test_with_docstring(PyObject *self, PyObject *Py_UNUSED(ignored))
6666

6767
static PyMethodDef test_methods[] = {
6868
{"docstring_empty",
69-
(PyCFunction)test_with_docstring, METH_VARARGS,
69+
test_with_docstring, METH_VARARGS,
7070
docstring_empty},
7171
{"docstring_no_signature",
72-
(PyCFunction)test_with_docstring, METH_VARARGS,
72+
test_with_docstring, METH_VARARGS,
7373
docstring_no_signature},
7474
{"docstring_no_signature_noargs",
75-
(PyCFunction)test_with_docstring, METH_NOARGS,
75+
test_with_docstring, METH_NOARGS,
7676
docstring_no_signature},
7777
{"docstring_no_signature_o",
78-
(PyCFunction)test_with_docstring, METH_O,
78+
test_with_docstring, METH_O,
7979
docstring_no_signature},
8080
{"docstring_with_invalid_signature",
81-
(PyCFunction)test_with_docstring, METH_VARARGS,
81+
test_with_docstring, METH_VARARGS,
8282
docstring_with_invalid_signature},
8383
{"docstring_with_invalid_signature2",
84-
(PyCFunction)test_with_docstring, METH_VARARGS,
84+
test_with_docstring, METH_VARARGS,
8585
docstring_with_invalid_signature2},
8686
{"docstring_with_signature",
87-
(PyCFunction)test_with_docstring, METH_VARARGS,
87+
test_with_docstring, METH_VARARGS,
8888
docstring_with_signature},
8989
{"docstring_with_signature_and_extra_newlines",
90-
(PyCFunction)test_with_docstring, METH_VARARGS,
90+
test_with_docstring, METH_VARARGS,
9191
docstring_with_signature_and_extra_newlines},
9292
{"docstring_with_signature_but_no_doc",
93-
(PyCFunction)test_with_docstring, METH_VARARGS,
93+
test_with_docstring, METH_VARARGS,
9494
docstring_with_signature_but_no_doc},
9595
{"docstring_with_signature_with_defaults",
96-
(PyCFunction)test_with_docstring, METH_VARARGS,
96+
test_with_docstring, METH_VARARGS,
9797
docstring_with_signature_with_defaults},
9898
{"no_docstring",
99-
(PyCFunction)test_with_docstring, METH_VARARGS},
99+
test_with_docstring, METH_VARARGS},
100100
{"test_with_docstring",
101101
test_with_docstring, METH_VARARGS,
102102
PyDoc_STR("This is a pretty normal docstring.")},
103103
{"func_with_unrepresentable_signature",
104-
(PyCFunction)test_with_docstring, METH_VARARGS,
104+
test_with_docstring, METH_VARARGS,
105105
PyDoc_STR(
106106
"func_with_unrepresentable_signature($module, /, a, b=<x>)\n"
107107
"--\n\n"
@@ -112,28 +112,28 @@ static PyMethodDef test_methods[] = {
112112

113113
static PyMethodDef DocStringNoSignatureTest_methods[] = {
114114
{"meth_noargs",
115-
(PyCFunction)test_with_docstring, METH_NOARGS,
115+
test_with_docstring, METH_NOARGS,
116116
docstring_no_signature},
117117
{"meth_o",
118-
(PyCFunction)test_with_docstring, METH_O,
118+
test_with_docstring, METH_O,
119119
docstring_no_signature},
120120
{"meth_noargs_class",
121-
(PyCFunction)test_with_docstring, METH_NOARGS|METH_CLASS,
121+
test_with_docstring, METH_NOARGS|METH_CLASS,
122122
docstring_no_signature},
123123
{"meth_o_class",
124-
(PyCFunction)test_with_docstring, METH_O|METH_CLASS,
124+
test_with_docstring, METH_O|METH_CLASS,
125125
docstring_no_signature},
126126
{"meth_noargs_static",
127-
(PyCFunction)test_with_docstring, METH_NOARGS|METH_STATIC,
127+
test_with_docstring, METH_NOARGS|METH_STATIC,
128128
docstring_no_signature},
129129
{"meth_o_static",
130-
(PyCFunction)test_with_docstring, METH_O|METH_STATIC,
130+
test_with_docstring, METH_O|METH_STATIC,
131131
docstring_no_signature},
132132
{"meth_noargs_coexist",
133-
(PyCFunction)test_with_docstring, METH_NOARGS|METH_COEXIST,
133+
test_with_docstring, METH_NOARGS|METH_COEXIST,
134134
docstring_no_signature},
135135
{"meth_o_coexist",
136-
(PyCFunction)test_with_docstring, METH_O|METH_COEXIST,
136+
test_with_docstring, METH_O|METH_COEXIST,
137137
docstring_no_signature},
138138
{NULL},
139139
};
@@ -149,28 +149,28 @@ static PyTypeObject DocStringNoSignatureTest = {
149149

150150
static PyMethodDef DocStringUnrepresentableSignatureTest_methods[] = {
151151
{"meth",
152-
(PyCFunction)test_with_docstring, METH_VARARGS,
152+
test_with_docstring, METH_VARARGS,
153153
PyDoc_STR(
154154
"meth($self, /, a, b=<x>)\n"
155155
"--\n\n"
156156
"This docstring has a signature with unrepresentable default."
157157
)},
158158
{"classmeth",
159-
(PyCFunction)test_with_docstring, METH_VARARGS|METH_CLASS,
159+
test_with_docstring, METH_VARARGS|METH_CLASS,
160160
PyDoc_STR(
161161
"classmeth($type, /, a, b=<x>)\n"
162162
"--\n\n"
163163
"This docstring has a signature with unrepresentable default."
164164
)},
165165
{"staticmeth",
166-
(PyCFunction)test_with_docstring, METH_VARARGS|METH_STATIC,
166+
test_with_docstring, METH_VARARGS|METH_STATIC,
167167
PyDoc_STR(
168168
"staticmeth(a, b=<x>)\n"
169169
"--\n\n"
170170
"This docstring has a signature with unrepresentable default."
171171
)},
172172
{"with_default",
173-
(PyCFunction)test_with_docstring, METH_VARARGS,
173+
test_with_docstring, METH_VARARGS,
174174
PyDoc_STR(
175175
"with_default($self, /, x=ONE)\n"
176176
"--\n\n"

Modules/_testcapi/exceptions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static PyTypeObject PyRecursingInfinitelyError_Type = {
538538
.tp_basicsize = sizeof(PyBaseExceptionObject),
539539
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
540540
.tp_doc = PyDoc_STR("Instantiating this exception starts infinite recursion."),
541-
.tp_init = (initproc)recurse_infinitely_error_init,
541+
.tp_init = recurse_infinitely_error_init,
542542
};
543543

544544
static PyMethodDef test_methods[] = {

Modules/_testcapi/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ obj_extra_data_set(PyObject *self, PyObject *newval, void *Py_UNUSED(ignored))
265265
}
266266

267267
static PyGetSetDef obj_extra_data_getset[] = {
268-
{"extra", (getter)obj_extra_data_get, (setter)obj_extra_data_set, NULL},
268+
{"extra", obj_extra_data_get, obj_extra_data_set, NULL},
269269
{NULL}
270270
};
271271

Modules/_testcapi/mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static PyMethodDef test_methods[] = {
691691
{"pyobject_malloc_without_gil", pyobject_malloc_without_gil, METH_NOARGS},
692692
{"remove_mem_hooks", remove_mem_hooks, METH_NOARGS,
693693
PyDoc_STR("Remove memory hooks.")},
694-
{"set_nomemory", (PyCFunction)set_nomemory, METH_VARARGS,
694+
{"set_nomemory", set_nomemory, METH_VARARGS,
695695
PyDoc_STR("set_nomemory(start:int, stop:int = 0)")},
696696
{"test_pymem_alloc0", test_pymem_alloc0, METH_NOARGS},
697697
{"test_pymem_setallocators", test_pymem_setallocators, METH_NOARGS},

Modules/_testcapi/watchers.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ get_code_watcher_num_destroyed_events(PyObject *self, PyObject *watcher_id)
413413
}
414414

415415
static PyObject *
416-
allocate_too_many_code_watchers(PyObject *self, PyObject *args)
416+
allocate_too_many_code_watchers(PyObject *self, PyObject *Py_UNUSED(args))
417417
{
418418
int watcher_ids[CODE_MAX_WATCHERS + 1];
419419
int num_watchers = 0;
@@ -742,7 +742,7 @@ get_context_switches(PyObject *Py_UNUSED(self), PyObject *watcher_id)
742742
}
743743

744744
static PyObject *
745-
allocate_too_many_context_watchers(PyObject *self, PyObject *args)
745+
allocate_too_many_context_watchers(PyObject *self, PyObject *Py_UNUSED(args))
746746
{
747747
int watcher_ids[CONTEXT_MAX_WATCHERS + 1];
748748
int num_watchers = 0;
@@ -811,16 +811,15 @@ static PyMethodDef test_methods[] = {
811811
{"clear_dict_watcher", clear_dict_watcher, METH_O, NULL},
812812
_TESTCAPI_WATCH_DICT_METHODDEF
813813
_TESTCAPI_UNWATCH_DICT_METHODDEF
814-
{"get_dict_watcher_events",
815-
(PyCFunction) get_dict_watcher_events, METH_NOARGS, NULL},
814+
{"get_dict_watcher_events", get_dict_watcher_events, METH_NOARGS, NULL},
816815

817816
// Type watchers.
818817
{"add_type_watcher", add_type_watcher, METH_O, NULL},
819818
{"clear_type_watcher", clear_type_watcher, METH_O, NULL},
820819
_TESTCAPI_WATCH_TYPE_METHODDEF
821820
_TESTCAPI_UNWATCH_TYPE_METHODDEF
822821
{"get_type_modified_events",
823-
(PyCFunction) get_type_modified_events, METH_NOARGS, NULL},
822+
get_type_modified_events, METH_NOARGS, NULL},
824823

825824
// Code object watchers.
826825
{"add_code_watcher", add_code_watcher, METH_O, NULL},
@@ -830,7 +829,7 @@ static PyMethodDef test_methods[] = {
830829
{"get_code_watcher_num_destroyed_events",
831830
get_code_watcher_num_destroyed_events, METH_O, NULL},
832831
{"allocate_too_many_code_watchers",
833-
(PyCFunction) allocate_too_many_code_watchers, METH_NOARGS, NULL},
832+
allocate_too_many_code_watchers, METH_NOARGS, NULL},
834833

835834
// Function watchers.
836835
{"add_func_watcher", add_func_watcher, METH_O, NULL},
@@ -846,7 +845,7 @@ static PyMethodDef test_methods[] = {
846845
{"clear_context_stack", clear_context_stack, METH_NOARGS, NULL},
847846
{"get_context_switches", get_context_switches, METH_O, NULL},
848847
{"allocate_too_many_context_watchers",
849-
(PyCFunction) allocate_too_many_context_watchers, METH_NOARGS, NULL},
848+
allocate_too_many_context_watchers, METH_NOARGS, NULL},
850849
{NULL},
851850
};
852851

Modules/_testinternalcapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,7 @@ static struct PyModuleDef _testcapimodule = {
22122212
.m_slots = module_slots,
22132213
.m_traverse = module_traverse,
22142214
.m_clear = module_clear,
2215-
.m_free = (freefunc)module_free,
2215+
.m_free = module_free,
22162216
};
22172217

22182218

Modules/_xxtestfuzz/_xxtestfuzz.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static PyObject* _fuzz_run(PyObject* self, PyObject* args) {
2424
}
2525

2626
static PyMethodDef module_methods[] = {
27-
{"run", (PyCFunction)_fuzz_run, METH_VARARGS, ""},
27+
{"run", _fuzz_run, METH_VARARGS, ""},
2828
{NULL},
2929
};
3030

Modules/_zoneinfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,10 +2605,10 @@ static PyMethodDef zoneinfo_methods[] = {
26052605
ZONEINFO_ZONEINFO_UTCOFFSET_METHODDEF
26062606
ZONEINFO_ZONEINFO_DST_METHODDEF
26072607
ZONEINFO_ZONEINFO_TZNAME_METHODDEF
2608-
{"fromutc", (PyCFunction)zoneinfo_fromutc, METH_O,
2608+
{"fromutc", zoneinfo_fromutc, METH_O,
26092609
PyDoc_STR("Given a datetime with local time in UTC, retrieve an adjusted "
26102610
"datetime in local time.")},
2611-
{"__reduce__", (PyCFunction)zoneinfo_reduce, METH_NOARGS,
2611+
{"__reduce__", zoneinfo_reduce, METH_NOARGS,
26122612
PyDoc_STR("Function for serialization with the pickle protocol.")},
26132613
ZONEINFO_ZONEINFO__UNPICKLE_METHODDEF
26142614
{"__init_subclass__", _PyCFunction_CAST(zoneinfo_init_subclass),

Modules/atexitmodule.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Run all registered exit functions.\n\
217217
If a callback raises an exception, it is logged with sys.unraisablehook.");
218218

219219
static PyObject *
220-
atexit_run_exitfuncs(PyObject *module, PyObject *unused)
220+
atexit_run_exitfuncs(PyObject *module, PyObject *Py_UNUSED(dummy))
221221
{
222222
struct atexit_state *state = get_atexit_state();
223223
atexit_callfuncs(state);
@@ -231,7 +231,7 @@ PyDoc_STRVAR(atexit_clear__doc__,
231231
Clear the list of previously registered exit functions.");
232232

233233
static PyObject *
234-
atexit_clear(PyObject *module, PyObject *unused)
234+
atexit_clear(PyObject *module, PyObject *Py_UNUSED(dummy))
235235
{
236236
atexit_cleanup(get_atexit_state());
237237
Py_RETURN_NONE;
@@ -244,7 +244,7 @@ PyDoc_STRVAR(atexit_ncallbacks__doc__,
244244
Return the number of registered exit functions.");
245245

246246
static PyObject *
247-
atexit_ncallbacks(PyObject *module, PyObject *unused)
247+
atexit_ncallbacks(PyObject *module, PyObject *Py_UNUSED(dummy))
248248
{
249249
struct atexit_state *state = get_atexit_state();
250250
assert(state->callbacks != NULL);
@@ -300,13 +300,11 @@ atexit_unregister(PyObject *module, PyObject *func)
300300
static PyMethodDef atexit_methods[] = {
301301
{"register", _PyCFunction_CAST(atexit_register), METH_VARARGS|METH_KEYWORDS,
302302
atexit_register__doc__},
303-
{"_clear", (PyCFunction) atexit_clear, METH_NOARGS,
304-
atexit_clear__doc__},
305-
{"unregister", (PyCFunction) atexit_unregister, METH_O,
306-
atexit_unregister__doc__},
307-
{"_run_exitfuncs", (PyCFunction) atexit_run_exitfuncs, METH_NOARGS,
303+
{"_clear", atexit_clear, METH_NOARGS, atexit_clear__doc__},
304+
{"unregister", atexit_unregister, METH_O, atexit_unregister__doc__},
305+
{"_run_exitfuncs", atexit_run_exitfuncs, METH_NOARGS,
308306
atexit_run_exitfuncs__doc__},
309-
{"_ncallbacks", (PyCFunction) atexit_ncallbacks, METH_NOARGS,
307+
{"_ncallbacks", atexit_ncallbacks, METH_NOARGS,
310308
atexit_ncallbacks__doc__},
311309
{NULL, NULL} /* sentinel */
312310
};

Modules/cjkcodecs/cjkcodecs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ _cjk_free(void *mod)
495495
}
496496

497497
static struct PyMethodDef _cjk_methods[] = {
498-
{"getcodec", (PyCFunction)getcodec, METH_O, ""},
498+
{"getcodec", getcodec, METH_O, ""},
499499
{NULL, NULL},
500500
};
501501

0 commit comments

Comments
 (0)