Skip to content

Commit

Permalink
gh-103857: Document utcnow and utcfromtimestamp deprecations in What'…
Browse files Browse the repository at this point in the history
…s New (#104542)

Co-authored-by: Paul Ganssle <[email protected]>
  • Loading branch information
hugovk and pganssle authored May 21, 2023
1 parent 0c5e79b commit 5841fbc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,16 @@ Deprecated
``int``, convert to int explicitly with ``~int(x)``. (Contributed by Tim Hoffmann
in :gh:`103487`.)

* :class:`datetime.datetime`'s
:meth:`~datetime.datetime.utcnow` and
:meth:`~datetime.datetime.utcfromtimestamp` are deprecated and will be
removed in a future version. Instead, use timezone-aware objects to represent
datetimes in UTC: respectively, call
:meth:`~datetime.datetime.now` and
:meth:`~datetime.datetime.fromtimestamp` with the *tz* parameter set to
:attr:`datetime.UTC`.
(Contributed by Paul Ganssle in :gh:`103857`.)

Pending Removal in Python 3.13
------------------------------

Expand Down
2 changes: 1 addition & 1 deletion Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5190,7 +5190,7 @@ datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"datetime.utcfromtimestamp() is deprecated and scheduled for removal "
"in a future version. Use timezone-aware objects to represent "
"datetimes in UTC: datetime.now(datetime.UTC).", 1))
"datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC).", 1))
{
return NULL;
}
Expand Down

0 comments on commit 5841fbc

Please sign in to comment.