From f215d516220e194847180e4c548a99928bd8e06a Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Thu, 27 Apr 2023 14:08:56 -0600 Subject: [PATCH 1/2] Check error status when raising DeprecationWarning --- Modules/_datetimemodule.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index d392d384c3eee6..4c5e97e1509dff 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -5144,13 +5144,12 @@ 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 - ); + if(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 NULL; + } return datetime_best_possible(cls, _PyTime_gmtime, Py_None); } @@ -5187,13 +5186,12 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw) static PyObject * datetime_utcfromtimestamp(PyObject *cls, PyObject *args) { - PyErr_WarnEx( - PyExc_DeprecationWarning, + 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).", - 2 - ); + "datetimes in UTC: datetime.now(datetime.UTC).", 2)) { + return NULL; + } PyObject *timestamp; PyObject *result = NULL; From 0cda214c2ebb3ba1b3c9f40dc64f49a6a1a4b41d Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Fri, 28 Apr 2023 14:49:14 -0400 Subject: [PATCH 2/2] fixup! Check error status when raising DeprecationWarning --- Modules/_datetimemodule.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 4c5e97e1509dff..8f86fc91966205 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -5144,10 +5144,11 @@ datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz) static PyObject * datetime_utcnow(PyObject *cls, PyObject *dummy) { - if(PyErr_WarnEx(PyExc_DeprecationWarning, + if (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)) { + "in UTC: datetime.now(datetime.UTC).", 2)) + { return NULL; } return datetime_best_possible(cls, _PyTime_gmtime, Py_None); @@ -5186,10 +5187,11 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw) static PyObject * datetime_utcfromtimestamp(PyObject *cls, PyObject *args) { - if(PyErr_WarnEx(PyExc_DeprecationWarning, + 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).", 2)) { + "datetimes in UTC: datetime.now(datetime.UTC).", 2)) + { return NULL; } PyObject *timestamp;