Commit bdba5cf6 authored by Guido van Rossum's avatar Guido van Rossum

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.
parent 0cb85a97
...@@ -265,7 +265,7 @@ class TestJointOps(unittest.TestCase): ...@@ -265,7 +265,7 @@ class TestJointOps(unittest.TestCase):
self.assertEqual(repr(s), '{set(...)}') self.assertEqual(repr(s), '{set(...)}')
else: else:
name = repr(s).partition('(')[0] # strip class name name = repr(s).partition('(')[0] # strip class name
self.assertEqual(repr(s), '%s([%s(...)])' % (name, name)) self.assertEqual(repr(s), '%s({%s(...)})' % (name, name))
def test_cyclical_print(self): def test_cyclical_print(self):
w = ReprWrapper() w = ReprWrapper()
......
...@@ -571,6 +571,8 @@ set_repr(PySetObject *so) ...@@ -571,6 +571,8 @@ set_repr(PySetObject *so)
PyObject *keys, *result=NULL; PyObject *keys, *result=NULL;
Py_UNICODE *u; Py_UNICODE *u;
int status = Py_ReprEnter((PyObject*)so); int status = Py_ReprEnter((PyObject*)so);
PyObject *listrepr;
Py_ssize_t newsize;
if (status != 0) { if (status != 0) {
if (status < 0) if (status < 0)
...@@ -588,13 +590,7 @@ set_repr(PySetObject *so) ...@@ -588,13 +590,7 @@ set_repr(PySetObject *so)
if (keys == NULL) if (keys == NULL)
goto done; goto done;
if (Py_Type(so) != &PySet_Type) { listrepr = PyObject_Repr(keys);
result = PyUnicode_FromFormat("%s(%R)", Py_Type(so)->tp_name, keys);
Py_DECREF(keys);
}
else {
PyObject *listrepr = PyObject_Repr(keys);
Py_ssize_t newsize;
Py_DECREF(keys); Py_DECREF(keys);
if (listrepr == NULL) { if (listrepr == NULL) {
Py_DECREF(keys); Py_DECREF(keys);
...@@ -612,6 +608,12 @@ set_repr(PySetObject *so) ...@@ -612,6 +608,12 @@ set_repr(PySetObject *so)
*u++ = '}'; *u++ = '}';
} }
Py_DECREF(listrepr); 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: done:
Py_ReprLeave((PyObject*)so); Py_ReprLeave((PyObject*)so);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment