summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-07 22:44:20 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-07 22:44:20 (GMT)
commitbdba5cf69478c82b3f8f644e52e6b6ca7d474b97 (patch)
tree9576f0579b44bcba474bc066de08d18b081b56a2 /Objects
parent0cb85a972f45ab1c59c6f11ecb73cf9509e23225 (diff)
downloadcpython-bdba5cf69478c82b3f8f644e52e6b6ca7d474b97.zip
cpython-bdba5cf69478c82b3f8f644e52e6b6ca7d474b97.tar.gz
cpython-bdba5cf69478c82b3f8f644e52e6b6ca7d474b97.tar.bz2
Change the repr() of frozenset instances (and set subclasses)
from name([e1, e2, ...]) to name({e1, e2, ...}). This makes more sense now we have the set notation.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 14d9155..2cc1743 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -571,6 +571,8 @@ set_repr(PySetObject *so)
PyObject *keys, *result=NULL;
Py_UNICODE *u;
int status = Py_ReprEnter((PyObject*)so);
+ PyObject *listrepr;
+ Py_ssize_t newsize;
if (status != 0) {
if (status < 0)
@@ -588,30 +590,30 @@ set_repr(PySetObject *so)
if (keys == NULL)
goto done;
- if (Py_Type(so) != &PySet_Type) {
- result = PyUnicode_FromFormat("%s(%R)", Py_Type(so)->tp_name, keys);
+ listrepr = PyObject_Repr(keys);
+ Py_DECREF(keys);
+ if (listrepr == NULL) {
Py_DECREF(keys);
+ goto done;
}
- else {
- PyObject *listrepr = PyObject_Repr(keys);
- Py_ssize_t newsize;
- Py_DECREF(keys);
- if (listrepr == NULL) {
- Py_DECREF(keys);
- goto done;
- }
- newsize = PyUnicode_GET_SIZE(listrepr);
- result = PyUnicode_FromUnicode(NULL, newsize);
- if (result) {
- u = PyUnicode_AS_UNICODE(result);
- *u++ = '{';
- /* Omit the brackets from the listrepr */
- Py_UNICODE_COPY(u, PyUnicode_AS_UNICODE(listrepr)+1,
- PyUnicode_GET_SIZE(listrepr)-2);
- u += newsize-2;
- *u++ = '}';
- }
- Py_DECREF(listrepr);
+ newsize = PyUnicode_GET_SIZE(listrepr);
+ result = PyUnicode_FromUnicode(NULL, newsize);
+ if (result) {
+ u = PyUnicode_AS_UNICODE(result);
+ *u++ = '{';
+ /* Omit the brackets from the listrepr */
+ Py_UNICODE_COPY(u, PyUnicode_AS_UNICODE(listrepr)+1,
+ PyUnicode_GET_SIZE(listrepr)-2);
+ u += newsize-2;
+ *u++ = '}';
+ }
+ Py_DECREF(listrepr);
+ if (Py_Type(so) != &PySet_Type) {
+ PyObject *tmp = PyUnicode_FromFormat("%s(%U)",
+ Py_Type(so)->tp_name,
+ result);
+ Py_DECREF(result);
+ result = tmp;
}
done:
Py_ReprLeave((PyObject*)so);