Skip to content

Commit 6e05537

Browse files
gh-117764: Add docstrings and signatures for the __replace__ methods (GH-117768)
1 parent deb921f commit 6e05537

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

Modules/_datetimemodule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3645,7 +3645,8 @@ 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\nThe same as replace().")},
36493650

36503651
{"__reduce__", (PyCFunction)date_reduce, METH_NOARGS,
36513652
PyDoc_STR("__reduce__() -> (cls, state)")},
@@ -4772,7 +4773,8 @@ static PyMethodDef time_methods[] = {
47724773

47734774
DATETIME_TIME_REPLACE_METHODDEF
47744775

4775-
{"__replace__", _PyCFunction_CAST(datetime_time_replace), METH_FASTCALL | METH_KEYWORDS},
4776+
{"__replace__", _PyCFunction_CAST(datetime_time_replace), METH_FASTCALL | METH_KEYWORDS,
4777+
PyDoc_STR("__replace__($self, /, **changes)\n--\n\nThe same as replace().")},
47764778

47774779
{"fromisoformat", (PyCFunction)time_fromisoformat, METH_O | METH_CLASS,
47784780
PyDoc_STR("string -> time from a string in ISO 8601 format")},
@@ -6619,7 +6621,8 @@ static PyMethodDef datetime_methods[] = {
66196621

66206622
DATETIME_DATETIME_REPLACE_METHODDEF
66216623

6622-
{"__replace__", _PyCFunction_CAST(datetime_datetime_replace), METH_FASTCALL | METH_KEYWORDS},
6624+
{"__replace__", _PyCFunction_CAST(datetime_datetime_replace), METH_FASTCALL | METH_KEYWORDS,
6625+
PyDoc_STR("__replace__($self, /, **changes)\n--\n\nThe same as replace().")},
66236626

66246627
{"astimezone", _PyCFunction_CAST(datetime_astimezone), METH_VARARGS | METH_KEYWORDS,
66256628
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)