bpo-31222: Make (datetime|date|time).replace return subclass type in … · python/cpython@191e993

@@ -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)

832832833833

# 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)

1320132013211321

# 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)

1602160216031603

def _local_timezone(self):