10000 GH-103944: Check error status when raising DeprecationWarning (#103949) · python/cpython@689723a · GitHub
[go: up one dir, main page]

Skip to content

Commit 689723a

Browse files
authored
GH-103944: Check error status when raising DeprecationWarning (#103949)
1 parent ebf97c5 commit 689723a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Modules/_datetimemodule.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5144,13 +5144,13 @@ datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz)
51445144
static PyObject *
51455145
datetime_utcnow(PyObject *cls, PyObject *dummy)
51465146
{
5147-
PyErr_WarnEx(
5148-
PyExc_DeprecationWarning,
5149-
"datetime.utcnow() is deprecated and scheduled for removal in a future "
5150-
"version. Use timezone-aware objects to represent datetimes in UTC: "
5151-
"datetime.now(datetime.UTC).",
5152-
2
5153-
);
5147+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
5148+
"datetime.utcnow() is deprecated and scheduled for removal in a "
5149+
"future version. Use timezone-aware objects to represent datetimes "
5150+
"in UTC: datetime.now(datetime.UTC).", 2))
5151+
{
5152+
return NULL;
5153+
}
51545154
return datetime_best_possible(cls, _PyTime_gmtime, Py_None);
51555155
}
51565156

@@ -5187,13 +5187,13 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
51875187
static PyObject *
51885188
datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
51895189
{
5190-
PyErr_WarnEx(
5191-
PyExc_DeprecationWarning,
5190+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
51925191
"datetime.utcfromtimestamp() is deprecated and scheduled for removal "
51935192
"in a future version. Use timezone-aware objects to represent "
5194-
"datetimes in UTC: datetime.now(datetime.UTC).",
5195-
2
5196-
);
5193+
"datetimes in UTC: datetime.now(datetime.UTC).", 2))
5194+
{
5195+
return NULL;
5196+
}
51975197
PyObject *timestamp;
51985198
PyObject *result = NULL;
51995199

0 commit comments

Comments
 (0)
0