[pypy-svn] pypy commit ab67e6572ad6: move __repr__ to dicttype.py

Bitbucket commits-noreply at bitbucket.org
Thu Dec 16 05:04:08 CET 2010


# HG changeset patch -- Bitbucket.org
# Project pypy
# URL http://bitbucket.org/pypy/pypy/overview
# User Benjamin Peterson <benjamin at python.org>
# Date 1292472299 21600
# Node ID ab67e6572ad6391beab31eac9c96c6bf139c3bdf
# Parent  20c28decae46ff7b47dcbd30e7d51655d87ef3aa
move __repr__ to dicttype.py

--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -809,42 +809,6 @@ def dict_popitem__DictMulti(space, w_dic
                              space.wrap("popitem(): dictionary is empty"))
     return space.newtuple([w_key, w_value])
 
-app = gateway.applevel('''
-    def dictrepr(currently_in_repr, d):
-        # Now we only handle one implementation of dicts, this one.
-        # The fix is to move this to dicttype.py, and do a
-        # multimethod lookup mapping str to StdObjSpace.str
-        # This cannot happen until multimethods are fixed. See dicttype.py
-            dict_id = id(d)
-            if dict_id in currently_in_repr:
-                return '{...}'
-            currently_in_repr[dict_id] = 1
-            try:
-                items = []
-                # XXX for now, we cannot use iteritems() at app-level because
-                #     we want a reasonable result instead of a RuntimeError
-                #     even if the dict is mutated by the repr() in the loop.
-                for k, v in dict.items(d):
-                    items.append(repr(k) + ": " + repr(v))
-                return "{" +  ', '.join(items) + "}"
-            finally:
-                try:
-                    del currently_in_repr[dict_id]
-                except:
-                    pass
-''', filename=__file__)
-
-dictrepr = app.interphook("dictrepr")
-
-def repr__DictMulti(space, w_dict):
-    if w_dict.length() == 0:
-        return space.wrap('{}')
-    ec = space.getexecutioncontext()
-    w_currently_in_repr = ec._py_repr
-    if w_currently_in_repr is None:
-        w_currently_in_repr = ec._py_repr = space.newdict()
-    return dictrepr(space, w_currently_in_repr, w_dict)
-
 
 # ____________________________________________________________
 # Iteration

--- a/pypy/objspace/std/dicttype.py
+++ b/pypy/objspace/std/dicttype.py
@@ -49,10 +49,6 @@ dict_reversed   = SMM('__reversed__',   
 def dict_reversed__ANY(space, w_dict):
     raise OperationError(space.w_TypeError, space.wrap('argument to reversed() must be a sequence'))
 
-#dict_fromkeys   = MultiMethod('fromkeys',      2, varargs=True)
-# This can return when multimethods have been fixed
-#dict_str        = StdObjSpace.str
-
 register_all(vars(), globals())
 
 @gateway.unwrap_spec(ObjSpace, W_Root, W_Root, W_Root)
@@ -71,6 +67,40 @@ def descr_fromkeys(space, w_type, w_keys
     return w_dict
 
 
+app = gateway.applevel('''
+    def dictrepr(currently_in_repr, d):
+        if len(d) == 0:
+            return "{}"
+        dict_id = id(d)
+        if dict_id in currently_in_repr:
+            return '{...}'
+        currently_in_repr[dict_id] = 1
+        try:
+            items = []
+            # XXX for now, we cannot use iteritems() at app-level because
+            #     we want a reasonable result instead of a RuntimeError
+            #     even if the dict is mutated by the repr() in the loop.
+            for k, v in dict.items(d):
+                items.append(repr(k) + ": " + repr(v))
+            return "{" +  ', '.join(items) + "}"
+        finally:
+            try:
+                del currently_in_repr[dict_id]
+            except:
+                pass
+''', filename=__file__)
+
+dictrepr = app.interphook("dictrepr")
+
+
+def descr_repr(space, w_dict):
+    ec = space.getexecutioncontext()
+    w_currently_in_repr = ec._py_repr
+    if w_currently_in_repr is None:
+        w_currently_in_repr = ec._py_repr = space.newdict()
+    return dictrepr(space, w_currently_in_repr, w_dict)
+
+
 # ____________________________________________________________
 
 def descr__new__(space, w_dicttype, __args__):
@@ -95,6 +125,7 @@ dict(**kwargs) -> new dictionary initial
                                  [gateway.ObjSpace,
                                   gateway.W_Root,gateway.Arguments]),
     __hash__ = no_hash_descr,
+    __repr__ = gateway.interp2app(descr_repr),
     fromkeys = gateway.interp2app(descr_fromkeys, as_classmethod=True),
     )
 dict_typedef.registermethods(globals())



More information about the Pypy-commit mailing list