@@ -3926,16 +3926,16 @@ time_replace(PyDateTime_Time *self, PyObject *args, PyObject *kw)
39263926 time_kws ,
39273927 & hh , & mm , & ss , & us , & tzinfo , & fold ))
39283928 return NULL ;
3929+ if (fold != 0 && fold != 1 ) {
3930+ PyErr_SetString (PyExc_ValueError ,
3931+ "fold must be either 0 or 1" );
3932+ return NULL ;
3933+ }
39293934 tuple = Py_BuildValue ("iiiiO" , hh , mm , ss , us , tzinfo );
39303935 if (tuple == NULL )
39313936 return NULL ;
39323937 clone = time_new (Py_TYPE (self ), tuple , NULL );
39333938 if (clone != NULL ) {
3934- if (fold != 0 && fold != 1 ) {
3935- PyErr_SetString (PyExc_ValueError ,
3936- "fold must be either 0 or 1" );
3937- return NULL ;
3938- }
39393939 TIME_SET_FOLD (clone , fold );
39403940 }
39413941 Py_DECREF (tuple );
@@ -5019,17 +5019,16 @@ datetime_replace(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
50195019 & y , & m , & d , & hh , & mm , & ss , & us ,
50205020 & tzinfo , & fold ))
50215021 return NULL ;
5022+ if (fold != 0 && fold != 1 ) {
5023+ PyErr_SetString (PyExc_ValueError ,
5024+ "fold must be either 0 or 1" );
5025+ return NULL ;
5026+ }
50225027 tuple = Py_BuildValue ("iiiiiiiO" , y , m , d , hh , mm , ss , us , tzinfo );
50235028 if (tuple == NULL )
50245029 return NULL ;
50255030 clone = datetime_new (Py_TYPE (self ), tuple , NULL );
5026-
50275031 if (clone != NULL ) {
5028- if (fold != 0 && fold != 1 ) {
5029- PyErr_SetString (PyExc_ValueError ,
5030- "fold must be either 0 or 1" );
5031- return NULL ;
5032- }
50335032 DATE_SET_FOLD (clone , fold );
50345033 }
50355034 Py_DECREF (tuple );
0 commit comments