Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: mappingproxy
Changeset: r86005:fcb110da6372
Date: 2016-08-03 17:21 +0100
http://bitbucket.org/pypy/pypy/changeset/fcb110da6372/

Log:    Merge obsoleted impl of W_DictProxyObject into the correct one: fix
        __new__, __init__ and __repr__

diff --git a/pypy/objspace/std/classdict.py b/pypy/objspace/std/classdict.py
--- a/pypy/objspace/std/classdict.py
+++ b/pypy/objspace/std/classdict.py
@@ -9,35 +9,6 @@
 from pypy.objspace.std.typeobject import unwrap_cell
 
 
-class W_DictProxyObject(W_DictObject):
-    @staticmethod
-    def descr_new(space, w_type, w_mapping):
-        if (not space.lookup(w_mapping, "__getitem__") or
-            space.isinstance_w(w_mapping, space.w_list) or
-            space.isinstance_w(w_mapping, space.w_tuple)):
-            raise oefmt(space.w_TypeError,
-                        "mappingproxy() argument must be a mapping, not %T", 
w_mapping)
-        strategy = space.fromcache(MappingProxyStrategy)
-        storage = strategy.erase(w_mapping)
-        w_obj = space.allocate_instance(W_DictProxyObject, w_type)
-        W_DictProxyObject.__init__(w_obj, space, strategy, storage)
-        return w_obj
-
-    def descr_init(self, space, __args__):
-        pass
-
-    def descr_repr(self, space):
-        return space.wrap(u"mappingproxy(%s)" % (
-            space.unicode_w(W_DictObject.descr_repr(self, space))))
-
-W_DictProxyObject.typedef = TypeDef(
-    "mappingproxy", W_DictObject.typedef,
-    __new__ = interp2app(W_DictProxyObject.descr_new),
-    __init__ = interp2app(W_DictProxyObject.descr_init),
-    __repr__ = interp2app(W_DictProxyObject.descr_repr),
-)
-
-
 class ClassDictStrategy(DictStrategy):
     """Exposes a W_TypeObject.dict_w at app-level.
 
diff --git a/pypy/objspace/std/dictproxyobject.py 
b/pypy/objspace/std/dictproxyobject.py
--- a/pypy/objspace/std/dictproxyobject.py
+++ b/pypy/objspace/std/dictproxyobject.py
@@ -2,6 +2,7 @@
 # type.__dict__, so PyDictProxy_New has to use a custom read-only mapping.
 
 from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import oefmt
 from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
 from pypy.interpreter.typedef import TypeDef, interp2app
 
@@ -11,6 +12,18 @@
     def __init__(self, w_mapping):
         self.w_mapping = w_mapping
 
+    @staticmethod
+    def descr_new(space, w_type, w_mapping):
+        if (not space.lookup(w_mapping, "__getitem__") or
+                space.isinstance_w(w_mapping, space.w_list) or
+                space.isinstance_w(w_mapping, space.w_tuple)):
+            raise oefmt(space.w_TypeError,
+                        "mappingproxy() argument must be a mapping, not %T", 
w_mapping)
+        return W_DictProxyObject(w_mapping)
+
+    def descr_init(self, space, __args__):
+        pass
+
     def descr_len(self, space):
         return space.len(self.w_mapping)
 
@@ -27,7 +40,8 @@
         return space.str(self.w_mapping)
 
     def descr_repr(self, space):
-        return space.repr(self.w_mapping)
+        return space.newunicode(u"mappingproxy(%s)" %
+                                (space.unicode_w(space.repr(self.w_mapping)),))
 
     @unwrap_spec(w_default=WrappedDefault(None))
     def get_w(self, space, w_key, w_default):
@@ -47,6 +61,8 @@
 
 W_DictProxyObject.typedef = TypeDef(
     'mappingproxy',
+    __new__=interp2app(W_DictProxyObject.descr_new),
+    __init__=interp2app(W_DictProxyObject.descr_init),
     __len__=interp2app(W_DictProxyObject.descr_len),
     __getitem__=interp2app(W_DictProxyObject.descr_getitem),
     __contains__=interp2app(W_DictProxyObject.descr_contains),
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to