summaryrefslogtreecommitdiffstats
path: root/Modules/_datetimemodule.c
diff options
context:
space:
mode:
authorPaul Ganssle <1377457+pganssle@users.noreply.github.com>2023-04-28 19:44:13 (GMT)
committerGitHub <noreply@github.com>2023-04-28 19:44:13 (GMT)
commit689723a4abdc1e61a9f71db8ff40886ae1b1704d (patch)
treebf45e7b8dafbbcabc1696bb6d651f265d16b5ccc /Modules/_datetimemodule.c
parentebf97c50f25d61e15671a4658f5718f214c35a98 (diff)
downloadcpython-689723a4abdc1e61a9f71db8ff40886ae1b1704d.zip
cpython-689723a4abdc1e61a9f71db8ff40886ae1b1704d.tar.gz
cpython-689723a4abdc1e61a9f71db8ff40886ae1b1704d.tar.bz2
GH-103944: Check error status when raising DeprecationWarning (#103949)
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r--Modules/_datetimemodule.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index d392d38..8f86fc9 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -5144,13 +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
- );
+ 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 +5187,13 @@ 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;