Skip to content

Commit 0a18ea5

Browse files
Clarify datetime replace documentation
In #115684, HopedForLuck noted that `datetime.date.replace()` documentation was confusing because it looked like it would be changing immutable objects. This documentation change specifies that the `replace()` methods in `datetime` return new objects. This uses similar wording to the documentation for `datetime.combine()`, which specifies that a new datetime is returned. This is also similar to wording for `string.replace()`, except `string.replace()` emphasizes that a "copy" is returned. Resolves #115684.
1 parent 5d0cdfe commit 0a18ea5

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

Doc/library/datetime.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ Instance methods:
646646

647647
.. method:: date.replace(year=self.year, month=self.month, day=self.day)
648648

649-
Return a date with the same value, except for those parameters given new
650-
values by whichever keyword arguments are specified.
649+
Return a new date with the same values, except with new values for
650+
those parameters given by whichever keyword arguments are specified.
651651

652652
Example::
653653

@@ -1273,10 +1273,10 @@ Instance methods:
12731273
hour=self.hour, minute=self.minute, second=self.second, microsecond=self.microsecond, \
12741274
tzinfo=self.tzinfo, *, fold=0)
12751275
1276-
Return a datetime with the same attributes, except for those attributes given
1277-
new values by whichever keyword arguments are specified. Note that
1278-
``tzinfo=None`` can be specified to create a naive datetime from an aware
1279-
datetime with no conversion of date and time data.
1276+
Return a new datetime with the same attributes, except with new attributes
1277+
for those parameters given by whichever keyword arguments are specified.
1278+
Note that ``tzinfo=None`` can be specified to create a naive datetime from
1279+
an aware datetime with no conversion of date and time data.
12801280

12811281
:class:`.datetime` objects are also supported by generic function
12821282
:func:`copy.replace`.
@@ -1851,10 +1851,10 @@ Instance methods:
18511851
.. method:: time.replace(hour=self.hour, minute=self.minute, second=self.second, \
18521852
microsecond=self.microsecond, tzinfo=self.tzinfo, *, fold=0)
18531853
1854-
Return a :class:`.time` with the same value, except for those attributes given
1855-
new values by whichever keyword arguments are specified. Note that
1856-
``tzinfo=None`` can be specified to create a naive :class:`.time` from an
1857-
aware :class:`.time`, without conversion of the time data.
1854+
Return a new :class:`.time` with the same values, except with new values for
1855+
those attributes given by whichever keyword arguments are specified. Note
1856+
that ``tzinfo=None`` can be specified to create a naive :class:`.time` from
1857+
an aware :class:`.time`, without conversion of the time data.
18581858

18591859
:class:`.time` objects are also supported by generic function
18601860
:func:`copy.replace`.

0 commit comments

Comments
 (0)