@@ -1702,6 +1702,24 @@ append_keyword_fold(PyObject *repr, int fold)
17021702 return repr ;
17031703}
17041704
1705+ static PyObject *
1706+ append_keyword_nanosecond (PyObject * repr , int nanosecond )
1707+ {
1708+ PyObject * temp ;
1709+ assert (PyUnicode_Check (repr ));
1710+ if (nanosecond == 0 ) {
1711+ return repr ;
1712+ }
1713+ assert (PyUnicode_READ_CHAR (repr , PyUnicode_GET_LENGTH (repr )- 1 ) == ')' );
1714+ temp = PyUnicode_Substring (repr , 0 , PyUnicode_GET_LENGTH (repr ) - 1 );
1715+ Py_DECREF (repr );
1716+ if (temp == NULL )
1717+ return NULL ;
1718+ repr = PyUnicode_FromFormat ("%U, nanosecond=%d)" , temp , nanosecond );
1719+ Py_DECREF (temp );
1720+ return repr ;
1721+ }
1722+
17051723static inline PyObject *
17061724tzinfo_from_isoformat_results (int rv , int tzoffset , int tz_microseconds , int tz_nanosecond )
17071725{
@@ -6320,16 +6338,6 @@ datetime_repr(PyObject *op)
63206338 PyObject * baserepr ;
63216339
63226340 if (DATE_GET_MICROSECOND (self )) {
6323- baserepr = PyUnicode_FromFormat (
6324- "%s(%d, %d, %d, %d, %d, %d, %d, %d)" ,
6325- type_name ,
6326- GET_YEAR (self ), GET_MONTH (self ), GET_DAY (self ),
6327- DATE_GET_HOUR (self ), DATE_GET_MINUTE (self ),
6328- DATE_GET_SECOND (self ),
6329- DATE_GET_MICROSECOND (self ),
6330- DATE_GET_NANOSECOND (self ));
6331- }
6332- else if (DATE_GET_MICROSECOND (self )) {
63336341 baserepr = PyUnicode_FromFormat (
63346342 "%s(%d, %d, %d, %d, %d, %d, %d)" ,
63356343 type_name ,
@@ -6355,6 +6363,8 @@ datetime_repr(PyObject *op)
63556363 }
63566364 if (baserepr != NULL && DATE_GET_FOLD (self ) != 0 )
63576365 baserepr = append_keyword_fold (baserepr , DATE_GET_FOLD (self ));
6366+ if (baserepr != NULL && DATE_GET_NANOSECOND (self ) != 0 )
6367+ baserepr = append_keyword_nanosecond (baserepr , DATE_GET_NANOSECOND (self ));
63586368 if (baserepr == NULL || ! HASTZINFO (self ))
63596369 return baserepr ;
63606370 return append_keyword_tzinfo (baserepr , self -> tzinfo );
0 commit comments