Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.3
Changeset: r75227:6048008be2aa
Date: 2015-01-02 12:22 +0100
http://bitbucket.org/pypy/pypy/changeset/6048008be2aa/

Log:    dictproxy.copy() should use the proxied object and not always return
        a dict.

diff --git a/pypy/objspace/std/dictmultiobject.py 
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -197,9 +197,7 @@
 
     def descr_copy(self, space):
         """D.copy() -> a shallow copy of D"""
-        w_new = W_DictMultiObject.allocate_and_init_instance(space)
-        update1_dict_dict(space, w_new, self)
-        return w_new
+        return self.copy()
 
     def descr_items(self, space):
         """D.items() -> a set-like object providing a view on D's items"""
@@ -267,7 +265,7 @@
 
 def _add_indirections():
     dict_methods = "getitem getitem_str setitem setdefault \
-                    popitem delitem clear \
+                    popitem delitem clear copy \
                     length w_keys values items \
                     iterkeys itervalues iteritems \
                     listview_bytes listview_unicode listview_int \
@@ -412,6 +410,11 @@
         w_dict.strategy = strategy
         w_dict.dstorage = storage
 
+    def copy(self, w_dict):
+        w_new = W_DictMultiObject.allocate_and_init_instance(self.space)
+        update1_dict_dict(self.space, w_new, w_dict)
+        return w_new
+
     def listview_bytes(self, w_dict):
         return None
 
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
@@ -195,6 +195,9 @@
     def clear(self, w_dict):
         raise oefmt(self.space.w_AttributeError, "clear")
 
+    def copy(self, w_dict):
+        return self.space.call_method(self.unerase(w_dict.dstorage), "copy")
+
 create_iterator_classes(
     MappingProxyStrategy,
     override_next_key=MappingProxyStrategy.override_next_key,
diff --git a/pypy/objspace/std/test/test_dictproxy.py 
b/pypy/objspace/std/test/test_dictproxy.py
--- a/pypy/objspace/std/test/test_dictproxy.py
+++ b/pypy/objspace/std/test/test_dictproxy.py
@@ -78,6 +78,11 @@
         raises(TypeError, "proxy['a'] = 4")
         raises(TypeError, "del proxy['a']")
         raises(AttributeError, "proxy.clear()")
+        #
+        class D(dict):
+            def copy(self): return 3
+        proxy = dictproxy(D(a=1, b=2, c=3))
+        assert proxy.copy() == 3
 
 class AppTestUserObjectMethodCache(AppTestUserObject):
     spaceconfig = {"objspace.std.withmethodcachecounter": True}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to