@@ -5144,13 +5144,12 @@ datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz)
5144
5144
static PyObject *
5145
5145
datetime_utcnow (PyObject * cls , PyObject * dummy )
5146
5146
{
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
+ return NULL ;
5152
+ }
5154
5153
return datetime_best_possible (cls , _PyTime_gmtime , Py_None );
5155
5154
}
5156
5155
@@ -5187,13 +5186,12 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
5187
5186
static PyObject *
5188
5187
datetime_utcfromtimestamp (PyObject * cls , PyObject * args )
5189
5188
{
5190
- PyErr_WarnEx (
5191
- PyExc_DeprecationWarning ,
5189
+ if (PyErr_WarnEx (PyExc_DeprecationWarning ,
5192
5190
"datetime.utcfromtimestamp() is deprecated and scheduled for removal "
5193
5191
"in a future version. Use timezone-aware objects to represent "
5194
- "datetimes in UTC: datetime.now(datetime.UTC)." ,
5195
- 2
5196
- );
5192
+ "datetimes in UTC: datetime.now(datetime.UTC)." , 2 )) {
5193
+ return NULL ;
5194
+ }
5197
5195
PyObject * timestamp ;
5198
5196
PyObject * result = NULL ;
5199
5197
0 commit comments