summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorPaul Ganssle <1377457+pganssle@users.noreply.github.com>2023-04-27 17:32:30 (GMT)
committerGitHub <noreply@github.com>2023-04-27 17:32:30 (GMT)
commit0b7fd8ffc5df187edf8b5d926cee359924462df5 (patch)
treef88f8ba6dea519974bc2da3a4e18d69d07aefc8f /Modules
parenta5308e188b810e5cc69c1570bdc9b21ed6c87805 (diff)
downloadcpython-0b7fd8ffc5df187edf8b5d926cee359924462df5.zip
cpython-0b7fd8ffc5df187edf8b5d926cee359924462df5.tar.gz
cpython-0b7fd8ffc5df187edf8b5d926cee359924462df5.tar.bz2
GH-103857: Deprecate utcnow and utcfromtimestamp (#103858)
Using `datetime.datetime.utcnow()` and `datetime.datetime.utcfromtimestamp()` will now raise a `DeprecationWarning`. We also have removed our internal uses of these functions and documented the change.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_datetimemodule.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index f317dc1..d392d38 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -5144,6 +5144,13 @@ datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz)
static PyObject *
datetime_utcnow(PyObject *cls, PyObject *dummy)
{
+ PyErr_WarnEx(
+ PyExc_DeprecationWarning,
+ "datetime.utcnow() is deprecated and scheduled for removal in a future "
+ "version. Use timezone-aware objects to represent datetimes in UTC: "
+ "datetime.now(datetime.UTC).",
+ 2
+ );
return datetime_best_possible(cls, _PyTime_gmtime, Py_None);
}
@@ -5180,6 +5187,13 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
static PyObject *
datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
{
+ 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).",
+ 2
+ );
PyObject *timestamp;
PyObject *result = NULL;