diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-09-06 20:55:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-06 20:55:42 (GMT) |
commit | 6f3c138dfa868b32d3288898923bbfa388f2fa5d (patch) | |
tree | 98098db4d0d2f256f2a17d515c1750a28424166c /Modules/_datetimemodule.c | |
parent | 9f0c0a46f00d687e921990ee83894b2f4ce8a6e7 (diff) | |
download | cpython-6f3c138dfa868b32d3288898923bbfa388f2fa5d.zip cpython-6f3c138dfa868b32d3288898923bbfa388f2fa5d.tar.gz cpython-6f3c138dfa868b32d3288898923bbfa388f2fa5d.tar.bz2 |
gh-108751: Add copy.replace() function (GH-108752)
It creates a modified copy of an object by calling the object's
__replace__() method.
It is a generalization of dataclasses.replace(), named tuple's _replace()
method and replace() methods in various classes, and supports all these
stdlib classes.
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r-- | Modules/_datetimemodule.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 191db3f..0d35677 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -3590,6 +3590,8 @@ static PyMethodDef date_methods[] = { {"replace", _PyCFunction_CAST(date_replace), METH_VARARGS | METH_KEYWORDS, PyDoc_STR("Return date with new specified fields.")}, + {"__replace__", _PyCFunction_CAST(date_replace), METH_VARARGS | METH_KEYWORDS}, + {"__reduce__", (PyCFunction)date_reduce, METH_NOARGS, PyDoc_STR("__reduce__() -> (cls, state)")}, @@ -4719,6 +4721,8 @@ static PyMethodDef time_methods[] = { {"replace", _PyCFunction_CAST(time_replace), METH_VARARGS | METH_KEYWORDS, PyDoc_STR("Return time with new specified fields.")}, + {"__replace__", _PyCFunction_CAST(time_replace), METH_VARARGS | METH_KEYWORDS}, + {"fromisoformat", (PyCFunction)time_fromisoformat, METH_O | METH_CLASS, PyDoc_STR("string -> time from a string in ISO 8601 format")}, @@ -6579,6 +6583,8 @@ static PyMethodDef datetime_methods[] = { {"replace", _PyCFunction_CAST(datetime_replace), METH_VARARGS | METH_KEYWORDS, PyDoc_STR("Return datetime with new specified fields.")}, + {"__replace__", _PyCFunction_CAST(datetime_replace), METH_VARARGS | METH_KEYWORDS}, + {"astimezone", _PyCFunction_CAST(datetime_astimezone), METH_VARARGS | METH_KEYWORDS, PyDoc_STR("tz -> convert to local time in new timezone tz\n")}, |