Skip to content

Commit dea1eaf

Browse files
committed
Bring pure Python (datetime|date|time).replace behavior in line with C
1 parent 511e2f1 commit dea1eaf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Lib/datetime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ def replace(self, year=None, month=None, day=None):
828828
month = self._month
829829
if day is None:
830830
day = self._day
831-
return date(year, month, day)
831+
return type(self)(year, month, day)
832832

833833
# Comparisons of date objects with other.
834834

@@ -1316,7 +1316,7 @@ def replace(self, hour=None, minute=None, second=None, microsecond=None,
13161316
tzinfo = self.tzinfo
13171317
if fold is None:
13181318
fold = self._fold
1319-
return time(hour, minute, second, microsecond, tzinfo, fold=fold)
1319+
return type(self)(hour, minute, second, microsecond, tzinfo, fold=fold)
13201320

13211321
# Pickle support.
13221322

@@ -1597,7 +1597,7 @@ def replace(self, year=None, month=None, day=None, hour=None,
15971597
tzinfo = self.tzinfo
15981598
if fold is None:
15991599
fold = self.fold
1600-
return datetime(year, month, day, hour, minute, second,
1600+
return type(self)(year, month, day, hour, minute, second,
16011601
microsecond, tzinfo, fold=fold)
16021602

16031603
def _local_timezone(self):

0 commit comments

Comments
 (0)