Skip to content

Commit 7e9c577

Browse files
miss-islingtondavidlowrydudapganssle
authored
[3.13] gh-115684: Clarify datetime replace documentation (GH-116519) (#131676)
gh-115684: Clarify datetime `replace` documentation (GH-116519) * Clarify datetime `replace` documentation In GH-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 GH-115684. * Include reviewer comments Thanks Privat33r-dev for the comments! --------- (cherry picked from commit d2d8862) Co-authored-by: David Lowry-Duda <[email protected]> Co-authored-by: Paul Ganssle <[email protected]>
1 parent 53b9370 commit 7e9c577

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Doc/library/datetime.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@ Instance methods:
666666

667667
.. method:: date.replace(year=self.year, month=self.month, day=self.day)
668668

669-
Return a date with the same value, except for those parameters given new
670-
values by whichever keyword arguments are specified.
669+
Return a new :class:`date` object with the same values, but with specified
670+
parameters updated.
671671

672672
Example::
673673

@@ -676,8 +676,8 @@ Instance methods:
676676
>>> d.replace(day=26)
677677
datetime.date(2002, 12, 26)
678678

679-
:class:`date` objects are also supported by generic function
680-
:func:`copy.replace`.
679+
The generic function :func:`copy.replace` also supports :class:`date`
680+
objects.
681681

682682

683683
.. method:: date.timetuple()
@@ -1315,10 +1315,10 @@ Instance methods:
13151315
hour=self.hour, minute=self.minute, second=self.second, microsecond=self.microsecond, \
13161316
tzinfo=self.tzinfo, *, fold=0)
13171317
1318-
Return a datetime with the same attributes, except for those attributes given
1319-
new values by whichever keyword arguments are specified. Note that
1320-
``tzinfo=None`` can be specified to create a naive datetime from an aware
1321-
datetime with no conversion of date and time data.
1318+
Return a new :class:`datetime` object with the same attributes, but with
1319+
specified parameters updated. Note that ``tzinfo=None`` can be specified to
1320+
create a naive datetime from an aware datetime with no conversion of date
1321+
and time data.
13221322

13231323
:class:`.datetime` objects are also supported by generic function
13241324
:func:`copy.replace`.
@@ -1893,10 +1893,10 @@ Instance methods:
18931893
.. method:: time.replace(hour=self.hour, minute=self.minute, second=self.second, \
18941894
microsecond=self.microsecond, tzinfo=self.tzinfo, *, fold=0)
18951895
1896-
Return a :class:`.time` with the same value, except for those attributes given
1897-
new values by whichever keyword arguments are specified. Note that
1898-
``tzinfo=None`` can be specified to create a naive :class:`.time` from an
1899-
aware :class:`.time`, without conversion of the time data.
1896+
Return a new :class:`.time` with the same values, but with specified
1897+
parameters updated. Note that ``tzinfo=None`` can be specified to create a
1898+
naive :class:`.time` from an aware :class:`.time`, without conversion of the
1899+
time data.
19001900

19011901
:class:`.time` objects are also supported by generic function
19021902
:func:`copy.replace`.

0 commit comments

Comments
 (0)