[pypy-commit] pypy py3k: set.__repr__ uses the new set literal syntax: {1, 2, 3}

amauryfa noreply at buildbot.pypy.org
Thu Dec 22 00:39:53 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r50817:ceb5f49d0eeb
Date: 2011-12-22 00:39 +0100
http://bitbucket.org/pypy/pypy/changeset/ceb5f49d0eeb/

Log:	set.__repr__ uses the new set literal syntax: {1, 2, 3}

diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -641,7 +641,11 @@
             return '%s(...)' % (s.__class__.__name__,)
         currently_in_repr[set_id] = 1
         try:
-            return '%s(%s)' % (s.__class__.__name__, [x for x in s])
+            listrepr = repr([x for x in s])
+            if type(s) is set:
+                return '{%s}' % (listrepr[1:-1],)
+            else:
+                return '%s({%s})' % (s.__class__.__name__, listrepr[1:-1])
         finally:
             try:
                 del currently_in_repr[set_id]
diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -52,7 +52,7 @@
 
     def test_space_newset(self):
         s = self.space.newset()
-        assert self.space.str_w(self.space.repr(s)) == 'set([])'
+        assert self.space.str_w(self.space.repr(s)) == '{}'
 
 class AppTestAppSetTest:
     def test_subtype(self):
@@ -189,9 +189,9 @@
         s = set([1, 2, 3])
         s.add(A(s))
         therepr = repr(s)
-        assert therepr.startswith("set([")
-        assert therepr.endswith("])")
-        inner = set(therepr[5:-2].split(", "))
+        assert therepr.startswith("{")
+        assert therepr.endswith("}")
+        inner = set(therepr[1:-1].split(", "))
         assert inner == set(["1", "2", "3", "set(...)"])
 
     def test_recursive_repr_frozenset(self):
@@ -202,8 +202,8 @@
         s = frozenset([1, 2, 3, a])
         a.s = s
         therepr = repr(s)
-        assert therepr.startswith("frozenset([")
-        assert therepr.endswith("])")
+        assert therepr.startswith("frozenset({")
+        assert therepr.endswith("})")
         inner = set(therepr[11:-2].split(", "))
         assert inner == set(["1", "2", "3", "frozenset(...)"])
         
@@ -211,7 +211,7 @@
         s = set()
         try:
             s.remove(1)
-        except KeyError, e:
+        except KeyError as e:
             assert e.args[0] == 1
         else:
             assert 0, "should raise"
@@ -223,7 +223,7 @@
                 return int(id(self) & 0x7fffffff)
         s = H()
         f = set([s])
-        print f
+        print(f)
         assert s in f
         f.remove(s)
         f.add(s)
@@ -265,7 +265,7 @@
         key = set([2, 3])
         try:
             s.remove(key)
-        except KeyError, e:
+        except KeyError as e:
             assert e.args[0] is key
 
     def test_contains(self):
@@ -294,7 +294,7 @@
         for v1 in ['Q', (1,)]:
             try:
                 s.remove(v1)
-            except KeyError, e:
+            except KeyError as e:
                 v2 = e.args[0]
                 assert v1 == v2
             else:


More information about the pypy-commit mailing list