[Python-3000-checkins] r56811 - in python/branches/py3k-struni: Lib/test/test_set.py Objects/setobject.c

guido.van.rossum python-3000-checkins at python.org
Wed Aug 8 00:44:26 CEST 2007


Author: guido.van.rossum
Date: Wed Aug  8 00:44:20 2007
New Revision: 56811

Modified:
   python/branches/py3k-struni/Lib/test/test_set.py
   python/branches/py3k-struni/Objects/setobject.c
Log:
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.


Modified: python/branches/py3k-struni/Lib/test/test_set.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_set.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_set.py	Wed Aug  8 00:44:20 2007
@@ -265,7 +265,7 @@
             self.assertEqual(repr(s), '{set(...)}')
         else:
             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):
         w = ReprWrapper()

Modified: python/branches/py3k-struni/Objects/setobject.c
==============================================================================
--- python/branches/py3k-struni/Objects/setobject.c	(original)
+++ python/branches/py3k-struni/Objects/setobject.c	Wed Aug  8 00:44:20 2007
@@ -571,6 +571,8 @@
 	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 @@
 	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);


More information about the Python-3000-checkins mailing list