Skip to content

Commit 4c5e84d

Browse files
[3.12] gh-115684: Clarify datetime replace documentation (GH-116519) (#131694)
* 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: Paul Ganssle <[email protected]>
1 parent d00c6a3 commit 4c5e84d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Doc/library/datetime.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,8 @@ Instance methods:
650650

651651
.. method:: date.replace(year=self.year, month=self.month, day=self.day)
652652

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

656656
Example::
657657

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

12821282
.. versionchanged:: 3.6
12831283
Added the *fold* parameter.
@@ -1849,10 +1849,10 @@ Instance methods:
18491849
.. method:: time.replace(hour=self.hour, minute=self.minute, second=self.second, \
18501850
microsecond=self.microsecond, tzinfo=self.tzinfo, *, fold=0)
18511851
1852-
Return a :class:`.time` with the same value, except for those attributes given
1853-
new values by whichever keyword arguments are specified. Note that
1854-
``tzinfo=None`` can be specified to create a naive :class:`.time` from an
1855-
aware :class:`.time`, without conversion of the time data.
1852+
Return a new :class:`.time` with the same values, but with specified
1853+
parameters updated. Note that ``tzinfo=None`` can be specified to create a
1854+
naive :class:`.time` from an aware :class:`.time`, without conversion of the
1855+
time data.
18561856

18571857
.. versionchanged:: 3.6
18581858
Added the *fold* parameter.

0 commit comments

Comments
 (0)