Skip to content

Commit d2d8862

Browse files
gh-115684: Clarify datetime replace documentation (#116519)
* 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. * Include reviewer comments Thanks Privat33r-dev for the comments! --------- Co-authored-by: Paul Ganssle <[email protected]>
1 parent d716ea3 commit d2d8862

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
@@ -699,8 +699,8 @@ Instance methods:
699699

700700
.. method:: date.replace(year=self.year, month=self.month, day=self.day)
701701

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

705705
Example::
706706

@@ -709,8 +709,8 @@ Instance methods:
709709
>>> d.replace(day=26)
710710
datetime.date(2002, 12, 26)
711711

712-
:class:`date` objects are also supported by generic function
713-
:func:`copy.replace`.
712+
The generic function :func:`copy.replace` also supports :class:`date`
713+
objects.
714714

715715

716716
.. method:: date.timetuple()
@@ -1348,10 +1348,10 @@ Instance methods:
13481348
hour=self.hour, minute=self.minute, second=self.second, microsecond=self.microsecond, \
13491349
tzinfo=self.tzinfo, *, fold=0)
13501350
1351-
Return a datetime with the same attributes, except for those attributes given
1352-
new values by whichever keyword arguments are specified. Note that
1353-
``tzinfo=None`` can be specified to create a naive datetime from an aware
1354-
datetime with no conversion of date and time data.
1351+
Return a new :class:`datetime` object with the same attributes, but with
1352+
specified parameters updated. Note that ``tzinfo=None`` can be specified to
1353+
create a naive datetime from an aware datetime with no conversion of date
1354+
and time data.
13551355

13561356
:class:`.datetime` objects are also supported by generic function
13571357
:func:`copy.replace`.
@@ -1942,10 +1942,10 @@ Instance methods:
19421942
.. method:: time.replace(hour=self.hour, minute=self.minute, second=self.second, \
19431943
microsecond=self.microsecond, tzinfo=self.tzinfo, *, fold=0)
19441944
1945-
Return a :class:`.time` with the same value, except for those attributes given
1946-
new values by whichever keyword arguments are specified. Note that
1947-
``tzinfo=None`` can be specified to create a naive :class:`.time` from an
1948-
aware :class:`.time`, without conversion of the time data.
1945+
Return a new :class:`.time` with the same values, but with specified
1946+
parameters updated. Note that ``tzinfo=None`` can be specified to create a
1947+
naive :class:`.time` from an aware :class:`.time`, without conversion of the
1948+
time data.
19491949

19501950
:class:`.time` objects are also supported by generic function
19511951
:func:`copy.replace`.

0 commit comments

Comments
 (0)