@@ -1367,7 +1367,7 @@ static PyObject *
13671367odict_repr (PyODictObject * self )
13681368{
13691369 int i ;
1370- PyObject * pieces = NULL , * result = NULL ;
1370+ PyObject * result = NULL , * dcopy = NULL ;
13711371
13721372 if (PyODict_SIZE (self ) == 0 )
13731373 return PyUnicode_FromFormat ("%s()" , _PyType_Name (Py_TYPE (self )));
@@ -1377,57 +1377,16 @@ odict_repr(PyODictObject *self)
13771377 return i > 0 ? PyUnicode_FromString ("..." ) : NULL ;
13781378 }
13791379
1380- if (PyODict_CheckExact (self )) {
1381- Py_ssize_t count = 0 ;
1382- _ODictNode * node ;
1383- pieces = PyList_New (PyODict_SIZE (self ));
1384- if (pieces == NULL )
1385- goto Done ;
1386-
1387- _odict_FOREACH (self , node ) {
1388- PyObject * pair ;
1389- PyObject * key = _odictnode_KEY (node );
1390- PyObject * value = _odictnode_VALUE (node , self );
1391- if (value == NULL ) {
1392- if (!PyErr_Occurred ())
1393- PyErr_SetObject (PyExc_KeyError , key );
1394- goto Done ;
1395- }
1396- pair = PyTuple_Pack (2 , key , value );
1397- if (pair == NULL )
1398- goto Done ;
1399-
1400- if (count < PyList_GET_SIZE (pieces ))
1401- PyList_SET_ITEM (pieces , count , pair ); /* steals reference */
1402- else {
1403- if (PyList_Append (pieces , pair ) < 0 ) {
1404- Py_DECREF (pair );
1405- goto Done ;
1406- }
1407- Py_DECREF (pair );
1408- }
1409- count ++ ;
1410- }
1411- if (count < PyList_GET_SIZE (pieces )) {
1412- Py_SET_SIZE (pieces , count );
1413- }
1414- }
1415- else {
1416- PyObject * items = PyObject_CallMethodNoArgs (
1417- (PyObject * )self , & _Py_ID (items ));
1418- if (items == NULL )
1419- goto Done ;
1420- pieces = PySequence_List (items );
1421- Py_DECREF (items );
1422- if (pieces == NULL )
1423- goto Done ;
1380+ dcopy = PyDict_Copy ((PyObject * )self );
1381+ if (dcopy == NULL ) {
1382+ goto Done ;
14241383 }
14251384
14261385 result = PyUnicode_FromFormat ("%s(%R)" ,
1427- _PyType_Name (Py_TYPE (self )), pieces );
1386+ _PyType_Name (Py_TYPE (self )),
1387+ dcopy );
14281388
14291389Done :
1430- Py_XDECREF (pieces );
14311390 Py_ReprLeave ((PyObject * )self );
14321391 return result ;
14331392}
0 commit comments