Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.3
Changeset: r75228:ed4e7c9f2fd6
Date: 2015-01-02 14:54 +0100
http://bitbucket.org/pypy/pypy/changeset/ed4e7c9f2fd6/
Log: dictproxy() should only accept mappings
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
@@ -11,6 +11,11 @@
class W_DictProxyObject(W_DictMultiObject):
@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)
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
@@ -83,6 +83,9 @@
def copy(self): return 3
proxy = dictproxy(D(a=1, b=2, c=3))
assert proxy.copy() == 3
+ #
+ raises(TypeError, dictproxy, 3)
+ raises(TypeError, dictproxy, [3])
class AppTestUserObjectMethodCache(AppTestUserObject):
spaceconfig = {"objspace.std.withmethodcachecounter": True}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit