mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
[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 d2d886215c)
Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
This commit is contained in:
parent
d00c6a3c63
commit
4c5e84dbbe
1 changed files with 10 additions and 10 deletions
|
|
@ -650,8 +650,8 @@ Instance methods:
|
|||
|
||||
.. method:: date.replace(year=self.year, month=self.month, day=self.day)
|
||||
|
||||
Return a date with the same value, except for those parameters given new
|
||||
values by whichever keyword arguments are specified.
|
||||
Return a new :class:`date` object with the same values, but with specified
|
||||
parameters updated.
|
||||
|
||||
Example::
|
||||
|
||||
|
|
@ -1274,10 +1274,10 @@ Instance methods:
|
|||
hour=self.hour, minute=self.minute, second=self.second, microsecond=self.microsecond, \
|
||||
tzinfo=self.tzinfo, *, fold=0)
|
||||
|
||||
Return a datetime with the same attributes, except for those attributes given
|
||||
new values by whichever keyword arguments are specified. Note that
|
||||
``tzinfo=None`` can be specified to create a naive datetime from an aware
|
||||
datetime with no conversion of date and time data.
|
||||
Return a new :class:`datetime` object with the same attributes, but with
|
||||
specified parameters updated. Note that ``tzinfo=None`` can be specified to
|
||||
create a naive datetime from an aware datetime with no conversion of date
|
||||
and time data.
|
||||
|
||||
.. versionchanged:: 3.6
|
||||
Added the *fold* parameter.
|
||||
|
|
@ -1849,10 +1849,10 @@ Instance methods:
|
|||
.. method:: time.replace(hour=self.hour, minute=self.minute, second=self.second, \
|
||||
microsecond=self.microsecond, tzinfo=self.tzinfo, *, fold=0)
|
||||
|
||||
Return a :class:`.time` with the same value, except for those attributes given
|
||||
new values by whichever keyword arguments are specified. Note that
|
||||
``tzinfo=None`` can be specified to create a naive :class:`.time` from an
|
||||
aware :class:`.time`, without conversion of the time data.
|
||||
Return a new :class:`.time` with the same values, but with specified
|
||||
parameters updated. Note that ``tzinfo=None`` can be specified to create a
|
||||
naive :class:`.time` from an aware :class:`.time`, without conversion of the
|
||||
time data.
|
||||
|
||||
.. versionchanged:: 3.6
|
||||
Added the *fold* parameter.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue