@@ -5144,13 +5144,12 @@ datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz)
51445144static PyObject *
51455145datetime_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+ return NULL ;
5152+ }
51545153 return datetime_best_possible (cls , _PyTime_gmtime , Py_None );
51555154}
51565155
@@ -5187,13 +5186,12 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
51875186static PyObject *
51885187datetime_utcfromtimestamp (PyObject * cls , PyObject * args )
51895188{
5190- PyErr_WarnEx (
5191- PyExc_DeprecationWarning ,
5189+ if (PyErr_WarnEx (PyExc_DeprecationWarning ,
51925190 "datetime.utcfromtimestamp() is deprecated and scheduled for removal "
51935191 "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+ }
51975195 PyObject * timestamp ;
51985196 PyObject * result = NULL ;
51995197
0 commit comments