]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103857: Document utcnow and utcfromtimestamp deprecations in What's New (#104542)
authorHugo van Kemenade <hugovk@users.noreply.github.com>
Sun, 21 May 2023 19:45:44 +0000 (22:45 +0300)
committerGitHub <noreply@github.com>
Sun, 21 May 2023 19:45:44 +0000 (13:45 -0600)
Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
Doc/whatsnew/3.12.rst
Modules/_datetimemodule.c

index 8a0a59ba7301e187163b855f9f21bf65e8a7fb5e..14f03ef755c734e78591557c6da53609954311f1 100644 (file)
@@ -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
 ------------------------------
 
index 8b417bdd0fb5b6475fae205ddea92880d13942a9..19e11780ec6e19d3029b479a3bbfcca674b64376 100644 (file)
@@ -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;
     }