diff -r 96736b0e4c30 Lib/test/test_structseq.py --- a/Lib/test/test_structseq.py Fri Jul 13 20:23:39 2012 -0700 +++ b/Lib/test/test_structseq.py Sun Jul 15 22:05:07 2012 -0700 @@ -34,7 +34,8 @@ t = time.gmtime(0) self.assertEqual(repr(t), "time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, " - "tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)") + "tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0, " + "tm_zone='UTC', tm_gmtoff=0)") # os.stat() gives a complicated struct sequence. st = os.stat(__file__) rep = repr(st) diff -r 96736b0e4c30 Objects/structseq.c --- a/Objects/structseq.c Fri Jul 13 20:23:39 2012 -0700 +++ b/Objects/structseq.c Sun Jul 15 22:05:07 2012 -0700 @@ -176,7 +176,12 @@ pbuf += len; *pbuf++ = '('; - for (i=0; i < VISIBLE_SIZE(obj); i++) { + Py_ssize_t n_fields, n_visible_fields, n_unnamed_fields; + n_fields = REAL_SIZE(obj); + n_visible_fields = VISIBLE_SIZE(obj); + n_unnamed_fields = UNNAMED_FIELDS(obj); + + for (i=0; i < n_visible_fields; i++) { PyObject *val, *repr; char *cname, *crepr; @@ -206,6 +211,47 @@ pbuf += strlen(crepr); *pbuf++ = ','; *pbuf++ = ' '; + Py_DECREF(repr); + } + else { + strcpy(pbuf, "..."); + pbuf += 3; + Py_DECREF(repr); + break; + } + } + + // issue 11698, __repr__ should also show the named, but unindexed fields + for (; i < n_fields; i++) { + PyObject *val, *repr; + char *cname, *crepr; + + cname = Py_TYPE(obj)->tp_members[i-n_unnamed_fields].name; + if (cname == NULL) { + PyErr_Format(PyExc_SystemError, "In structseq_repr(), member %d name is NULL" + " for type %.500s", i, typ->tp_name); + return NULL; + } + + val = PyStructSequence_GET_ITEM(obj, i); + repr = PyObject_Repr(val); + if (repr == NULL) + return NULL; + crepr = _PyUnicode_AsString(repr); + if (crepr == NULL) { + Py_DECREF(repr); + return NULL; + } + + len = strlen(cname) + strlen(crepr) + 3; + if ((pbuf+len) <= endofbuf) { + strcpy(pbuf, cname); + pbuf += strlen(cname); + *pbuf++ = '='; + strcpy(pbuf, crepr); + pbuf += strlen(crepr); + *pbuf++ = ','; + *pbuf++ = ' '; removelast = 1; Py_DECREF(repr); }