diff options
author | Guido van Rossum <guido@python.org> | 2006-08-28 15:27:34 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-08-28 15:27:34 (GMT) |
commit | 86e58e239e39845e706c4afa392423f0fedcdf39 (patch) | |
tree | 1d0f4d942e644ee5c903636d87176b98a7203371 /Objects | |
parent | ecfd0b2f3bfd622c3ba148e53d3feebb8c1ae721 (diff) | |
download | cpython-86e58e239e39845e706c4afa392423f0fedcdf39.zip cpython-86e58e239e39845e706c4afa392423f0fedcdf39.tar.gz cpython-86e58e239e39845e706c4afa392423f0fedcdf39.tar.bz2 |
SF patch 1547796 by Georg Brandl -- set literals.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/setobject.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index d651457..b4b58b7 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -530,14 +530,20 @@ set_tp_print(PySetObject *so, FILE *fp, int flags) char *emit = ""; /* No separator emitted on first pass */ char *separator = ", "; - fprintf(fp, "%s([", so->ob_type->tp_name); + if (so->ob_type == &PySet_Type) + fprintf(fp, "{"); + else + fprintf(fp, "%s([", so->ob_type->tp_name); while (set_next(so, &pos, &entry)) { fputs(emit, fp); emit = separator; if (PyObject_Print(entry->key, fp, 0) != 0) return -1; } - fputs("])", fp); + if (so->ob_type == &PySet_Type) + fputs("}", fp); + else + fputs("])", fp); return 0; } @@ -554,8 +560,15 @@ set_repr(PySetObject *so) if (listrepr == NULL) return NULL; - result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name, - PyString_AS_STRING(listrepr)); + if (so->ob_type == &PySet_Type) { + char *s = PyString_AS_STRING(listrepr); + s += 1; + s[strlen(s)-1] = 0; + result = PyString_FromFormat("{%s}", s); + } else { + result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name, + PyString_AS_STRING(listrepr)); + } Py_DECREF(listrepr); return result; } |