Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5841fbc

Browse files
hugovkpganssle
andauthored
gh-103857: Document utcnow and utcfromtimestamp deprecations in What's New (#104542)
Co-authored-by: Paul Ganssle <[email protected]>
1 parent 0c5e79b commit 5841fbc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,16 @@ Deprecated
774774
``int``, convert to int explicitly with ``~int(x)``. (Contributed by Tim Hoffmann
775775
in :gh:`103487`.)
776776

777+
* :class:`datetime.datetime`'s
778+
:meth:`~datetime.datetime.utcnow` and
779+
:meth:`~datetime.datetime.utcfromtimestamp` are deprecated and will be
780+
removed in a future version. Instead, use timezone-aware objects to represent
781+
datetimes in UTC: respectively, call
782+
:meth:`~datetime.datetime.now` and
783+
:meth:`~datetime.datetime.fromtimestamp` with the *tz* parameter set to
784+
:attr:`datetime.UTC`.
785+
(Contributed by Paul Ganssle in :gh:`103857`.)
786+
777787
Pending Removal in Python 3.13
778788
------------------------------
779789

Modules/_datetimemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5190,7 +5190,7 @@ datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
51905190
if (PyErr_WarnEx(PyExc_DeprecationWarning,
51915191
"datetime.utcfromtimestamp() is deprecated and scheduled for removal "
51925192
"in a future version. Use timezone-aware objects to represent "
5193-
"datetimes in UTC: datetime.now(datetime.UTC).", 1))
5193+
"datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC).", 1))
51945194
{
51955195
return NULL;
51965196
}

0 commit comments

Comments
 (0)