[pypy-svn] pypy default: Test and fix.

arigo commits-noreply at bitbucket.org
Thu Feb 17 07:38:01 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r42098:3649edf6e8ae
Date: 2011-02-17 07:37 +0100
http://bitbucket.org/pypy/pypy/changeset/3649edf6e8ae/

Log:	Test and fix.

diff --git a/pypy/module/_collections/test/test_defaultdict.py b/pypy/module/_collections/test/test_defaultdict.py
--- a/pypy/module/_collections/test/test_defaultdict.py
+++ b/pypy/module/_collections/test/test_defaultdict.py
@@ -16,3 +16,14 @@
         d[5] = l2
         d[5].append(44)
         assert l == [42, 43] and l2 == [44]
+
+    def test_keyerror_without_factory(self):
+        from _collections import defaultdict
+        d1 = defaultdict()
+        for key in ['foo', (1,)]:
+            try:
+                d1[key]
+            except KeyError, err:
+                assert err.args[0] == key
+            else:
+                assert 0, "expected KeyError"

diff --git a/pypy/module/_collections/interp_defaultdict.py b/pypy/module/_collections/interp_defaultdict.py
--- a/pypy/module/_collections/interp_defaultdict.py
+++ b/pypy/module/_collections/interp_defaultdict.py
@@ -6,7 +6,7 @@
     # threads.
     w_default_factory = space.getattr(w_self, space.wrap('default_factory'))
     if space.is_w(w_default_factory, space.w_None):
-        raise OperationError(space.w_KeyError, w_key)
+        raise OperationError(space.w_KeyError, space.newtuple([w_key]))
     w_value = space.call_function(w_default_factory)
     space.setitem(w_self, w_key, w_value)
     return w_value


More information about the Pypy-commit mailing list