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 /Lib/_pydatetime.py | |
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 'Lib/_pydatetime.py')
-rw-r--r-- | Lib/_pydatetime.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py index 549fcda..df616bb 100644 --- a/Lib/_pydatetime.py +++ b/Lib/_pydatetime.py @@ -1112,6 +1112,8 @@ class date: day = self._day return type(self)(year, month, day) + __replace__ = replace + # Comparisons of date objects with other. def __eq__(self, other): @@ -1637,6 +1639,8 @@ class time: fold = self._fold return type(self)(hour, minute, second, microsecond, tzinfo, fold=fold) + __replace__ = replace + # Pickle support. def _getstate(self, protocol=3): @@ -1983,6 +1987,8 @@ class datetime(date): return type(self)(year, month, day, hour, minute, second, microsecond, tzinfo, fold=fold) + __replace__ = replace + def _local_timezone(self): if self.tzinfo is None: ts = self._mktime() |