Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.3
Changeset: r75220:a3cb64940229
Date: 2015-01-01 20:25 +0100
http://bitbucket.org/pypy/pypy/changeset/a3cb64940229/
Log: Fix: 'a' in dictproxy() should not raise KeyError
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
@@ -145,7 +145,12 @@
unerase = staticmethod(unerase)
def getitem(self, w_dict, w_key):
- return self.space.getitem(self.unerase(w_dict.dstorage), w_key)
+ try:
+ return self.space.getitem(self.unerase(w_dict.dstorage), w_key)
+ except OperationError, e:
+ if not e.match(self.space, self.space.w_KeyError):
+ raise
+ return None
def setitem(self, w_dict, w_key, w_value):
raise oefmt(self.space.w_TypeError,
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
@@ -46,6 +46,8 @@
assert a.__dict__ != b.__dict__
assert a.__dict__ != {'123': '456'}
assert {'123': '456'} != a.__dict__
+ b.__dict__.pop('__qualname__')
+ c.__dict__.pop('__qualname__')
assert b.__dict__ == c.__dict__
def test_str_repr(self):
@@ -69,6 +71,8 @@
mapping = dict(a=1, b=2, c=3)
proxy = dictproxy(mapping)
assert proxy['a'] == 1
+ assert 'a' in proxy
+ assert 'z' not in proxy
assert repr(proxy) == 'mappingproxy(%r)' % mapping
assert proxy.keys() == mapping.keys()
raises(TypeError, "proxy['a'] = 4")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit