[Python-checkins] gh-103857: Document utcnow and utcfromtimestamp deprecations in What's New (#104542)
hugovk
webhook-mailer at python.org
Sun May 21 15:45:51 EDT 2023
https://github.com/python/cpython/commit/5841fbc1a2aa5dd9e1c3d8d369f2bba8a99b285b
commit: 5841fbc1a2aa5dd9e1c3d8d369f2bba8a99b285b
branch: main
author: Hugo van Kemenade <hugovk at users.noreply.github.com>
committer: hugovk <hugovk at users.noreply.github.com>
date: 2023-05-21T13:45:44-06:00
summary:
gh-103857: Document utcnow and utcfromtimestamp deprecations in What's New (#104542)
Co-authored-by: Paul Ganssle <1377457+pganssle at users.noreply.github.com>
files:
M Doc/whatsnew/3.12.rst
M Modules/_datetimemodule.c
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst
index 8a0a59ba7301..14f03ef755c7 100644
--- a/Doc/whatsnew/3.12.rst
+++ b/Doc/whatsnew/3.12.rst
@@ -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
------------------------------
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 8b417bdd0fb5..19e11780ec6e 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -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;
}
More information about the Python-checkins
mailing list