Skip to content

Commit ce37187

Browse files
pythongh-117764: Add docstrings and signatures for the __replace__ methods
1 parent a2ae847 commit ce37187

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎Modules/_datetimemodule.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3645,7 +3645,9 @@ static PyMethodDef date_methods[] = {
36453645

36463646
DATETIME_DATE_REPLACE_METHODDEF
36473647

3648-
{"__replace__", _PyCFunction_CAST(datetime_date_replace), METH_FASTCALL | METH_KEYWORDS},
3648+
{"__replace__", _PyCFunction_CAST(datetime_date_replace), METH_FASTCALL | METH_KEYWORDS,
3649+
PyDoc_STR("__replace__($self, **changes)\n--\n\n"
3650+
"Return a copy of the date object with new values for the specified fields.")},
36493651

36503652
{"__reduce__", (PyCFunction)date_reduce, METH_NOARGS,
36513653
PyDoc_STR("__reduce__() -> (cls, state)")},
@@ -4772,7 +4774,9 @@ static PyMethodDef time_methods[] = {
47724774

47734775
DATETIME_TIME_REPLACE_METHODDEF
47744776

4775-
{"__replace__", _PyCFunction_CAST(datetime_time_replace), METH_FASTCALL | METH_KEYWORDS},
4777+
{"__replace__", _PyCFunction_CAST(datetime_time_replace), METH_FASTCALL | METH_KEYWORDS,
4778+
PyDoc_STR("__replace__($self, **changes)\n--\n\n"
4779+
"Return a copy of the time object with new values for the specified fields.")},
47764780

47774781
{"fromisoformat", (PyCFunction)time_fromisoformat, METH_O | METH_CLASS,
47784782
PyDoc_STR("string -> time from a string in ISO 8601 format")},
@@ -6619,7 +6623,9 @@ static PyMethodDef datetime_methods[] = {
66196623

66206624
DATETIME_DATETIME_REPLACE_METHODDEF
66216625

6622-
{"__replace__", _PyCFunction_CAST(datetime_datetime_replace), METH_FASTCALL | METH_KEYWORDS},
6626+
{"__replace__", _PyCFunction_CAST(datetime_datetime_replace), METH_FASTCALL | METH_KEYWORDS,
6627+
PyDoc_STR("__replace__($self, **changes)\n--\n\n"
6628+
"Return a copy of the datetime object with new values for the specified fields.")},
66236629

66246630
{"astimezone", _PyCFunction_CAST(datetime_astimezone), METH_VARARGS | METH_KEYWORDS,
66256631
PyDoc_STR("tz -> convert to local time in new timezone tz\n")},

‎Objects/codeobject.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,8 @@ static struct PyMethodDef code_methods[] = {
21702170
{"co_positions", (PyCFunction)code_positionsiterator, METH_NOARGS},
21712171
CODE_REPLACE_METHODDEF
21722172
CODE__VARNAME_FROM_OPARG_METHODDEF
2173-
{"__replace__", _PyCFunction_CAST(code_replace), METH_FASTCALL|METH_KEYWORDS},
2173+
{"__replace__", _PyCFunction_CAST(code_replace), METH_FASTCALL|METH_KEYWORDS,
2174+
PyDoc_STR("__replace__($self, /, **changes)\n--\n\nThe same as replace().")},
21742175
{NULL, NULL} /* sentinel */
21752176
};
21762177

‎Objects/namespaceobject.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ namespace_replace(PyObject *self, PyObject *args, PyObject *kwargs)
219219
static PyMethodDef namespace_methods[] = {
220220
{"__reduce__", (PyCFunction)namespace_reduce, METH_NOARGS,
221221
namespace_reduce__doc__},
222-
{"__replace__", _PyCFunction_CAST(namespace_replace), METH_VARARGS|METH_KEYWORDS, NULL},
222+
{"__replace__", _PyCFunction_CAST(namespace_replace), METH_VARARGS|METH_KEYWORDS,
223+
PyDoc_STR("__replace__($self, **changes)\n--\n\n"
224+
"Return a copy of the namespace object with new values for the specified attributes.")},
223225
{NULL, NULL} // sentinel
224226
};
225227

‎Objects/structseq.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ structseq_replace(PyStructSequence *self, PyObject *args, PyObject *kwargs)
453453

454454
static PyMethodDef structseq_methods[] = {
455455
{"__reduce__", (PyCFunction)structseq_reduce, METH_NOARGS, NULL},
456-
{"__replace__", _PyCFunction_CAST(structseq_replace), METH_VARARGS | METH_KEYWORDS, NULL},
456+
{"__replace__", _PyCFunction_CAST(structseq_replace), METH_VARARGS | METH_KEYWORDS,
457+
PyDoc_STR("__replace__($self, **changes)\n--\n\n"
458+
"Return a copy of the structure with new values for the specified fields.")},
457459
{NULL, NULL} // sentinel
458460
};
459461

0 commit comments

Comments
 (0)