@@ -2284,21 +2284,50 @@ delta_bool(PyDateTime_Delta *self)
22842284static PyObject *
22852285delta_repr (PyDateTime_Delta * self )
22862286{
2287- if (GET_TD_MICROSECONDS (self ) != 0 )
2288- return PyUnicode_FromFormat ("%s(%d, %d, %d)" ,
2289- Py_TYPE (self )-> tp_name ,
2290- GET_TD_DAYS (self ),
2291- GET_TD_SECONDS (self ),
2292- GET_TD_MICROSECONDS (self ));
2293- if (GET_TD_SECONDS (self ) != 0 )
2294- return PyUnicode_FromFormat ("%s(%d, %d)" ,
2295- Py_TYPE (self )-> tp_name ,
2296- GET_TD_DAYS (self ),
2297- GET_TD_SECONDS (self ));
2298-
2299- return PyUnicode_FromFormat ("%s(%d)" ,
2300- Py_TYPE (self )-> tp_name ,
2301- GET_TD_DAYS (self ));
2287+ PyObject * args = PyUnicode_FromString ("" );
2288+
2289+ if (args == NULL ) {
2290+ return NULL ;
2291+ }
2292+
2293+ const char * sep = "" ;
2294+
2295+ if (GET_TD_DAYS (self ) != 0 ) {
2296+ Py_SETREF (args , PyUnicode_FromFormat ("days=%d" , GET_TD_DAYS (self )));
2297+ if (args == NULL ) {
2298+ return NULL ;
2299+ }
2300+ sep = ", " ;
2301+ }
2302+
2303+ if (GET_TD_SECONDS (self ) != 0 ) {
2304+ Py_SETREF (args , PyUnicode_FromFormat ("%U%sseconds=%d" , args , sep ,
2305+ GET_TD_SECONDS (self )));
2306+ if (args == NULL ) {
2307+ return NULL ;
2308+ }
2309+ sep = ", " ;
2310+ }
2311+
2312+ if (GET_TD_MICROSECONDS (self ) != 0 ) {
2313+ Py_SETREF (args , PyUnicode_FromFormat ("%U%smicroseconds=%d" , args , sep ,
2314+ GET_TD_MICROSECONDS (self )));
2315+ if (args == NULL ) {
2316+ return NULL ;
2317+ }
2318+ }
2319+
2320+ if (PyUnicode_GET_LENGTH (args ) == 0 ) {
2321+ Py_SETREF (args , PyUnicode_FromString ("0" ));
2322+ if (args == NULL ) {
2323+ return NULL ;
2324+ }
2325+ }
2326+
2327+ PyObject * repr = PyUnicode_FromFormat ("%s(%S)" , Py_TYPE (self )-> tp_name ,
2328+ args );
2329+ Py_DECREF (args );
2330+ return repr ;
23022331}
23032332
23042333static PyObject *
0 commit comments